distribute/election/raft_lite
Types
A tiny “raft-lite” helper. This is a lightweight, deterministic
leader selection module built on top of membership. It does not
implement full Raft semantics (log replication, terms, safety), but
provides a small and well-tested way to elect a leader among alive
nodes. It is useful as a pragmatic default and as a base for a
future full Raft implementation.
pub type ElectionResult {
Leader(String)
NoLeader
}
Constructors
-
Leader(String) -
NoLeader
Values
pub fn current_leader() -> option.Option(String)
Convenience: return the current leader as Option(String).
pub fn elect() -> ElectionResult
Elect a leader from the current alive members. The election rule is
deterministic: choose the lexicographically largest node returned by
membership.alive(). Returns NoLeader when there are no alive nodes.
pub fn get_raft_leader() -> option.Option(String)
Get the current leader from the Raft service. Returns the leader node name, or empty string if no leader.
pub fn request_vote(term: Int, candidate: String) -> Bool
Request a vote from a peer for the given term and candidate. Returns True if the vote was granted.
pub fn send_heartbeat(leader: String) -> Nil
Send a heartbeat as leader to maintain leadership.
pub fn start_election() -> Nil
Trigger a new election. The node will become a candidate and request votes.
pub fn start_service() -> Nil
Start the Raft-lite election service. This spawns a background process that handles election timeouts and heartbeats.