Documentation ¶
Index ¶
- Variables
- func IsLeaderChange(err error) bool
- func NewDefaultPDServiceDiscovery(ctx context.Context, cancel context.CancelFunc, urls []string, ...) *pdServiceDiscovery
- func NewMockPDServiceDiscovery(urls []string, tlsCfg *tls.Config) *mockPDServiceDiscovery
- func WithRUStats(op *GetResourceGroupOp)
- type APIContext
- type APIVersion
- type Client
- func NewClient(svrAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error)
- func NewClientWithAPIContext(ctx context.Context, apiCtx APIContext, svrAddrs []string, ...) (Client, error)
- func NewClientWithContext(ctx context.Context, svrAddrs []string, security SecurityOption, ...) (Client, error)
- func NewClientWithKeyspace(ctx context.Context, keyspaceID uint32, svrAddrs []string, ...) (Client, error)
- type ClientOption
- func WithCustomTimeoutOption(timeout time.Duration) ClientOption
- func WithForwardingOption(enableForwarding bool) ClientOption
- func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOption
- func WithInitMetricsOption(initMetrics bool) ClientOption
- func WithMaxErrorRetry(count int) ClientOption
- func WithMetricsLabels(labels prometheus.Labels) ClientOption
- type DynamicOption
- type GCClient
- type GetRegionOp
- type GetRegionOption
- type GetResourceGroupOp
- type GetResourceGroupOption
- type GetStoreOp
- type GetStoreOption
- type GlobalConfigItem
- type KeyspaceClient
- type MetaStorageClient
- type Op
- type OpOption
- type RPCClient
- type Region
- type RegionsOp
- type RegionsOption
- type ResourceManagerClient
- type SecurityOption
- type ServiceClient
- type ServiceDiscovery
- type TSFuture
- type TSOClient
Constants ¶
This section is empty.
Variables ¶
var ControllerConfigPathPrefixBytes = []byte(controllerConfigPathPrefix)
ControllerConfigPathPrefixBytes is used to watch or get controller config.
var GroupSettingsPathPrefixBytes = []byte(groupSettingsPathPrefix)
GroupSettingsPathPrefixBytes is used to watch or get resource groups.
var MemberHealthCheckInterval = time.Second
MemberHealthCheckInterval might be changed in the unit to shorten the testing time.
Functions ¶
func IsLeaderChange ¶
IsLeaderChange will determine whether there is a leader change.
func NewDefaultPDServiceDiscovery ¶
func NewDefaultPDServiceDiscovery( ctx context.Context, cancel context.CancelFunc, urls []string, tlsCfg *tls.Config, ) *pdServiceDiscovery
NewDefaultPDServiceDiscovery returns a new default PD service discovery-based client.
func NewMockPDServiceDiscovery ¶
NewMockPDServiceDiscovery creates a mock PD service discovery.
func WithRUStats ¶
func WithRUStats(op *GetResourceGroupOp)
WithRUStats specifies to return resource group with ru statistics data.
Types ¶
type APIContext ¶
type APIContext interface { GetAPIVersion() (apiVersion APIVersion) GetKeyspaceName() (keyspaceName string) }
APIContext is the context for API version.
func NewAPIContextV1 ¶
func NewAPIContextV1() APIContext
NewAPIContextV1 creates a API context for V1.
func NewAPIContextV2 ¶
func NewAPIContextV2(keyspaceName string) APIContext
NewAPIContextV2 creates a API context with the specified keyspace name for V2.
type APIVersion ¶
type APIVersion int
APIVersion is the API version the server and the client is using. See more details in https://github.com/tikv/rfcs/blob/master/text/0069-api-v2.md#kvproto
const ( V1 APIVersion = iota V2 )
The API versions the client supports. As for V1TTL, client won't use it and we just remove it.
type Client ¶
type Client interface { RPCClient // GetClusterID gets the cluster ID from PD. GetClusterID(ctx context.Context) uint64 // GetLeaderURL returns current leader's URL. It returns "" before // syncing leader from server. GetLeaderURL() string // GetServiceDiscovery returns ServiceDiscovery GetServiceDiscovery() ServiceDiscovery // UpdateOption updates the client option. UpdateOption(option DynamicOption, value any) error // Close closes the client. Close() }
Client is a PD (Placement Driver) RPC client. It should not be used after calling Close().
func NewClient ¶
func NewClient( svrAddrs []string, security SecurityOption, opts ...ClientOption, ) (Client, error)
NewClient creates a PD client.
func NewClientWithAPIContext ¶
func NewClientWithAPIContext( ctx context.Context, apiCtx APIContext, svrAddrs []string, security SecurityOption, opts ...ClientOption, ) (Client, error)
NewClientWithAPIContext creates a client according to the API context.
func NewClientWithContext ¶
func NewClientWithContext( ctx context.Context, svrAddrs []string, security SecurityOption, opts ...ClientOption, ) (Client, error)
NewClientWithContext creates a PD client with context. This API uses the default keyspace id 0.
func NewClientWithKeyspace ¶
func NewClientWithKeyspace( ctx context.Context, keyspaceID uint32, svrAddrs []string, security SecurityOption, opts ...ClientOption, ) (Client, error)
NewClientWithKeyspace creates a client with context and the specified keyspace id. And now, it's only for test purpose.
type ClientOption ¶
type ClientOption func(c *client)
ClientOption configures client.
func WithCustomTimeoutOption ¶
func WithCustomTimeoutOption(timeout time.Duration) ClientOption
WithCustomTimeoutOption configures the client with timeout option.
func WithForwardingOption ¶
func WithForwardingOption(enableForwarding bool) ClientOption
WithForwardingOption configures the client with forwarding option.
func WithGRPCDialOptions ¶
func WithGRPCDialOptions(opts ...grpc.DialOption) ClientOption
WithGRPCDialOptions configures the client with gRPC dial options.
func WithInitMetricsOption ¶
func WithInitMetricsOption(initMetrics bool) ClientOption
WithInitMetricsOption configures the client with metrics labels.
func WithMaxErrorRetry ¶
func WithMaxErrorRetry(count int) ClientOption
WithMaxErrorRetry configures the client max retry times when connect meets error.
func WithMetricsLabels ¶
func WithMetricsLabels(labels prometheus.Labels) ClientOption
WithMetricsLabels configures the client with metrics labels.
type DynamicOption ¶
type DynamicOption int
DynamicOption is used to distinguish the dynamic option type.
const ( // MaxTSOBatchWaitInterval is the max TSO batch wait interval option. // It is stored as time.Duration and should be between 0 and 10ms. MaxTSOBatchWaitInterval DynamicOption = iota // EnableTSOFollowerProxy is the TSO Follower Proxy option. // It is stored as bool. EnableTSOFollowerProxy // EnableFollowerHandle is the follower handle option. EnableFollowerHandle )
type GCClient ¶
type GCClient interface { UpdateGCSafePointV2(ctx context.Context, keyspaceID uint32, safePoint uint64) (uint64, error) UpdateServiceSafePointV2(ctx context.Context, keyspaceID uint32, serviceID string, ttl int64, safePoint uint64) (uint64, error) WatchGCSafePointV2(ctx context.Context, revision int64) (chan []*pdpb.SafePointEvent, error) }
GCClient is a client for doing GC
type GetRegionOp ¶
type GetRegionOp struct {
// contains filtered or unexported fields
}
GetRegionOp represents available options when getting regions.
type GetRegionOption ¶
type GetRegionOption func(op *GetRegionOp)
GetRegionOption configures GetRegionOp.
func WithAllowFollowerHandle ¶
func WithAllowFollowerHandle() GetRegionOption
WithAllowFollowerHandle means that client can send request to follower and let it handle this request.
func WithBuckets ¶
func WithBuckets() GetRegionOption
WithBuckets means getting region and its buckets.
type GetResourceGroupOp ¶
type GetResourceGroupOp struct {
// contains filtered or unexported fields
}
GetResourceGroupOp represents available options when getting resource group.
type GetResourceGroupOption ¶
type GetResourceGroupOption func(*GetResourceGroupOp)
GetResourceGroupOption configures GetResourceGroupOp.
type GetStoreOp ¶
type GetStoreOp struct {
// contains filtered or unexported fields
}
GetStoreOp represents available options when getting stores.
type GetStoreOption ¶
type GetStoreOption func(*GetStoreOp)
GetStoreOption configures GetStoreOp.
func WithExcludeTombstone ¶
func WithExcludeTombstone() GetStoreOption
WithExcludeTombstone excludes tombstone stores from the result.
type GlobalConfigItem ¶
GlobalConfigItem standard format of KV pair in GlobalConfig client
type KeyspaceClient ¶
type KeyspaceClient interface { // LoadKeyspace load and return target keyspace's metadata. LoadKeyspace(ctx context.Context, name string) (*keyspacepb.KeyspaceMeta, error) // UpdateKeyspaceState updates target keyspace's state. UpdateKeyspaceState(ctx context.Context, id uint32, state keyspacepb.KeyspaceState) (*keyspacepb.KeyspaceMeta, error) // WatchKeyspaces watches keyspace meta changes. WatchKeyspaces(ctx context.Context) (chan []*keyspacepb.KeyspaceMeta, error) // GetAllKeyspaces get all keyspace's metadata. GetAllKeyspaces(ctx context.Context, startID uint32, limit uint32) ([]*keyspacepb.KeyspaceMeta, error) }
KeyspaceClient manages keyspace metadata.
type MetaStorageClient ¶
type MetaStorageClient interface { // Watch watches on a key or prefix. Watch(ctx context.Context, key []byte, opts ...OpOption) (chan []*meta_storagepb.Event, error) // Get gets the value for a key. Get(ctx context.Context, key []byte, opts ...OpOption) (*meta_storagepb.GetResponse, error) // Put puts a key-value pair into meta storage. Put(ctx context.Context, key []byte, value []byte, opts ...OpOption) (*meta_storagepb.PutResponse, error) }
MetaStorageClient is the interface for meta storage client.
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op represents available options when using meta storage client.
type OpOption ¶
type OpOption func(*Op)
OpOption configures etcd Op.
func WithPrevKV ¶
func WithPrevKV() OpOption
WithPrevKV specifies the previous key-value pair of the key.
func WithRangeEnd ¶
WithRangeEnd specifies the range end of the key.
type RPCClient ¶
type RPCClient interface { // GetAllMembers gets the members Info from PD GetAllMembers(ctx context.Context) ([]*pdpb.Member, error) // GetRegion gets a region and its leader Peer from PD by key. // The region may expire after split. Caller is responsible for caching and // taking care of region change. // Also, it may return nil if PD finds no Region for the key temporarily, // client should retry later. GetRegion(ctx context.Context, key []byte, opts ...GetRegionOption) (*Region, error) // GetRegionFromMember gets a region from certain members. GetRegionFromMember(ctx context.Context, key []byte, memberURLs []string, opts ...GetRegionOption) (*Region, error) // GetPrevRegion gets the previous region and its leader Peer of the region where the key is located. GetPrevRegion(ctx context.Context, key []byte, opts ...GetRegionOption) (*Region, error) // GetRegionByID gets a region and its leader Peer from PD by id. GetRegionByID(ctx context.Context, regionID uint64, opts ...GetRegionOption) (*Region, error) // ScanRegions gets a list of regions, starts from the region that contains key. // Limit limits the maximum number of regions returned. // If a region has no leader, corresponding leader will be placed by a peer // with empty value (PeerID is 0). ScanRegions(ctx context.Context, key, endKey []byte, limit int, opts ...GetRegionOption) ([]*Region, error) // GetStore gets a store from PD by store id. // The store may expire later. Caller is responsible for caching and taking care // of store change. GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error) // GetAllStores gets all stores from pd. // The store may expire later. Caller is responsible for caching and taking care // of store change. GetAllStores(ctx context.Context, opts ...GetStoreOption) ([]*metapb.Store, error) // UpdateGCSafePoint TiKV will check it and do GC themselves if necessary. // If the given safePoint is less than the current one, it will not be updated. // Returns the new safePoint after updating. UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint64, error) // UpdateServiceGCSafePoint updates the safepoint for specific service and // returns the minimum safepoint across all services, this value is used to // determine the safepoint for multiple services, it does not trigger a GC // job. Use UpdateGCSafePoint to trigger the GC job if needed. UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) // ScatterRegion scatters the specified region. Should use it for a batch of regions, // and the distribution of these regions will be dispersed. // NOTICE: This method is the old version of ScatterRegions, you should use the later one as your first choice. ScatterRegion(ctx context.Context, regionID uint64) error // ScatterRegions scatters the specified regions. Should use it for a batch of regions, // and the distribution of these regions will be dispersed. ScatterRegions(ctx context.Context, regionsID []uint64, opts ...RegionsOption) (*pdpb.ScatterRegionResponse, error) // SplitRegions split regions by given split keys SplitRegions(ctx context.Context, splitKeys [][]byte, opts ...RegionsOption) (*pdpb.SplitRegionsResponse, error) // SplitAndScatterRegions split regions by given split keys and scatter new regions SplitAndScatterRegions(ctx context.Context, splitKeys [][]byte, opts ...RegionsOption) (*pdpb.SplitAndScatterRegionsResponse, error) // GetOperator gets the status of operator of the specified region. GetOperator(ctx context.Context, regionID uint64) (*pdpb.GetOperatorResponse, error) // LoadGlobalConfig gets the global config from etcd LoadGlobalConfig(ctx context.Context, names []string, configPath string) ([]GlobalConfigItem, int64, error) // StoreGlobalConfig set the config from etcd StoreGlobalConfig(ctx context.Context, configPath string, items []GlobalConfigItem) error // WatchGlobalConfig returns a stream with all global config and updates WatchGlobalConfig(ctx context.Context, configPath string, revision int64) (chan []GlobalConfigItem, error) // GetExternalTimestamp returns external timestamp GetExternalTimestamp(ctx context.Context) (uint64, error) // SetExternalTimestamp sets external timestamp SetExternalTimestamp(ctx context.Context, timestamp uint64) error // TSOClient is the TSO client. TSOClient // MetaStorageClient is the meta storage client. MetaStorageClient // KeyspaceClient manages keyspace metadata. KeyspaceClient // GCClient manages gcSafePointV2 and serviceSafePointV2 GCClient // ResourceManagerClient manages resource group metadata and token assignment. ResourceManagerClient }
RPCClient is a PD (Placement Driver) RPC and related mcs client which can only call RPC.
type Region ¶
type Region struct { Meta *metapb.Region Leader *metapb.Peer DownPeers []*metapb.Peer PendingPeers []*metapb.Peer Buckets *metapb.Buckets }
Region contains information of a region's meta and its peers.
type RegionsOp ¶
type RegionsOp struct {
// contains filtered or unexported fields
}
RegionsOp represents available options when operate regions
type RegionsOption ¶
type RegionsOption func(op *RegionsOp)
RegionsOption configures RegionsOp
func WithGroup ¶
func WithGroup(group string) RegionsOption
WithGroup specify the group during Scatter/Split Regions
func WithRetry ¶
func WithRetry(retry uint64) RegionsOption
WithRetry specify the retry limit during Scatter/Split Regions
func WithSkipStoreLimit ¶
func WithSkipStoreLimit() RegionsOption
WithSkipStoreLimit specify if skip the store limit check during Scatter/Split Regions
type ResourceManagerClient ¶
type ResourceManagerClient interface { ListResourceGroups(ctx context.Context, opts ...GetResourceGroupOption) ([]*rmpb.ResourceGroup, error) GetResourceGroup(ctx context.Context, resourceGroupName string, opts ...GetResourceGroupOption) (*rmpb.ResourceGroup, error) AddResourceGroup(ctx context.Context, metaGroup *rmpb.ResourceGroup) (string, error) ModifyResourceGroup(ctx context.Context, metaGroup *rmpb.ResourceGroup) (string, error) DeleteResourceGroup(ctx context.Context, resourceGroupName string) (string, error) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, int64, error) AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, error) Watch(ctx context.Context, key []byte, opts ...OpOption) (chan []*meta_storagepb.Event, error) }
ResourceManagerClient manages resource group info and token request.
type SecurityOption ¶
type SecurityOption struct { CAPath string CertPath string KeyPath string SSLCABytes []byte SSLCertBytes []byte SSLKEYBytes []byte }
SecurityOption records options about tls
type ServiceClient ¶
type ServiceClient interface { // GetURL returns the client url of the PD/etcd server. GetURL() string // GetClientConn returns the gRPC connection of the service client. // It returns nil if the connection is not available. GetClientConn() *grpc.ClientConn // BuildGRPCTargetContext builds a context object with a gRPC context. // ctx: the original context object. // mustLeader: whether must send to leader. BuildGRPCTargetContext(ctx context.Context, mustLeader bool) context.Context // IsConnectedToLeader returns whether the connected PD server is leader. IsConnectedToLeader() bool // Available returns if the network or other availability for the current service client is available. Available() bool // NeedRetry checks if client need to retry based on the PD server error response. // And It will mark the client as unavailable if the pd error shows the follower can't handle request. NeedRetry(*pdpb.Error, error) bool }
ServiceClient is an interface that defines a set of operations for a raw PD gRPC client to specific PD server.
type ServiceDiscovery ¶
type ServiceDiscovery interface { // Init initialize the concrete client underlying Init() error // Close releases all resources Close() // GetClusterID returns the ID of the cluster GetClusterID() uint64 // GetKeyspaceID returns the ID of the keyspace GetKeyspaceID() uint32 // GetKeyspaceGroupID returns the ID of the keyspace group GetKeyspaceGroupID() uint32 // GetServiceURLs returns the URLs of the servers providing the service GetServiceURLs() []string // GetServingEndpointClientConn returns the grpc client connection of the serving endpoint // which is the leader in a quorum-based cluster or the primary in a primary/secondary // configured cluster. GetServingEndpointClientConn() *grpc.ClientConn // GetClientConns returns the mapping {URL -> a gRPC connection} GetClientConns() *sync.Map // GetServingURL returns the serving endpoint which is the leader in a quorum-based cluster // or the primary in a primary/secondary configured cluster. GetServingURL() string // GetBackupURLs gets the URLs of the current reachable backup service // endpoints. Backup service endpoints are followers in a quorum-based cluster or // secondaries in a primary/secondary configured cluster. GetBackupURLs() []string // GetServiceClient tries to get the leader/primary ServiceClient. // If the leader ServiceClient meets network problem, // it returns a follower/secondary ServiceClient which can forward the request to leader. GetServiceClient() ServiceClient // GetAllServiceClients tries to get all ServiceClient. // If the leader is not nil, it will put the leader service client first in the slice. GetAllServiceClients() []ServiceClient // GetOrCreateGRPCConn returns the corresponding grpc client connection of the given url. GetOrCreateGRPCConn(url string) (*grpc.ClientConn, error) // ScheduleCheckMemberChanged is used to trigger a check to see if there is any membership change // among the leader/followers in a quorum-based cluster or among the primary/secondaries in a // primary/secondary configured cluster. ScheduleCheckMemberChanged() // CheckMemberChanged immediately check if there is any membership change among the leader/followers // in a quorum-based cluster or among the primary/secondaries in a primary/secondary configured cluster. CheckMemberChanged() error // AddServingURLSwitchedCallback adds callbacks which will be called when the leader // in a quorum-based cluster or the primary in a primary/secondary configured cluster // is switched. AddServingURLSwitchedCallback(callbacks ...func()) // AddServiceURLsSwitchedCallback adds callbacks which will be called when any leader/follower // in a quorum-based cluster or any primary/secondary in a primary/secondary configured cluster // is changed. AddServiceURLsSwitchedCallback(callbacks ...func()) }
ServiceDiscovery defines the general interface for service discovery on a quorum-based cluster or a primary/secondary configured cluster.
type TSFuture ¶
type TSFuture interface { // Wait gets the physical and logical time, it would block caller if data is not available yet. Wait() (int64, int64, error) }
TSFuture is a future which promises to return a TSO.
type TSOClient ¶
type TSOClient interface { // GetTS gets a timestamp from PD or TSO microservice. GetTS(ctx context.Context) (int64, int64, error) // GetTSAsync gets a timestamp from PD or TSO microservice, without block the caller. GetTSAsync(ctx context.Context) TSFuture // GetLocalTS gets a local timestamp from PD or TSO microservice. GetLocalTS(ctx context.Context, dcLocation string) (int64, int64, error) // GetLocalTSAsync gets a local timestamp from PD or TSO microservice, without block the caller. GetLocalTSAsync(ctx context.Context, dcLocation string) TSFuture // GetMinTS gets a timestamp from PD or the minimal timestamp across all keyspace groups from // the TSO microservice. GetMinTS(ctx context.Context) (int64, int64, error) }
TSOClient is the client used to get timestamps.