Documentation
¶
Index ¶
- Constants
- Variables
- func NewMockServiceDiscovery(urls []string, tlsCfg *tls.Config) *mockServiceDiscovery
- type APIKind
- type LeaderSwitchedCallbackFunc
- type ServiceClient
- type ServiceDiscovery
- func NewDefaultServiceDiscovery(ctx context.Context, cancel context.CancelFunc, urls []string, ...) ServiceDiscovery
- func NewServiceDiscovery(ctx context.Context, cancel context.CancelFunc, wg *sync.WaitGroup, ...) ServiceDiscovery
- func NewTSOServiceDiscovery(ctx context.Context, metacli metastorage.Client, ...) ServiceDiscovery
- type UpdateKeyspaceIDFunc
Constants ¶
const ( // MemberUpdateInterval is the interval to update the member list. MemberUpdateInterval = time.Minute // UpdateMemberMaxBackoffTime is the max time to back off when updating the member list. UpdateMemberMaxBackoffTime = 100 * time.Millisecond // UpdateMemberBackOffBaseTime is the base time to back off when updating the member list. // Here we use 20ms is because getting timestamp will print a warning log if the time exceeds 30ms. UpdateMemberBackOffBaseTime = 20 * time.Millisecond // UpdateMemberTimeout is the timeout to update the member list. // Use a shorter timeout to recover faster from network isolation. UpdateMemberTimeout = time.Second )
Variables ¶
var MemberHealthCheckInterval = time.Second
MemberHealthCheckInterval might be changed in the unit to shorten the testing time.
Functions ¶
func NewMockServiceDiscovery ¶
NewMockServiceDiscovery creates a mock service discovery.
Types ¶
type LeaderSwitchedCallbackFunc ¶
LeaderSwitchedCallbackFunc is the callback function for leader switched event
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 // ExecAndAddLeaderSwitchedCallback executes the callback once and adds it to the callback list then. ExecAndAddLeaderSwitchedCallback(cb LeaderSwitchedCallbackFunc) // AddLeaderSwitchedCallback 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. AddLeaderSwitchedCallback(cb LeaderSwitchedCallbackFunc) // AddMembersChangedCallback 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. AddMembersChangedCallback(cb func()) }
ServiceDiscovery defines the general interface for service discovery on a quorum-based cluster or a primary/secondary configured cluster.
func NewDefaultServiceDiscovery ¶
func NewDefaultServiceDiscovery( ctx context.Context, cancel context.CancelFunc, urls []string, tlsCfg *tls.Config, ) ServiceDiscovery
NewDefaultServiceDiscovery returns a new default service discovery-based client.
func NewServiceDiscovery ¶
func NewServiceDiscovery( 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
NewServiceDiscovery returns a new service discovery-based client.
func NewTSOServiceDiscovery ¶
func NewTSOServiceDiscovery( ctx context.Context, metacli metastorage.Client, serviceDiscovery ServiceDiscovery, keyspaceID uint32, tlsCfg *tls.Config, option *opt.Option, ) ServiceDiscovery
NewTSOServiceDiscovery returns a new client-side service discovery for the independent TSO service.
type UpdateKeyspaceIDFunc ¶
type UpdateKeyspaceIDFunc func() error
UpdateKeyspaceIDFunc is the function type for updating the keyspace ID.