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) error
- func (c *Config) GetAdvertiseListenAddr() string
- func (c *Config) GetBackendEndpoints() string
- func (c *Config) GetLease() 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) Parse(flagSet *pflag.FlagSet) error
- type Server
- func (*Server) AddServiceReadyCallback(...func(context.Context) error)
- func (s *Server) Close()
- func (s *Server) GetAddr() string
- func (s *Server) GetAdvertiseListenAddr() string
- func (s *Server) GetBackendEndpoints() string
- func (s *Server) GetBasicServer() bs.Server
- func (s *Server) GetConfig() *Config
- func (*Server) GetExternalTS() uint64
- func (s *Server) GetKeyspaceGroupManager() *tso.KeyspaceGroupManager
- func (s *Server) GetMember(keyspaceID, keyspaceGroupID uint32) (member.Election, error)
- func (s *Server) GetServingUrls() []string
- func (s *Server) GetTLSConfig() *grpcutil.TLSConfig
- func (s *Server) GetTSOAllocator(keyspaceGroupID uint32) (*tso.Allocator, error)
- func (s *Server) IsClosed() bool
- func (s *Server) IsKeyspaceServingByGroup(keyspaceID, keyspaceGroupID uint32) bool
- func (s *Server) IsServing() bool
- func (s *Server) Name() string
- func (s *Server) RegisterGRPCService(grpcServer *grpc.Server)
- func (s *Server) ResetTS(ts uint64, ignoreSmaller, skipUpperBoundCheck bool, keyspaceGroupID uint32) error
- func (s *Server) ResignPrimary(keyspaceID, keyspaceGroupID uint32) error
- func (s *Server) Run() (err error)
- func (s *Server) ServerLoopWgAdd(n int)
- func (s *Server) ServerLoopWgDone()
- func (*Server) SetExternalTS(uint64) error
- func (s *Server) SetLogLevel(level string) error
- func (s *Server) SetUpRestHandler() (http.Handler, apiutil.APIServiceGroup)
- func (s *Server) ValidateRequest(header *tsopb.RequestHeader) error
- type Service
- func (s *Service) FindGroupByKeyspaceID(_ context.Context, request *tsopb.FindGroupByKeyspaceIDRequest) (*tsopb.FindGroupByKeyspaceIDResponse, error)
- func (s *Service) GetMinTS(_ context.Context, request *tsopb.GetMinTSRequest) (*tsopb.GetMinTSResponse, error)
- func (s *Service) RegisterGRPCService(g *grpc.Server)
- func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) error
- func (s *Service) Tso(stream tsopb.TSO_TsoServer) error
Constants ¶
This section is empty.
Variables ¶
var SetUpRestHandler = func(*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"`
// 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"`
// Deprecated
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) GetAdvertiseListenAddr ¶
GetAdvertiseListenAddr returns the AdvertiseListenAddr
func (*Config) GetBackendEndpoints ¶
GetBackendEndpoints returns the BackendEndpoints
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.
type Server ¶
type Server struct {
*server.BaseServer
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) GetAdvertiseListenAddr ¶
GetAdvertiseListenAddr returns the advertise address of the server.
func (*Server) GetBackendEndpoints ¶
GetBackendEndpoints returns the backend endpoints.
func (*Server) GetBasicServer ¶
GetBasicServer returns the basic server.
func (*Server) GetExternalTS ¶
GetExternalTS returns external timestamp from the cache or the persistent storage. TODO: Implement GetExternalTS
func (*Server) GetKeyspaceGroupManager ¶
func (s *Server) GetKeyspaceGroupManager() *tso.KeyspaceGroupManager
GetKeyspaceGroupManager returns the manager of keyspace group.
func (*Server) GetServingUrls ¶
GetServingUrls gets service endpoints. The entry at the index 0 is the primary's service endpoint.
func (*Server) GetTLSConfig ¶
GetTLSConfig gets the security config.
func (*Server) GetTSOAllocator ¶
GetTSOAllocator returns the TSO Allocator of the given keyspace group.
func (*Server) IsKeyspaceServingByGroup ¶
IsKeyspaceServingByGroup returns whether the server is the primary of the given keyspace. It only returns true when the keyspace ID matches the keyspace group ID.
func (*Server) RegisterGRPCService ¶
RegisterGRPCService registers the grpc service.
func (*Server) ResetTS ¶
func (s *Server) ResetTS(ts uint64, ignoreSmaller, skipUpperBoundCheck bool, keyspaceGroupID uint32) error
ResetTS resets the TSO with the specified one.
func (*Server) ResignPrimary ¶
ResignPrimary resigns the primary of the given keyspace.
func (*Server) ServerLoopWgAdd ¶
ServerLoopWgAdd increases the server loop wait group.
func (*Server) ServerLoopWgDone ¶
func (s *Server) ServerLoopWgDone()
ServerLoopWgDone decreases the server loop wait group.
func (*Server) SetExternalTS ¶
SetExternalTS saves external timestamp to cache and the persistent storage. TODO: Implement SetExternalTS
func (*Server) SetLogLevel ¶
SetLogLevel sets log level.
func (*Server) SetUpRestHandler ¶
func (s *Server) SetUpRestHandler() (http.Handler, apiutil.APIServiceGroup)
SetUpRestHandler sets up the REST handler.
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) FindGroupByKeyspaceID ¶
func (s *Service) FindGroupByKeyspaceID( _ context.Context, request *tsopb.FindGroupByKeyspaceIDRequest, ) (*tsopb.FindGroupByKeyspaceIDResponse, error)
FindGroupByKeyspaceID returns the keyspace group that the keyspace belongs to.
func (*Service) GetMinTS ¶
func (s *Service) GetMinTS( _ context.Context, request *tsopb.GetMinTSRequest, ) (*tsopb.GetMinTSResponse, error)
GetMinTS gets the minimum timestamp across all keyspace groups served by the TSO server who receives and handles the request.
func (*Service) RegisterGRPCService ¶
RegisterGRPCService registers the service to gRPC server.
func (*Service) RegisterRESTHandler ¶
RegisterRESTHandler registers the service to REST server.