Documentation ¶
Index ¶
- Constants
- Variables
- func NewMockPDServiceDiscovery(urls []string, tlsCfg *tls.Config) *mockPDServiceDiscovery
- type APIKind
- type ServiceClient
- type ServiceDiscovery
- func NewDefaultPDServiceDiscovery(ctx context.Context, cancel context.CancelFunc, urls []string, ...) ServiceDiscovery
- func NewPDServiceDiscovery(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, ...) ServiceDiscovery
- func NewTSOServiceDiscovery(ctx context.Context, metacli metastorage.Client, ...) ServiceDiscovery
- type TSOEventSource
- type UpdateKeyspaceIDFunc
Constants ¶
const ( // MemberUpdateInterval is the interval to update the member list. MemberUpdateInterval = time.Minute // UpdateMemberTimeout is the timeout to update the member list. // Use a shorter timeout to recover faster from network isolation. UpdateMemberTimeout = time.Second // UpdateMemberBackOffBaseTime is the base time to back off when updating the member list. UpdateMemberBackOffBaseTime = 100 * time.Millisecond )
Variables ¶
var MemberHealthCheckInterval = time.Second
MemberHealthCheckInterval might be changed in the unit to shorten the testing time.
Functions ¶
func NewMockPDServiceDiscovery ¶
NewMockPDServiceDiscovery creates a mock PD service discovery.
Types ¶
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 // SetKeyspaceID sets the ID of the keyspace SetKeyspaceID(id 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 // GetServiceClientByKind tries to get the ServiceClient with the given API kind. GetServiceClientByKind(kind APIKind) 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.
func NewDefaultPDServiceDiscovery ¶
func NewDefaultPDServiceDiscovery( ctx context.Context, cancel context.CancelFunc, urls []string, tlsCfg *tls.Config, ) ServiceDiscovery
NewDefaultPDServiceDiscovery returns a new default PD service discovery-based client.
func NewPDServiceDiscovery ¶
func NewPDServiceDiscovery( ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, serviceModeUpdateCb func(pdpb.ServiceMode), updateKeyspaceIDFunc UpdateKeyspaceIDFunc, keyspaceID uint32, urls []string, tlsCfg *tls.Config, option *opt.Option, ) ServiceDiscovery
NewPDServiceDiscovery returns a new PD service discovery-based client.
func NewTSOServiceDiscovery ¶
func NewTSOServiceDiscovery( ctx context.Context, metacli metastorage.Client, apiSvcDiscovery ServiceDiscovery, keyspaceID uint32, tlsCfg *tls.Config, option *opt.Option, ) ServiceDiscovery
NewTSOServiceDiscovery returns a new client-side service discovery for the independent TSO service.
type TSOEventSource ¶
type TSOEventSource interface {
// SetTSOLeaderURLUpdatedCallback adds a callback which will be called when the TSO leader/primary is updated.
SetTSOLeaderURLUpdatedCallback(callback tsoLeaderURLUpdatedFunc)
}
TSOEventSource subscribes to events related to changes in the TSO leader/primary from the service discovery.
type UpdateKeyspaceIDFunc ¶
type UpdateKeyspaceIDFunc func() error
UpdateKeyspaceIDFunc is the function type for updating the keyspace ID.