server

package
v0.1.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

Package server provides the bootstrapping logic for a node in an arrebato cluster.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDefaultAdvertiseAddress = errors.New("could not find a default advertise address to use")

ErrNoDefaultAdvertiseAddress is the error returned when the server cannot determine an IP address to advertise to other servers in the cluster.

View Source
var ErrReload = errors.New("server has requested to reload from snapshot")

ErrReload is the error given when the server has read a snapshot and must be restarted to restore its state.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The server version
	Version string

	// LogLevel denotes the verbosity of logs.
	LogLevel int

	// BindAddress denotes the address the server will bind to for serf, raft & grpc.
	BindAddress string

	// AdvertiseAddress denotes the address the server will advertise to other nodes for serf & raft.
	AdvertiseAddress string

	// DataPath denotes the on-disk location that raft & message state are stored.
	DataPath string

	// Peers contain existing node addresses that should be connected to on start.
	Peers []string

	// PruneInterval determines how frequently messages are pruned from topics based on the topic's
	// retention period.
	PruneInterval time.Duration

	Raft    RaftConfig
	Serf    SerfConfig
	GRPC    GRPCConfig
	TLS     TLSConfig
	Metrics MetricConfig
}

The Config type contains configuration values for the Server.

type GRPCConfig

type GRPCConfig struct {
	// The Port to use for gRPC transport.
	Port int
}

The GRPCConfig type describes configuration values for the Server's gRPC endpoints.

type MetricConfig

type MetricConfig struct {
	// The Port that metrics should be served on via HTTP.
	Port int
}

The MetricConfig type contains configuration values for serving prometheus metrics.

type MetricExporter

type MetricExporter interface {
	Export(ctx context.Context) error
}

The MetricExporter interface describes types that export domain-specific metrics.

type RaftConfig

type RaftConfig struct {
	// Timeout is the timeout to use for raft communications.
	Timeout time.Duration

	// MaxSnapshots is the maximum number of raft snapshots to keep.
	MaxSnapshots int

	// NonVoter determines if the server is added to the cluster as a replica that can
	// never gain leadership.
	NonVoter bool
}

The RaftConfig type describes configuration values for the raft consensus algorithm used to maintain state across the cluster.

type SerfConfig

type SerfConfig struct {
	// The Port to use for serf transport.
	Port int

	// The location of the file whose contents should contain the primary encryption key for
	// gossip messages. The file contents should be either 16, 24, or 32 bytes to select AES-128,
	// AES-192, or AES-256.
	EncryptionKeyFile string
}

The SerfConfig type contains configuration values for serf.

type Server

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

The Server type represents the entire arrebato node and stitches together the serf, raft & grpc configuration.

func New

func New(config Config) (*Server, error)

New returns a new instance of the Server type based on the provided Config.

func (*Server) Apply

func (svr *Server) Apply(log *raft.Log) interface{}

Apply unmarshals the contents of the raft.Log, expecting a command.Command that can be handled by a command handler.

func (*Server) IsLeader

func (svr *Server) IsLeader() bool

IsLeader returns true if this server instance is the cluster leader.

func (*Server) Restore

func (svr *Server) Restore(snapshot io.ReadCloser) error

Restore replaces the current state of the applied raft log with the contents of the io.ReadCloser implementation. This is done by initialising the snapshot in a temporary file and triggering the server to restart. The server will detect the restore file, rename it and use it from then on.

func (*Server) Snapshot

func (svr *Server) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a raft.FSMSnapshot implementation that backs up the current state of the applied raft log. It always returns a nil error.

func (*Server) Start

func (svr *Server) Start(ctx context.Context) error

Start the server. This method blocks until an error occurs or the provided context is cancelled.

type Snapshot

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

The Snapshot type is used to obtain a copy of the current data store managed by the raft log.

func (*Snapshot) Persist

func (s *Snapshot) Persist(sink raft.SnapshotSink) error

Persist the contents of the data store to the raft.SnapshotSink implementation.

func (*Snapshot) Release

func (s *Snapshot) Release()

Release does nothing.

type TLSConfig

type TLSConfig struct {
	// Location of the TLS certificate file to use for transport credentials.
	CertFile string

	// Location of the TLS Key file to use for transport credentials.
	KeyFile string

	// The certificate of the CA that signs client certificates.
	CAFile string
}

The TLSConfig type contains configuration values for TLS between the server nodes and clients.

Jump to

Keyboard shortcuts

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