server

package
v0.0.0-...-2c42c2a Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultOracleTimeCapDelta is the delta of the upper bound of KronosTime
	// which is persisted in the oracle state machine
	DefaultOracleTimeCapDelta = time.Minute
	// KronosDefaultRaftPort is the default port used by the raft HTTP transport
	KronosDefaultRaftPort = "5766"
	// KronosDefaultGRPCPort is the default port used by the kronos GRPC server
	KronosDefaultGRPCPort = "5767"
	// KronosDefaultDriftServerPort is the default port used by the kronos
	// drift server used in acceptance tests
	KronosDefaultDriftServerPort = "5768"
	// KronosDefaultPProfPort is the default port used by the pprof
	KronosDefaultPProfPort = "5777"
)

Variables

This section is empty.

Functions

func GenerateNewNodeID

func GenerateNewNodeID() string

Types

type Client

type Client interface {
	io.Closer
	// OracleTime returns the KronosTime if the server is the current oracle.
	// Otherwise it returns an NOT_ORACLE in OracleTimeResponse
	OracleTime(
		ctx context.Context,
		server *kronospb.NodeAddr,
	) (*kronospb.OracleTimeResponse, error)
	// KronosTime returns the KronosTime for given server even if it is
	// not the oracle.
	KronosTime(
		ctx context.Context,
		server *kronospb.NodeAddr,
	) (*kronospb.KronosTimeResponse, error)
	// Status returns the status of the given Server
	Status(
		ctx context.Context,
		server *kronospb.NodeAddr,
	) (*kronospb.StatusResponse, error)
}

Client is used by KronosServer to query KronosTime of nodes in the Kronos cluster Client is not thread safe

func NewGRPCClient

func NewGRPCClient(certsDir string) Client

NewGRPCClient creates a GRPC client to query Kronos servers

type Config

type Config struct {
	*oracle.RaftConfig
	// OracleTimeCapDelta is the delta of the upper bound of KronosTime which
	// is persisted in the oracle state machine
	OracleTimeCapDelta time.Duration
	// manageOracleTickInterval is the time after which an action is taken based
	// on the current state of state machine. Action can be to sync with oracle
	// or extend the oracle lease.
	ManageOracleTickInterval time.Duration
	// Clock is the interface which is used to access system time inside server.
	Clock tm.Clock
}

Config is used to initialize a kronos server based on the given parameters

type Server

type Server struct {
	// OracleSM is the state machine that is used to select an oracle
	OracleSM oracle.StateMachine
	// Client is used to query other kronos servers for time
	Client Client
	// GRPCAddr is the address of the grpc server
	GRPCAddr *kronospb.NodeAddr

	// OracleDelta is the delta of this server with respect to KronosTime
	OracleDelta atomic.Int64
	// Clock is used to get current time
	Clock tm.Clock
	// StopC is used to trigger cleanup functions
	StopC chan struct{}
	// OracleTimeCapDelta is the delta of the upper bound of KronosTime which
	// is persisted in the oracle state machine
	OracleTimeCapDelta time.Duration
	// Metrics records kronos metrics
	Metrics *kronosstats.KronosMetrics
	// contains filtered or unexported fields
}

Server is a time server application which can return nearly the same time in a cluster of nodes. It is fault tolerant and nearly monotonic across restarts.

func NewKronosServer

func NewKronosServer(ctx context.Context, config Config, selfID string) (*Server, error)

NewKronosServer returns an instance of Server based on given configurations

func (*Server) AddNewSeedHosts

func (k *Server) AddNewSeedHosts(newSeedHosts []string)

func (*Server) AddNode

func (k *Server) AddNode(id, addr string)

func (*Server) GetID

func (k *Server) GetID() string

func (*Server) ID

func (k *Server) ID() (string, error)

ID returns the persisted ID of the kronos server. If the kronos server is not initialized and does not have an assigned ID, an error is returned

func (*Server) KronosTime

func (k *Server) KronosTime(
	ctx context.Context, request *kronospb.KronosTimeRequest,
) (*kronospb.KronosTimeResponse, error)

KronosTime is the same as KronosTimeNow except that it takes a KronosTimeRequest as an argument so that Server implements the kronos GRPC service.

func (*Server) KronosTimeNow

func (k *Server) KronosTimeNow(ctx context.Context) (*kronospb.KronosTimeResponse, error)

KronosTimeNow returns the current KronosTime according to the server. If an error is returned, then server might be unitialized or it might have stale data.

func (*Server) ManageOracle

func (k *Server) ManageOracle(tickCh <-chan time.Time, tickCallback func())

ManageOracle initializes the server and takes an action on each tick of tickCh At every tick of tickCh the current state of the oracle state machine is read and the action taken could be 1. Extend oracle lease 2. Overthrow the oracle if it is down 3. Sync time with the oracle tickCallback is called after processing each tick

func (*Server) NewClusterClient

func (k *Server) NewClusterClient() (*kronoshttp.ClusterClient, error)

NewClusterClient returns a ClusterClient which can be used to perform cluster operations on the kronos server. Close should be called after completing all the requests to avoid connection leaks. Close should be called after completing all the requests to avoid connection leaks.

func (*Server) OracleTime

func (k *Server) OracleTime(
	ctx context.Context, request *kronospb.OracleTimeRequest,
) (*kronospb.OracleTimeResponse, error)

OracleTime returns the current KronosTime if the this server is the elected oracle. If an error is returned, this oracle may be overthrown by another kronos instance.

func (*Server) RunServer

func (k *Server) RunServer(ctx context.Context) error

RunServer starts a Kronos GRPC server

func (*Server) ServerStatus

func (k *Server) ServerStatus() kronospb.ServerStatus

ServerStatus returns the current status of the server

func (*Server) Status

func (k *Server) Status(
	ctx context.Context, request *kronospb.StatusRequest,
) (*kronospb.StatusResponse, error)

Status returns the current status of the server

func (*Server) Stop

func (k *Server) Stop()

Stop the Kronos server

Jump to

Keyboard shortcuts

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