Skip to main content

SharedLeaderElection

Struct SharedLeaderElection 

Source
pub struct SharedLeaderElection { /* private fields */ }

Implementations§

Source§

impl SharedLeaderElection

Source

pub fn create(path: impl AsRef<Path>) -> Result<Self, LeaderError>

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, LeaderError>

Source

pub fn header(&self) -> &LeaderHeader

Source

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.

Source

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).

Source

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.

Source

pub fn global_epoch(&self) -> u64

Current global epoch value.

Source

pub fn current_leader(&self) -> Option<u32>

Current leader PID, or None when there is no leader.

Source

pub fn am_i_leader(&self, my_pid: u32) -> bool

Convenience: is my_pid the current leader?

Source

pub fn election_term(&self) -> u32

Current election term. Increments on each leadership change. Subscribers can poll this to detect handovers.

Source

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.

Source

pub fn flush(&self) -> Result<(), LeaderError>

Source

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).

Trait Implementations§

Source§

impl AdaptiveInstance for SharedLeaderElection

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.
Source§

impl Send for SharedLeaderElection

Source§

impl Sync for SharedLeaderElection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.