From 3e6863df22d8f11ac8d2243ff6482b02c9ecb358 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 26 Oct 2022 18:52:35 +0800 Subject: [PATCH] improve region path Signed-off-by: Ryan Leung --- server/storage/endpoint/key_path.go | 10 +++++++++- server/storage/endpoint/key_path_test.go | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 server/storage/endpoint/key_path_test.go diff --git a/server/storage/endpoint/key_path.go b/server/storage/endpoint/key_path.go index 9de751c3f464..f5b050e5bbd1 100644 --- a/server/storage/endpoint/key_path.go +++ b/server/storage/endpoint/key_path.go @@ -15,8 +15,10 @@ package endpoint import ( + "bytes" "fmt" "path" + "strconv" ) const ( @@ -38,6 +40,7 @@ const ( keyspaceMetaInfix = "meta" keyspaceIDInfix = "id" keyspaceAllocID = "alloc_id" + regionPathPrefix = "raft/r" ) // AppendToRootPath appends the given key to the rootPath. @@ -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 { diff --git a/server/storage/endpoint/key_path_test.go b/server/storage/endpoint/key_path_test.go new file mode 100644 index 000000000000..6450847bbe05 --- /dev/null +++ b/server/storage/endpoint/key_path_test.go @@ -0,0 +1,9 @@ +package endpoint + +import "testing" + +func BenchmarkRegionPath(b *testing.B) { + for i := 0; i < b.N; i++ { + _ = RegionPath(uint64(i)) + } +}