raft

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandAddConsistentHashEntry = "ADD_CONSISTENT_HASH_ENTRY"
	RaftLeaderState               = raft.Leader
	LeaderElectionTimeout         = 3 * time.Second
)

Configuration constants for Raft operations.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsistentHashCommand

type ConsistentHashCommand struct {
	Type      string `json:"type"`
	Hash      uint64 `json:"hash"`
	BlockName string `json:"blockName"`
}

ConsistentHashCommand represents a command to modify the consistent hash.

type FSM

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

FSM represents the Finite State Machine for the Raft cluster.

func NewFSM

func NewFSM() *FSM

NewFSM creates a new FSM instance.

func (*FSM) Apply

func (f *FSM) Apply(log *raft.Log) interface{}

Apply implements the raft.FSM interface.

func (*FSM) GetProxyBlock

func (f *FSM) GetProxyBlock(hash uint64) (string, bool)

GetProxyBlock safely retrieves the block name for a given hash.

func (*FSM) Restore

func (f *FSM) Restore(rc io.ReadCloser) error

Restore restores the FSM from a snapshot.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a snapshot of the FSM.

type FSMSnapshot

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

FSMSnapshot represents a snapshot of the FSM.

func (*FSMSnapshot) Persist

func (f *FSMSnapshot) Persist(sink raft.SnapshotSink) error

Persist writes the FSMSnapshot data to the given SnapshotSink.

func (*FSMSnapshot) Release

func (f *FSMSnapshot) Release()

type Node

type Node struct {
	Fsm *FSM

	Logger zerolog.Logger
	Peers  []config.RaftPeer
	// contains filtered or unexported fields
}

Node represents a node in the Raft cluster.

func NewRaftNode

func NewRaftNode(logger zerolog.Logger, raftConfig config.Raft) (*Node, error)

NewRaftNode creates and initializes a new Raft node.

func (*Node) AddPeer

func (n *Node) AddPeer(peerID, peerAddr string) error

AddPeer adds a new peer to the Raft cluster.

func (*Node) Apply

func (n *Node) Apply(data []byte, timeout time.Duration) error

Apply is the public method that handles forwarding if necessary.

func (*Node) GetState

func (n *Node) GetState() raft.RaftState

GetState returns the current Raft state.

func (*Node) RemovePeer

func (n *Node) RemovePeer(peerID string) error

RemovePeer removes a peer from the Raft cluster.

func (*Node) Shutdown

func (n *Node) Shutdown() error

Shutdown gracefully stops the Node by stopping the gRPC server, closing RPC client connections, and shutting down the underlying Raft node. It returns an error if the Raft node fails to shutdown properly, ignoring the ErrRaftShutdown error which indicates the node was already shutdown.

Directories

Path Synopsis
Package proto is a reverse proxy.
Package proto is a reverse proxy.

Jump to

Keyboard shortcuts

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