Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Oct 27, 2022
1 parent 8cb5c97 commit b983009
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/storage/endpoint/key_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
keyspaceIDInfix = "id"
keyspaceAllocID = "alloc_id"
regionPathPrefix = "raft/r"

// we use uint64 to represent ID, the max length of uint64 is 20.
keyLen = 20
)

// AppendToRootPath appends the given key to the rootPath.
Expand Down Expand Up @@ -81,12 +84,12 @@ func RegionPath(regionID uint64) string {
buf.WriteString(regionPathPrefix)
buf.WriteString("/")
s := strconv.FormatUint(regionID, 10)
if len(s) > 20 {
s = s[len(s)-20:]
if len(s) > keyLen {
s = s[len(s)-keyLen:]
} else {
b := make([]byte, 20)
diff := 20 - len(s)
for i := 0; i < 20; i++ {
b := make([]byte, keyLen)
diff := keyLen - len(s)
for i := 0; i < keyLen; i++ {
if i < diff {
b[i] = 48
} else {
Expand Down

0 comments on commit b983009

Please sign in to comment.