pub struct ElectionState {
pub timer: ElectionTimer,
pub votes: VoteTracker,
pub current_term: Term,
}Expand description
Election state machine
Fields§
§timer: ElectionTimerCurrent election timer
votes: VoteTrackerVote tracker for current election
current_term: TermCurrent term being contested
Implementations§
Source§impl ElectionState
impl ElectionState
Sourcepub fn new(
cluster_size: usize,
min_timeout_ms: u64,
max_timeout_ms: u64,
) -> Self
pub fn new( cluster_size: usize, min_timeout_ms: u64, max_timeout_ms: u64, ) -> Self
Create a new election state
Sourcepub fn start_election(&mut self, term: Term, self_id: &NodeId)
pub fn start_election(&mut self, term: Term, self_id: &NodeId)
Start a new election for the given term
Sourcepub fn reset_timer(&mut self)
pub fn reset_timer(&mut self)
Reset the election timer (when receiving valid heartbeat)
Sourcepub fn should_start_election(&self) -> bool
pub fn should_start_election(&self) -> bool
Check if election timeout has occurred
Sourcepub fn record_vote(&mut self, node_id: NodeId) -> bool
pub fn record_vote(&mut self, node_id: NodeId) -> bool
Record a vote and check if we won
Sourcepub fn update_cluster_size(&mut self, cluster_size: usize)
pub fn update_cluster_size(&mut self, cluster_size: usize)
Update cluster size
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ElectionState
impl RefUnwindSafe for ElectionState
impl Send for ElectionState
impl Sync for ElectionState
impl Unpin for ElectionState
impl UnwindSafe for ElectionState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more