Skip to content

Commit

Permalink
improve region path
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 26, 2022
1 parent a4d9f29 commit 3e6863d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/storage/endpoint/key_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package endpoint

import (
"bytes"
"fmt"
"path"
"strconv"
)

const (
Expand All @@ -38,6 +40,7 @@ const (
keyspaceMetaInfix = "meta"
keyspaceIDInfix = "id"
keyspaceAllocID = "alloc_id"
regionPathPrefix = "raft/r"
)

// AppendToRootPath appends the given key to the rootPath.
Expand Down Expand Up @@ -74,7 +77,12 @@ func storeRegionWeightPath(storeID uint64) string {

// RegionPath returns the region meta info key path with the given region ID.
func RegionPath(regionID uint64) string {
return path.Join(clusterPath, "r", fmt.Sprintf("%020d", regionID))
buf := new(bytes.Buffer)
buf.WriteString(regionPathPrefix)
buf.WriteString("/")
buf.WriteString(strconv.FormatUint(regionID, 10))

return buf.String()
}

func ruleKeyPath(ruleKey string) string {
Expand Down
9 changes: 9 additions & 0 deletions server/storage/endpoint/key_path_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package endpoint

import "testing"

func BenchmarkRegionPath(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = RegionPath(uint64(i))
}
}

0 comments on commit 3e6863d

Please sign in to comment.