tm

package module
v0.0.0-...-a6ee7d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LeaderHealthCheckInterval = time.Second

LeaderHealthCheckInterval might be changed in the unit to shorten the testing time.

Functions

func IsLeaderChange

func IsLeaderChange(err error) bool

IsLeaderChange will determine whether there is a leader change.

Types

type Client

type Client interface {
	// GetClusterID gets the cluster ID from TM.
	GetClusterID(ctx context.Context) uint64
	// GetAllMembers gets the members Info from TM
	GetAllMembers(ctx context.Context) ([]*pdpb.Member, error)
	// GetLeaderAddr returns current leader's address. It returns "" before
	// syncing leader from server.
	GetLeaderAddr() string
	// GetRegion gets a region and its leader Peer from TM 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 TM 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) (*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 TM by id.
	GetRegionByID(ctx context.Context, regionID uint64, opts ...GetRegionOption) (*Region, error)
	// ScanRegion 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) ([]*Region, error)
	// GetStore gets a store from TM 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 tm.
	// 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)
	// Update GC safe point. 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 an stream with all global config and updates
	WatchGlobalConfig(ctx context.Context, configPath string, revision int64) (chan []GlobalConfigItem, error)
	// UpdateOption updates the client option.
	UpdateOption(option DynamicOption, value interface{}) 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
	// ResourceManagerClient manages resource group metadata and token assignment.
	ResourceManagerClient
	// Close closes the client.
	Close()
}

Client is a TM (Placement Driver) client. It should not be used after calling Close().

func NewClient

func NewClient(svrAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error)

NewClient creates a TM client.

func NewClientWithContext

func NewClientWithContext(ctx context.Context, svrAddrs []string, security SecurityOption, opts ...ClientOption) (Client, error)

NewClientWithContext creates a TM 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.

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 WithMaxErrorRetry

func WithMaxErrorRetry(count int) ClientOption

WithMaxErrorRetry configures the client max retry times when connect meets error.

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
)

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 WithBuckets

func WithBuckets() GetRegionOption

WithBuckets means getting region and its buckets.

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

type GlobalConfigItem struct {
	EventType pdpb.EventType
	Name      string
	Value     string
	PayLoad   []byte
}

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)
	// WatchKeyspaces watches keyspace meta changes.
	WatchKeyspaces(ctx context.Context) (chan []*keyspacepb.KeyspaceMeta, error)
	// UpdateKeyspaceState updates target keyspace's state.
	UpdateKeyspaceState(ctx context.Context, id uint32, state keyspacepb.KeyspaceState) (*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 WithLease

func WithLease(lease int64) OpOption

WithLease specifies the lease of the key.

func WithLimit

func WithLimit(limit int64) OpOption

WithLimit specifies the limit of the key.

func WithPrefix

func WithPrefix() OpOption

WithPrefix specifies the prefix of the key.

func WithPrevKV

func WithPrevKV() OpOption

WithPrevKV specifies the previous key-value pair of the key.

func WithRangeEnd

func WithRangeEnd(rangeEnd []byte) OpOption

WithRangeEnd specifies the range end of the key.

func WithRev

func WithRev(revision int64) OpOption

WithRev specifies the start revision of the key.

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

type ResourceManagerClient

type ResourceManagerClient interface {
	ListResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, error)
	GetResourceGroup(ctx context.Context, resourceGroupName string) (*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)
	WatchResourceGroup(ctx context.Context, revision int64) (chan []*rmpb.ResourceGroup, error)
	AcquireTokenBuckets(ctx context.Context, request *rmpb.TokenBucketsRequest) ([]*rmpb.TokenBucketResponse, 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 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
	// GetURLs returns the URLs of the servers.
	GetURLs() []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 {addr -> a gRPC connection}
	GetClientConns() *sync.Map
	// GetServingAddr returns the serving endpoint which is the leader in a quorum-based cluster
	// or the primary in a primary/secondary configured cluster.
	GetServingAddr() string
	// GetBackupAddrs gets the addresses of the current reachable and healthy backup service
	// endpoints randomly. Backup service endpoints are followers in a quorum-based cluster or
	// secondaries in a primary/secondary configured cluster.
	GetBackupAddrs() []string
	// GetOrCreateGRPCConn returns the corresponding grpc client connection of the given addr
	GetOrCreateGRPCConn(addr 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
	// AddServingAddrSwitchedCallback 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.
	AddServingAddrSwitchedCallback(callbacks ...func())
	// AddServiceAddrsSwitchedCallback 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.
	AddServiceAddrsSwitchedCallback(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 TM.
	GetTS(ctx context.Context) (int64, int64, error)
	// GetTSAsync gets a timestamp from TM, without block the caller.
	GetTSAsync(ctx context.Context) TSFuture
	// GetLocalTS gets a local timestamp from TM.
	GetLocalTS(ctx context.Context, dcLocation string) (int64, int64, error)
	// GetLocalTSAsync gets a local timestamp from TM, without block the caller.
	GetLocalTSAsync(ctx context.Context, dcLocation string) TSFuture
}

TSOClient is the client used to get timestamps.

Directories

Path Synopsis
resource_group

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL