raft

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingReplicaID = errors.New("invalid raft configuration: local replica id is required")
	ErrMissingField     = errors.New("invalid raft configuration: tick and timeout are required and one of peers path or quorum")
	ErrTickTooSmall     = errors.New("invalid raft configuration: tick must be greater than 10ms")
	ErrTimeoutTooBig    = errors.New("invalid raft configuration: timeout must be smaller than the tick")
	ErrMissingReplica   = errors.New("invalid raft configuration: local replica is not defined in the quorum")
)

Validation Errors

View Source
var (
	ErrCannotSetRunningState = errors.New("can only set the running state from the initialized state")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	ReplicaID uint32        `required:"true"`    // the process ID of the local replica to identify from the peers config
	Tick      time.Duration `default:"1s"`       // the tick interval used to compute the heartbeat and election timeouts
	Timeout   time.Duration `default:"500ms"`    // the timeout to wait for a response from a peer
	Aggregate bool          `default:"true"`     // aggregate multiple commands into one append entries
	PeersPath string        `split_words:"true"` // the path to the peers configuration (usually loaded from a config map), only loaded if quorum is nil
	Quorum    *peers.Quorum `ignored:"true"`     // the peers configuration, will not be loaded from the environment
}

Config is intended to be loaded from the environment using envconfig and embedded as an subconfiguration of the service configuration (not loaded directly).

func (*Config) Validate

func (c *Config) Validate() (err error)

Validate the raft configuration. This also loads the peers from disk and validates the quorum and peers configuration if not directly specified.

type Replica

type Replica struct {
	api.UnimplementedRaftServer
	peers.Peer
	// contains filtered or unexported fields
}

func New

func New(conf Config) (replica *Replica, err error)

New creates a new replica from the configuration, validating it and setting the replica to its initialized state. If the configuration is invalid or the replica cannot be correctly initialized then an error is returned.

func (*Replica) Election

func (r *Replica) Election() election.Election

Election returns a new election from the replica's internal configuration with the replica voting yes for itself automatically (e.g. to start its candidacy).

func (*Replica) State

func (r *Replica) State() State

State returns the current state of the replica for testing.

type State

type State uint8

State is an enumeration of the possible status of a replica.

const (
	Stopped State = iota // stopped should be the zero value and default
	Initialized
	Running
	Follower
	Candidate
	Leader
)

Raft server states (not part of the state machine)

func (State) String

func (s State) String() string

String returns a human readable representation of the state.

Directories

Path Synopsis
api
log

Jump to

Keyboard shortcuts

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