Skip to content

Commit

Permalink
perf: update key generator
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-sjtu authored and vipwzw committed Nov 30, 2021
1 parent f39e038 commit 5c5d864
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions common/db/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,37 +433,47 @@ func pad(version int64) []byte {

//GetKeyPerfix 获取key前缀
func GetKeyPerfix(key []byte) []byte {
b := append([]byte{}, mvccData...)
newkey := append(b, key...)
newkey = append(newkey, []byte(".")...)
return newkey
result := make([]byte, 0, len(mvccData) + len(key) + 1)
result = append(result, mvccData...)
result = append(result, key...)
result = append(result, []byte(".")...)
return result
}

//GetKey 获取键
func GetKey(key []byte, version int64) ([]byte, error) {
newkey := append(GetKeyPerfix(key), pad(version)...)
return newkey, nil
result := make([]byte, 0, len(mvccData) + len(key) + 21)
result = append(result, mvccData...)
result = append(result, key...)
result = append(result, []byte(".")...)
result = append(result, pad(version)...)
return result, nil
}

func getLastKey(key []byte) []byte {
b := append([]byte{}, mvccLast...)
return append(b, key...)
result := make([]byte, 0, len(mvccLast) + len(key))
result = append(result, mvccLast...)
result = append(result, key...)
return result
}

func getVersionHashKey(hash []byte) []byte {
b := append([]byte{}, mvccMeta...)
key := append(b, hash...)
return key
result := make([]byte, 0, len(mvccMeta) + len(hash))
result = append(result, mvccMeta...)
result = append(result, hash...)
return result
}

func getVersionKey(version int64) []byte {
b := append([]byte{}, mvccMetaVersion...)
key := append(b, pad(version)...)
return key
result := make([]byte, 0, len(mvccMetaVersion) + 20)
result = append(result, mvccMetaVersion...)
result = append(result, pad(version)...)
return result
}

func getVersionKeyListKey(version int64) []byte {
b := append([]byte{}, mvccMetaVersionKeyList...)
key := append(b, pad(version)...)
return key
result := make([]byte, 0, len(mvccMetaVersionKeyList) + 20)
result = append(result, mvccMetaVersionKeyList...)
result = append(result, pad(version)...)
return result
}

0 comments on commit 5c5d864

Please sign in to comment.