Skip to content

Commit

Permalink
Move more consts to mics
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Nov 21, 2024
1 parent dd7dbcd commit 7d2220f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 3 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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}
}
Expand Down
4 changes: 4 additions & 0 deletions client/utils/mics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 7d2220f

Please sign in to comment.