server

package
v1.1.0-beta.0...-debceaf Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CreateServerWrapper(cmd *cobra.Command, args []string)

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

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"`

	// 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

func GenerateConfig(c *Config) (*Config, error)

GenerateConfig generates a new config with the given options.

func NewConfig

func NewConfig() *Config

NewConfig creates a new config.

func (*Config) Adjust

func (c *Config) Adjust(meta *toml.MetaData) error

Adjust is used to adjust the TSO configurations.

func (*Config) GeBackendEndpoints

func (c *Config) GeBackendEndpoints() string

GeBackendEndpoints returns the BackendEndpoints

func (*Config) GetAdvertiseListenAddr

func (c *Config) GetAdvertiseListenAddr() string

GetAdvertiseListenAddr returns the AdvertiseListenAddr

func (*Config) GetLeaderLease

func (c *Config) GetLeaderLease() int64

GetLeaderLease returns the leader lease.

func (*Config) GetListenAddr

func (c *Config) GetListenAddr() string

GetListenAddr returns the ListenAddr

func (*Config) GetMaxResetTSGap

func (c *Config) GetMaxResetTSGap() time.Duration

GetMaxResetTSGap returns the MaxResetTSGap.

func (*Config) GetName

func (c *Config) GetName() string

GetName returns the Name

func (*Config) GetTLSConfig

func (c *Config) GetTLSConfig() *grpcutil.TLSConfig

GetTLSConfig returns the TLS config.

func (*Config) GetTSOSaveInterval

func (c *Config) GetTSOSaveInterval() time.Duration

GetTSOSaveInterval returns TSO save interval.

func (*Config) GetTSOUpdatePhysicalInterval

func (c *Config) GetTSOUpdatePhysicalInterval() time.Duration

GetTSOUpdatePhysicalInterval returns TSO update physical interval.

func (*Config) Parse

func (c *Config) Parse(flagSet *pflag.FlagSet) error

Parse parses flag definitions from the argument list.

func (*Config) Validate

func (c *Config) Validate() error

Validate is used to validate if some configurations are right.

type ConfigProvider

type ConfigProvider any

ConfigProvider is used to get tso config from the given `bs.server` without modifying its interface.

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

func CreateServer(ctx context.Context, cfg *Config) *Server

CreateServer creates the Server

func (*Server) AddServiceReadyCallback

func (*Server) AddServiceReadyCallback(...func(context.Context) error)

AddServiceReadyCallback implements basicserver. It adds callbacks when it's ready for providing tso service.

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) GetAddr

func (s *Server) GetAddr() string

GetAddr returns the address of the server.

func (*Server) GetAdvertiseListenAddr

func (s *Server) GetAdvertiseListenAddr() string

GetAdvertiseListenAddr returns the advertise address of the server.

func (*Server) GetBackendEndpoints

func (s *Server) GetBackendEndpoints() string

GetBackendEndpoints returns the backend endpoints.

func (*Server) GetBasicServer

func (s *Server) GetBasicServer() bs.Server

GetBasicServer returns the basic server.

func (*Server) GetConfig

func (s *Server) GetConfig() *Config

GetConfig gets the config.

func (*Server) GetExternalTS

func (*Server) GetExternalTS() uint64

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) GetLeaderListenUrls

func (s *Server) GetLeaderListenUrls() []string

GetLeaderListenUrls gets service endpoints from the leader in election group. The entry at the index 0 is the primary's service endpoint.

func (*Server) GetMember

func (s *Server) GetMember(keyspaceID, keyspaceGroupID uint32) (tso.ElectionMember, error)

GetMember returns the election member of the given keyspace and keyspace group.

func (*Server) GetTLSConfig

func (s *Server) GetTLSConfig() *grpcutil.TLSConfig

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) IsClosed

func (s *Server) IsClosed() bool

IsClosed checks if the server loop is closed

func (*Server) IsKeyspaceServing

func (s *Server) IsKeyspaceServing(keyspaceID, keyspaceGroupID uint32) bool

IsKeyspaceServing returns whether the server is the primary of the given keyspace. TODO: update basicserver interface to support keyspace.

func (*Server) IsServing

func (s *Server) IsServing() bool

IsServing implements basicserver. It returns whether the server is the leader if there is embedded etcd, or the primary otherwise.

func (*Server) Name

func (s *Server) Name() string

Name returns the unique name for this server in the TSO cluster.

func (*Server) RegisterGRPCService

func (s *Server) RegisterGRPCService(grpcServer *grpc.Server)

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

func (s *Server) ResignPrimary(keyspaceID, keyspaceGroupID uint32) error

ResignPrimary resigns the primary of the given keyspace.

func (*Server) Run

func (s *Server) Run() (err error)

Run runs the TSO server.

func (*Server) ServerLoopWgAdd

func (s *Server) ServerLoopWgAdd(n int)

ServerLoopWgAdd increases the server loop wait group.

func (*Server) ServerLoopWgDone

func (s *Server) ServerLoopWgDone()

ServerLoopWgDone decreases the server loop wait group.

func (*Server) SetExternalTS

func (*Server) SetExternalTS(uint64) error

SetExternalTS saves external timestamp to cache and the persistent storage. TODO: Implement SetExternalTS

func (*Server) SetLogLevel

func (s *Server) SetLogLevel(level string) error

SetLogLevel sets log level.

func (*Server) SetUpRestHandler

func (s *Server) SetUpRestHandler() (http.Handler, apiutil.APIServiceGroup)

SetUpRestHandler sets up the REST handler.

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) FindGroupByKeyspaceID

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

func (s *Service) RegisterGRPCService(g *grpc.Server)

RegisterGRPCService registers the service to gRPC server.

func (*Service) RegisterRESTHandler

func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) error

RegisterRESTHandler registers the service to REST server.

func (*Service) Tso

func (s *Service) Tso(stream tsopb.TSO_TsoServer) error

Tso returns a stream of timestamps

Directories

Path Synopsis
apis
v1

Jump to

Keyboard shortcuts

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