diff --git a/client/client.go b/client/client.go index 00bdbf5e6a1..6781182a44b 100644 --- a/client/client.go +++ b/client/client.go @@ -33,11 +33,11 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/tikv/pd/client/caller" "github.com/tikv/pd/client/clients/metastorage" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/metrics" "github.com/tikv/pd/client/opt" sd "github.com/tikv/pd/client/servicediscovery" - "github.com/tikv/pd/client/utils" "github.com/tikv/pd/client/utils/tlsutil" "go.uber.org/zap" ) @@ -263,7 +263,7 @@ func NewClientWithContext( security SecurityOption, opts ...opt.ClientOption, ) (Client, error) { return createClientWithKeyspace(ctx, callerComponent, - utils.NullKeyspaceID, svrAddrs, security, opts...) + constants.NullKeyspaceID, svrAddrs, security, opts...) } // NewClientWithKeyspace creates a client with context and the specified keyspace id. @@ -274,9 +274,9 @@ func NewClientWithKeyspace( keyspaceID uint32, svrAddrs []string, security SecurityOption, opts ...opt.ClientOption, ) (Client, error) { - if keyspaceID < utils.DefaultKeyspaceID || keyspaceID > utils.MaxKeyspaceID { + if keyspaceID < constants.DefaultKeyspaceID || keyspaceID > constants.MaxKeyspaceID { return nil, errors.Errorf("invalid keyspace id %d. It must be in the range of [%d, %d]", - keyspaceID, utils.DefaultKeyspaceID, utils.MaxKeyspaceID) + keyspaceID, constants.DefaultKeyspaceID, constants.MaxKeyspaceID) } return createClientWithKeyspace(ctx, callerComponent, keyspaceID, svrAddrs, security, opts...) @@ -366,7 +366,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 = utils.DefaultKeyspaceName + keyspaceName = constants.DefaultKeyspaceName } return &apiContextV2{keyspaceName: keyspaceName} } @@ -426,7 +426,7 @@ func newClientWithKeyspaceName( inner: &innerClient{ // Create a PD service discovery with null keyspace id, then query the real id with the keyspace name, // finally update the keyspace id to the PD service discovery for the following interactions. - keyspaceID: utils.NullKeyspaceID, + keyspaceID: constants.NullKeyspaceID, updateTokenConnectionCh: make(chan struct{}, 1), ctx: clientCtx, cancel: clientCancel, diff --git a/client/utils/mics.go b/client/constants/constants.go similarity index 98% rename from client/utils/mics.go rename to client/constants/constants.go index 662fd306c0d..10963dd10b6 100644 --- a/client/utils/mics.go +++ b/client/constants/constants.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package utils +package constants const ( // DefaultKeyspaceID is the default keyspace ID. diff --git a/client/servicediscovery/pd_service_discovery.go b/client/servicediscovery/pd_service_discovery.go index 879f838bf5e..2d106559b76 100644 --- a/client/servicediscovery/pd_service_discovery.go +++ b/client/servicediscovery/pd_service_discovery.go @@ -29,10 +29,10 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/retry" - "github.com/tikv/pd/client/utils" "github.com/tikv/pd/client/utils/grpcutil" "github.com/tikv/pd/client/utils/tlsutil" "go.uber.org/zap" @@ -454,7 +454,7 @@ func NewDefaultPDServiceDiscovery( urls []string, tlsCfg *tls.Config, ) ServiceDiscovery { var wg sync.WaitGroup - return NewPDServiceDiscovery(ctx, cancel, &wg, nil, nil, utils.DefaultKeyspaceID, urls, tlsCfg, opt.NewOption()) + return NewPDServiceDiscovery(ctx, cancel, &wg, nil, nil, constants.DefaultKeyspaceID, urls, tlsCfg, opt.NewOption()) } // NewPDServiceDiscovery returns a new PD service discovery-based client. @@ -501,7 +501,7 @@ func (c *pdServiceDiscovery) Init() error { // We need to update the keyspace ID before we discover and update the service mode // so that TSO in API mode can be initialized with the correct keyspace ID. - if c.keyspaceID == utils.NullKeyspaceID && c.updateKeyspaceIDFunc != nil { + if c.keyspaceID == constants.NullKeyspaceID && c.updateKeyspaceIDFunc != nil { if err := c.initRetry(c.updateKeyspaceIDFunc); err != nil { return err } @@ -668,7 +668,7 @@ func (c *pdServiceDiscovery) SetKeyspaceID(keyspaceID uint32) { // GetKeyspaceGroupID returns the ID of the keyspace group func (*pdServiceDiscovery) GetKeyspaceGroupID() uint32 { // PD/API service only supports the default keyspace group - return utils.DefaultKeyspaceGroupID + return constants.DefaultKeyspaceGroupID } // DiscoverMicroservice discovers the microservice with the specified type and returns the server urls. diff --git a/client/servicediscovery/tso_service_discovery.go b/client/servicediscovery/tso_service_discovery.go index f2b67f54133..81ef69c5545 100644 --- a/client/servicediscovery/tso_service_discovery.go +++ b/client/servicediscovery/tso_service_discovery.go @@ -30,9 +30,9 @@ import ( "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" "github.com/tikv/pd/client/clients/metastorage" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/utils" "github.com/tikv/pd/client/utils/grpcutil" "go.uber.org/zap" "google.golang.org/grpc" @@ -182,7 +182,7 @@ func NewTSOServiceDiscovery( c.tsoServerDiscovery = &tsoServerDiscovery{urls: make([]string, 0)} // Start with the default keyspace group. The actual keyspace group, to which the keyspace belongs, // will be discovered later. - c.defaultDiscoveryKey = fmt.Sprintf(tsoSvcDiscoveryFormat, c.clusterID, utils.DefaultKeyspaceGroupID) + c.defaultDiscoveryKey = fmt.Sprintf(tsoSvcDiscoveryFormat, c.clusterID, constants.DefaultKeyspaceGroupID) log.Info("created tso service discovery", zap.Uint64("cluster-id", c.clusterID), @@ -293,7 +293,7 @@ func (c *tsoServiceDiscovery) GetKeyspaceGroupID() uint32 { c.keyspaceGroupSD.RLock() defer c.keyspaceGroupSD.RUnlock() if c.keyspaceGroupSD.group == nil { - return utils.DefaultKeyspaceGroupID + return constants.DefaultKeyspaceGroupID } return c.keyspaceGroupSD.group.Id } @@ -469,7 +469,7 @@ func (c *tsoServiceDiscovery) updateMember() error { } members[0].IsPrimary = true keyspaceGroup = &tsopb.KeyspaceGroup{ - Id: utils.DefaultKeyspaceGroupID, + Id: constants.DefaultKeyspaceGroupID, Members: members, } } @@ -554,7 +554,7 @@ func (c *tsoServiceDiscovery) findGroupByKeyspaceID( Header: &tsopb.RequestHeader{ ClusterId: c.clusterID, KeyspaceId: keyspaceID, - KeyspaceGroupId: utils.DefaultKeyspaceGroupID, + KeyspaceGroupId: constants.DefaultKeyspaceGroupID, }, KeyspaceId: keyspaceID, }) diff --git a/client/tso_stream.go b/client/tso_stream.go index 6cf574c91bf..ce3c513ac46 100644 --- a/client/tso_stream.go +++ b/client/tso_stream.go @@ -29,9 +29,9 @@ import ( "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/metrics" - "github.com/tikv/pd/client/utils" "go.uber.org/zap" "google.golang.org/grpc" ) @@ -145,7 +145,7 @@ func (s pdTSOStreamAdapter) Recv() (tsoRequestResult, error) { physical: resp.GetTimestamp().GetPhysical(), logical: resp.GetTimestamp().GetLogical(), count: resp.GetCount(), - respKeyspaceGroupID: utils.DefaultKeyspaceGroupID, + respKeyspaceGroupID: constants.DefaultKeyspaceGroupID, }, nil }