pub struct SharedLeaderElection { /* private fields */ }Implementations§
pub fn create(path: impl AsRef<Path>) -> Result<Self, LeaderError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, LeaderError>
pub fn header(&self) -> &LeaderHeader
Sourcepub fn try_claim_leadership(&self, my_pid: u32, grace_epochs: u64) -> bool
pub fn try_claim_leadership(&self, my_pid: u32, grace_epochs: u64) -> bool
Attempt to claim leadership for my_pid. Returns true if
successful (now leader) or already leader; false if the
current leader is alive AND has a lower or equal PID.
grace_epochs is the staleness window: when the current
leader’s heartbeat is more than this many epochs behind the
global epoch, the leader is presumed dead and any process
can claim.
Sourcepub fn beat_as_leader(&self, my_pid: u32) -> bool
pub fn beat_as_leader(&self, my_pid: u32) -> bool
Heartbeat as the current leader. Updates the heartbeat to
the current global epoch. Returns true if the caller is
still leader (so the heartbeat counts), false if another
process has taken over (caller is no longer leader).
Sourcepub fn tick_epoch(&self) -> u64
pub fn tick_epoch(&self) -> u64
Advance the global epoch by 1 and return the new value. Typically called by the leader once per scan tick.
Sourcepub fn global_epoch(&self) -> u64
pub fn global_epoch(&self) -> u64
Current global epoch value.
Sourcepub fn current_leader(&self) -> Option<u32>
pub fn current_leader(&self) -> Option<u32>
Current leader PID, or None when there is no leader.
Sourcepub fn am_i_leader(&self, my_pid: u32) -> bool
pub fn am_i_leader(&self, my_pid: u32) -> bool
Convenience: is my_pid the current leader?
Sourcepub fn election_term(&self) -> u32
pub fn election_term(&self) -> u32
Current election term. Increments on each leadership change. Subscribers can poll this to detect handovers.
Sourcepub fn step_down(&self, my_pid: u32) -> bool
pub fn step_down(&self, my_pid: u32) -> bool
Voluntarily release leadership. Returns true if the caller
was the leader at the moment of release.
pub fn flush(&self) -> Result<(), LeaderError>
Sourcepub fn flush_async(&self) -> Result<(), LeaderError>
pub fn flush_async(&self) -> Result<(), LeaderError>
Non-blocking flush: schedules a writeback via the OS. Note: Windows is only partially async (sync to page cache, not to disk).