consensus

package
v0.0.0-...-37eefcc Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotLeader = errors.New("not leader")
)

Functions

func ConvertAddRoute

func ConvertAddRoute(route *rm.Route) ([]byte, error)

func ConvertConfigSnapshot

func ConvertConfigSnapshot(shards map[dht.ShardID]dht.ShardLocation) ([]byte, error)

func ConvertRemoveRoute

func ConvertRemoveRoute(routeName string) ([]byte, error)

func NewRaftConsensus

func NewRaftConsensus(serverID string, port int, volumeDir string, fsmStore raft.FSM, log *zap.Logger, bootstrap bool) (*raftConsensus, error)

Types

type Consensus

type Consensus interface {

	// Join is called to add a new node in the cluster.
	// It returns an error if this node is not a leader
	Join(nodeID, raftAddress string) error

	// Remove is called to remove a particular node from the cluster.
	// It returns an error if this node is not a leader
	Remove(nodeID string) error

	// Stats returns the stats of raft on this node
	Stats() map[string]string

	// Returns true if the current node is leader
	IsLeader() bool

	// Returns the address of the leader node
	GetLeaderAddress() string

	// Apply is used to apply a command to the FSM
	Apply(cmd []byte) error

	// GetConfigurations returns a list of servers that are currently in a cluster
	GetConfigurations() ([]raft.Server, error)
}

Consensus is responsible for electing a leader, maintaining linearizability and maintaining the config and FSM in the cluster.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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