diff --git a/domain/domain.go b/domain/domain.go index 76b6b90186cbb..36e1f44089c0b 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -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) } diff --git a/domain/keyspace.go b/domain/keyspace.go index 9f97489d634fa..1bb9d0a11db68 100644 --- a/domain/keyspace.go +++ b/domain/keyspace.go @@ -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:] +} diff --git a/domain/keyspace_test.go b/domain/keyspace_test.go index 1d43dc39e8662..1b463b9c486bf 100644 --- a/domain/keyspace_test.go +++ b/domain/keyspace_test.go @@ -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)