consensus

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consensus

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

func NewConsensus

func NewConsensus(cfg *config.Config, logger log.Logger, node model.ElectNode) (*Consensus, error)

func (*Consensus) ClusterState

func (c *Consensus) ClusterState() (*model.ClusterState, error)

ClusterState retrieves the current state of the cluster including all nodes.

func (*Consensus) CurrentState

func (c *Consensus) CurrentState() model.ElectNode

CurrentState returns the current election node state.

func (*Consensus) IsLeader

func (c *Consensus) IsLeader() bool

IsLeader determines whether the current node is the leader node.

func (*Consensus) Leader

func (c *Consensus) Leader() (*model.Node, error)

Leader retrieves the current leader node from the cluster. It returns an error if no leader is found or there's an issue fetching the cluster state.

func (*Consensus) Run

func (c *Consensus) Run() (<-chan model.StateTransition, error)

Run starts the consensus Returns a channel of state transitions and an error

func (*Consensus) Visualize

func (c *Consensus) Visualize() string

Visualize returns a visualization of the current consensus state machine in Graphviz format.

type RpcHandler

type RpcHandler struct {
	*Consensus
}

func NewConsensusRpcHandler

func NewConsensusRpcHandler(cfg *config.Config, logger log.Logger, node model.ElectNode) (*RpcHandler, error)

func (*RpcHandler) HeartBeat

func (c *RpcHandler) HeartBeat(args *model.HeartBeatRequest, reply *model.HeartBeatResponse) error

HeartBeat handles heartbeat request from peer node

func (*RpcHandler) Ping

func (c *RpcHandler) Ping(args struct{}, reply *string) error

Ping handles ping request from peer node

func (*RpcHandler) RequestVote

func (c *RpcHandler) RequestVote(args *model.RequestVoteRequest, reply *model.RequestVoteResponse) error

RequestVote handle vote request from peer node

func (*RpcHandler) Run

func (c *RpcHandler) Run() (<-chan model.StateTransition, error)

Run starts the consensus Returns a channel of state transitions and an error

func (*RpcHandler) State

func (c *RpcHandler) State(args struct{}, reply *model.ElectNode) error

State return current node state

Jump to

Keyboard shortcuts

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