Documentation
¶
Overview ¶
Package election provides Raft-based leader election for multi-core HA setups
Index ¶
- type Cluster
- func (c *Cluster) Apply(cmd []byte, timeout time.Duration) error
- func (c *Cluster) GetClusterSize() int
- func (c *Cluster) GetLeader() string
- func (c *Cluster) GetRaft() *raft.Raft
- func (c *Cluster) GetState() State
- func (c *Cluster) IsLeader() bool
- func (c *Cluster) Leave() error
- func (c *Cluster) ListPeers() []string
- func (c *Cluster) Shutdown() error
- func (c *Cluster) Subscribe() <-chan StateChange
- func (c *Cluster) Unsubscribe(ch <-chan StateChange)
- type Config
- type State
- type StateChange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster represents a Raft consensus cluster for leader election
func NewCluster ¶
NewCluster creates a new Raft cluster for leader election
func (*Cluster) GetClusterSize ¶
GetClusterSize returns the number of nodes in the cluster
func (*Cluster) Subscribe ¶
func (c *Cluster) Subscribe() <-chan StateChange
Subscribe subscribes to state changes
func (*Cluster) Unsubscribe ¶
func (c *Cluster) Unsubscribe(ch <-chan StateChange)
Unsubscribe unsubscribes from state changes
type Config ¶
type Config struct {
// NodeID is the unique identifier for this node
NodeID string
// Addr is the address this node listens on
Addr string
// Peers is the list of all peer addresses in the cluster
Peers []string
// BootstrapExpect is the number of nodes needed to bootstrap
BootstrapExpect int
// HeartbeatTimeout is the timeout for leader heartbeats
HeartbeatTimeout time.Duration
// ElectionTimeout is the timeout for elections
ElectionTimeout time.Duration
// CommitTimeout is the timeout for commit operations
CommitTimeout time.Duration
}
Config holds configuration for the Raft cluster
type StateChange ¶
StateChange represents a change in cluster state
Click to show internal directories.
Click to hide internal directories.