server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 52 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStarted = status.Errorf(codes.Unavailable, "server not started")
)

gRPC errors

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

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

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

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, reloading bool) 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) IsLocalTSOEnabled

func (c *Config) IsLocalTSOEnabled() bool

IsLocalTSOEnabled returns if the local TSO is enabled.

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 Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a helper to export methods to handle API/RPC requests.

func (*Handler) ResetTS

func (h *Handler) ResetTS(
	ts uint64, ignoreSmaller, skipUpperBoundCheck bool, keyspaceGroupID uint32,
) error

ResetTS resets the TSO with the specified one.

type Server

type Server struct {
	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 (s *Server) AddServiceReadyCallback(callbacks ...func(context.Context))

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

func (s *Server) Close()

Close closes the server.

func (*Server) ClusterID

func (s *Server) ClusterID() uint64

ClusterID returns the cluster ID of this server.

func (*Server) Context

func (s *Server) Context() context.Context

Context returns the context of server.

func (*Server) GetAddr

func (s *Server) GetAddr() string

GetAddr returns the address of the server.

func (*Server) GetBasicServer

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

GetBasicServer returns the basic server.

func (*Server) GetClient

func (s *Server) GetClient() *clientv3.Client

GetClient returns builtin etcd client.

func (*Server) GetConfig

func (s *Server) GetConfig() *Config

GetConfig gets the config.

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

func (s *Server) GetExternalTS() uint64

GetExternalTS returns external timestamp from the cache or the persistent storage. TODO: Implement GetExternalTS

func (*Server) GetHTTPClient

func (s *Server) GetHTTPClient() *http.Client

GetHTTPClient returns builtin http client.

func (*Server) GetHandler

func (s *Server) GetHandler() *Handler

GetHandler returns the handler.

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

func (s *Server) IsLocalRequest(forwardedHost string) bool

IsLocalRequest checks if the forwarded host is the current host

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

func (s *Server) Run() error

Run runs the TSO server.

func (*Server) SetExternalTS

func (s *Server) SetExternalTS(externalTS uint64) error

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

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)

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