Skip to content

Commit

Permalink
add get keyspaceid from keyspace prefix (pingcap#45)
Browse files Browse the repository at this point in the history
Signed-off-by: ystaticy <y_static_y@sina.com>
  • Loading branch information
ystaticy authored Sep 5, 2022
1 parent e68d581 commit 2ad90b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ func (do *Domain) Init(ddlLease time.Duration, sysExecutorFactory func(*Domain)

// If keyspace has been set in KvStorage
if isKvStorageKeyspaceSet(do.store) {
keyspaceId := KeyspaceIdBytesToUint32(do.store.GetCodec().GetKeyspace())
keyspacePrefix := do.store.GetCodec().GetKeyspace()
keyspaceId := KeyspaceIdBytesToUint32(GetKeyspaceID(keyspacePrefix))
etcdPathPrefix := GetKeyspacePathPrefix(keyspaceId)
etcd.SetEtcdCliByNamespace(cli, etcdPathPrefix)
}
Expand Down
5 changes: 5 additions & 0 deletions domain/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ func KeyspaceIdBytesToUint32(b []byte) uint32 {
func isKvStorageKeyspaceSet(store kv.Storage) bool {
return store.GetCodec().GetKeyspace() != nil
}

// GetKeyspaceID is used to get keyspace id bytes from keyspace prefix
func GetKeyspaceID(b []byte) []byte {
return b[1:]
}
2 changes: 1 addition & 1 deletion domain/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (k *keyspaceSuite) TestID2Uint32() {
expectBytes := make([]byte, 4)
binary.BigEndian.PutUint32(expectBytes, expectId)

testBytes := expectBytes[1:]
testBytes := GetKeyspaceID(expectBytes)
testId := KeyspaceIdBytesToUint32(testBytes)
k.Equal(expectId, testId)

Expand Down

0 comments on commit 2ad90b5

Please sign in to comment.