pub struct LeaderState {
pub ballot: u64,
pub leader_id: String,
pub priority: i32,
pub lease_expiry_nanos: u64,
pub versionstamp: [u8; 12],
}Expand description
The core leader state - stored at a single key
Contains all information needed to determine leadership without scanning candidates.
§Ballot Numbers
The ballot number works like Raft’s term:
- Monotonically increasing counter
- Higher ballot always wins
- Prevents split-brain after recovery/partition
- Incremented on every leadership claim or refresh
Fields§
§ballot: u64Ballot number (like Raft’s term)
Always increments when claiming or refreshing leadership. Higher ballot wins in any conflict.
leader_id: StringUnique identifier of the leader process
priority: i32Leader’s priority (higher = more preferred)
Used for preemption decisions when allow_preemption is enabled.
lease_expiry_nanos: u64Absolute timestamp when lease expires (nanos since epoch)
Leadership is only valid while current_time < lease_expiry_nanos.
versionstamp: [u8; 12]Versionstamp assigned when this process registered
Used for identity consistency and ordering.
Implementations§
Source§impl LeaderState
impl LeaderState
Sourcepub fn is_lease_valid(&self, current_time: Duration) -> bool
pub fn is_lease_valid(&self, current_time: Duration) -> bool
Trait Implementations§
Source§impl Clone for LeaderState
impl Clone for LeaderState
Source§fn clone(&self) -> LeaderState
fn clone(&self) -> LeaderState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LeaderState
impl Debug for LeaderState
Source§impl PartialEq for LeaderState
impl PartialEq for LeaderState
impl Eq for LeaderState
impl StructuralPartialEq for LeaderState
Auto Trait Implementations§
impl Freeze for LeaderState
impl RefUnwindSafe for LeaderState
impl Send for LeaderState
impl Sync for LeaderState
impl Unpin for LeaderState
impl UnwindSafe for LeaderState
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