From 3ea88d7e4b615c2735cc14e7c8a9f4c5dbd9ce8a Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 19 Nov 2024 17:06:33 +0800 Subject: [PATCH] Move more consts to mics Signed-off-by: JmPotato --- client/client.go | 11 +++-------- client/utils/mics.go | 4 ++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index bfa27d60a59..ecb228a10ec 100644 --- a/client/client.go +++ b/client/client.go @@ -41,11 +41,6 @@ import ( "go.uber.org/zap" ) -const ( - maxKeyspaceID = uint32(0xFFFFFF) - defaultKeyspaceName = "DEFAULT" -) - // Region contains information of a region's meta and its peers. type Region struct { Meta *metapb.Region @@ -278,9 +273,9 @@ func NewClientWithKeyspace( keyspaceID uint32, svrAddrs []string, security SecurityOption, opts ...opt.ClientOption, ) (Client, error) { - if keyspaceID < utils.DefaultKeyspaceID || keyspaceID > maxKeyspaceID { + if keyspaceID < utils.DefaultKeyspaceID || keyspaceID > utils.MaxKeyspaceID { return nil, errors.Errorf("invalid keyspace id %d. It must be in the range of [%d, %d]", - keyspaceID, utils.DefaultKeyspaceID, maxKeyspaceID) + keyspaceID, utils.DefaultKeyspaceID, utils.MaxKeyspaceID) } return createClientWithKeyspace(ctx, callerComponent, keyspaceID, svrAddrs, security, opts...) @@ -370,7 +365,7 @@ type apiContextV2 struct { // NewAPIContextV2 creates a API context with the specified keyspace name for V2. func NewAPIContextV2(keyspaceName string) APIContext { if len(keyspaceName) == 0 { - keyspaceName = defaultKeyspaceName + keyspaceName = utils.DefaultKeyspaceName } return &apiContextV2{keyspaceName: keyspaceName} } diff --git a/client/utils/mics.go b/client/utils/mics.go index 653709829ef..662fd306c0d 100644 --- a/client/utils/mics.go +++ b/client/utils/mics.go @@ -20,9 +20,13 @@ const ( // ​0 is reserved for default keyspace with the name "DEFAULT", It's initialized // when PD bootstrap and reserved for users who haven't been assigned keyspace. DefaultKeyspaceID = uint32(0) + // MaxKeyspaceID is the maximum keyspace ID. + MaxKeyspaceID = uint32(0xFFFFFF) // NullKeyspaceID is used for API v1 or legacy path where is keyspace agnostic. NullKeyspaceID = uint32(0xFFFFFFFF) // DefaultKeyspaceGroupID is the default key space group id. // We also reserved 0 for the keyspace group for the same purpose. DefaultKeyspaceGroupID = uint32(0) + // DefaultKeyspaceName is the default keyspace name. + DefaultKeyspaceName = "DEFAULT" )