Documentation ¶
Index ¶
- Variables
- func CreateServerWrapper(cmd *cobra.Command, args []string)
- func MustNewGrpcClient(re *require.Assertions, addr string) (*grpc.ClientConn, tsopb.TSOClient)
- func NewService(svr bs.Server) registry.RegistrableService
- type Config
- func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error
- func (c *Config) GeBackendEndpoints() string
- func (c *Config) GetAdvertiseListenAddr() string
- func (c *Config) GetLeaderLease() int64
- func (c *Config) GetListenAddr() string
- func (c *Config) GetMaxResetTSGap() time.Duration
- func (c *Config) GetName() string
- func (c *Config) GetTLSConfig() *grpcutil.TLSConfig
- func (c *Config) GetTSOSaveInterval() time.Duration
- func (c *Config) GetTSOUpdatePhysicalInterval() time.Duration
- func (c *Config) IsLocalTSOEnabled() bool
- func (c *Config) Parse(flagSet *pflag.FlagSet) error
- func (c *Config) Validate() error
- type Handler
- type Server
- func (s *Server) AddServiceReadyCallback(callbacks ...func(context.Context))
- func (s *Server) AddStartCallback(callbacks ...func())
- func (s *Server) Close()
- func (s *Server) ClusterID() uint64
- func (s *Server) Context() context.Context
- func (s *Server) GetAddr() string
- func (s *Server) GetBasicServer() bs.Server
- func (s *Server) GetClient() *clientv3.Client
- func (s *Server) GetConfig() *Config
- func (s *Server) GetDelegateClient(ctx context.Context, forwardedHost string) (*grpc.ClientConn, error)
- func (s *Server) GetExternalTS() uint64
- func (s *Server) GetHTTPClient() *http.Client
- func (s *Server) GetHandler() *Handler
- func (s *Server) GetLeaderListenUrls() []string
- func (s *Server) GetTLSConfig() *grpcutil.TLSConfig
- func (s *Server) GetTSOAllocatorManager(keyspaceGroupID uint32) (*tso.AllocatorManager, error)
- func (s *Server) IsClosed() bool
- func (s *Server) IsKeyspaceServing(keyspaceID, keyspaceGroupID uint32) bool
- func (s *Server) IsLocalRequest(forwardedHost string) bool
- func (s *Server) IsServing() bool
- func (s *Server) Name() string
- func (s *Server) Run() error
- func (s *Server) SetExternalTS(externalTS uint64) error
- func (s *Server) ValidateInternalRequest(_ *tsopb.RequestHeader, _ bool) error
- func (s *Server) ValidateRequest(header *tsopb.RequestHeader) error
- type Service
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotStarted = status.Errorf(codes.Unavailable, "server not started")
)
gRPC errors
var SetUpRestHandler = func(srv *Service) (http.Handler, apiutil.APIServiceGroup) { return dummyRestService{}, apiutil.APIServiceGroup{} }
SetUpRestHandler is a hook to sets up the REST service.
Functions ¶
func CreateServerWrapper ¶
CreateServerWrapper encapsulates the configuration/log/metrics initialization and create the server
func MustNewGrpcClient ¶
func MustNewGrpcClient(re *require.Assertions, addr string) (*grpc.ClientConn, tsopb.TSOClient)
MustNewGrpcClient must create a new TSO grpc client.
func NewService ¶
func NewService(svr bs.Server) registry.RegistrableService
NewService creates a new TSO service.
Types ¶
type Config ¶
type Config struct { BackendEndpoints string `toml:"backend-endpoints" json:"backend-endpoints"` ListenAddr string `toml:"listen-addr" json:"listen-addr"` AdvertiseListenAddr string `toml:"advertise-listen-addr" json:"advertise-listen-addr"` Name string `toml:"name" json:"name"` DataDir string `toml:"data-dir" json:"data-dir"` EnableGRPCGateway bool `json:"enable-grpc-gateway"` // LeaderLease defines the time within which a TSO primary/leader must update its TTL // in etcd, otherwise etcd will expire the leader key and other servers can campaign // the primary/leader again. Etcd only supports seconds TTL, so here is second too. LeaderLease int64 `toml:"lease" json:"lease"` // EnableLocalTSO is used to enable the Local TSO Allocator feature, // which allows the PD server to generate Local TSO for certain DC-level transactions. // To make this feature meaningful, user has to set the "zone" label for the PD server // to indicate which DC this PD belongs to. EnableLocalTSO bool `toml:"enable-local-tso" json:"enable-local-tso"` // TSOSaveInterval is the interval to save timestamp. TSOSaveInterval typeutil.Duration `toml:"tso-save-interval" json:"tso-save-interval"` // The interval to update physical part of timestamp. Usually, this config should not be set. // At most 1<<18 (262144) TSOs can be generated in the interval. The smaller the value, the // more TSOs provided, and at the same time consuming more CPU time. // This config is only valid in 1ms to 10s. If it's configured too long or too short, it will // be automatically clamped to the range. TSOUpdatePhysicalInterval typeutil.Duration `toml:"tso-update-physical-interval" json:"tso-update-physical-interval"` // MaxResetTSGap is the max gap to reset the TSO. MaxResetTSGap typeutil.Duration `toml:"max-gap-reset-ts" json:"max-gap-reset-ts"` Metric metricutil.MetricConfig `toml:"metric" json:"metric"` // WarningMsgs contains all warnings during parsing. WarningMsgs []string // Log related config. Log log.Config `toml:"log" json:"log"` Logger *zap.Logger LogProps *log.ZapProperties Security configutil.SecurityConfig `toml:"security" json:"security"` }
Config is the configuration for the TSO.
func GenerateConfig ¶
GenerateConfig generates a new config with the given options.
func (*Config) GeBackendEndpoints ¶
GeBackendEndpoints returns the BackendEndpoints
func (*Config) GetAdvertiseListenAddr ¶
GetAdvertiseListenAddr returns the AdvertiseListenAddr
func (*Config) GetLeaderLease ¶
GetLeaderLease returns the leader lease.
func (*Config) GetListenAddr ¶
GetListenAddr returns the ListenAddr
func (*Config) GetMaxResetTSGap ¶
GetMaxResetTSGap returns the MaxResetTSGap.
func (*Config) GetTLSConfig ¶
GetTLSConfig returns the TLS config.
func (*Config) GetTSOSaveInterval ¶
GetTSOSaveInterval returns TSO save interval.
func (*Config) GetTSOUpdatePhysicalInterval ¶
GetTSOUpdatePhysicalInterval returns TSO update physical interval.
func (*Config) IsLocalTSOEnabled ¶
IsLocalTSOEnabled returns if the local TSO is enabled.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a helper to export methods to handle API/RPC requests.
type Server ¶
type Server struct { diagnosticspb.DiagnosticsServer // contains filtered or unexported fields }
Server is the TSO server, and it implements bs.Server.
func CreateServer ¶
CreateServer creates the Server
func (*Server) AddServiceReadyCallback ¶
AddServiceReadyCallback implements basicserver. It adds callbacks when it's ready for providing tso service.
func (*Server) AddStartCallback ¶
func (s *Server) AddStartCallback(callbacks ...func())
AddStartCallback adds a callback in the startServer phase.
func (*Server) GetBasicServer ¶
GetBasicServer returns the basic server.
func (*Server) GetDelegateClient ¶
func (s *Server) GetDelegateClient(ctx context.Context, forwardedHost string) (*grpc.ClientConn, error)
GetDelegateClient returns grpc client connection talking to the forwarded host
func (*Server) GetExternalTS ¶
GetExternalTS returns external timestamp from the cache or the persistent storage. TODO: Implement GetExternalTS
func (*Server) GetHTTPClient ¶
GetHTTPClient returns builtin http client.
func (*Server) GetLeaderListenUrls ¶
GetLeaderListenUrls gets service endpoints from the leader in election group. The entry at the index 0 is the primary's service endpoint.
func (*Server) GetTLSConfig ¶
GetTLSConfig gets the security config.
func (*Server) GetTSOAllocatorManager ¶
func (s *Server) GetTSOAllocatorManager(keyspaceGroupID uint32) (*tso.AllocatorManager, error)
GetTSOAllocatorManager returns the manager of TSO Allocator.
func (*Server) IsKeyspaceServing ¶
IsKeyspaceServing returns whether the server is the primary of the given keyspace. TODO: update basicserver interface to support keyspace.
func (*Server) IsLocalRequest ¶
IsLocalRequest checks if the forwarded host is the current host
func (*Server) IsServing ¶
IsServing implements basicserver. It returns whether the server is the leader if there is embedded etcd, or the primary otherwise.
func (*Server) SetExternalTS ¶
SetExternalTS saves external timestamp to cache and the persistent storage. TODO: Implement SetExternalTS
func (*Server) ValidateInternalRequest ¶
func (s *Server) ValidateInternalRequest(_ *tsopb.RequestHeader, _ bool) error
ValidateInternalRequest checks if server is closed, which is used to validate the gRPC communication between TSO servers internally. TODO: Check if the sender is from the global TSO allocator
func (*Server) ValidateRequest ¶
func (s *Server) ValidateRequest(header *tsopb.RequestHeader) error
ValidateRequest checks if the keyspace replica is the primary and clusterID is matched. TODO: Check if the keyspace replica is the primary
type Service ¶
type Service struct {
*Server
}
Service is the TSO grpc service.
func (*Service) RegisterGRPCService ¶
RegisterGRPCService registers the service to gRPC server.
func (*Service) RegisterRESTHandler ¶
RegisterRESTHandler registers the service to REST server.