Struct LeaderElection

Source
pub struct LeaderElection { /* private fields */ }
Expand description

A handle for one independently scoped leader lease.

lease_duration is this caller’s non-zero desired duration. It is persisted on every successful acquisition, takeover, and renewal. Existing foreign records remain governed by their own persisted duration. The handle holds no caller-local state and performs no scheduling or retries.

Implementations§

Source§

impl LeaderElection

Source

pub fn new(subspace: Subspace, lease_duration: Duration) -> Result<Self>

Creates an election handle with the non-zero duration it will persist on successful ownership changes.

Constructing a handle does not read or initialize durable state.

Source

pub fn lease_duration(&self) -> Duration

Returns this handle’s desired duration for its future owner records.

Source

pub async fn poll<T>( &self, txn: &T, participant: &ParticipantId, input: &PollInput, ) -> Result<PollResult>
where T: Deref<Target = Transaction>,

Polls the durable lease state in the caller’s transaction.

A released state is acquired immediately. An exact, locally unexpired PollInput::Leadership renews ownership with a fresh revision. A first or changed PollInput::Observation never steals; only an exact unchanged observation may take over, or same-owner reacquire, after the observed record’s persisted duration. An expired or mismatched leadership claim yields a follower result with a reset observation and cannot renew directly.

input carries elapsed time measured by the caller, see LocalState::input. Measure it before the enclosing Database::run and reuse it for every retry attempt, making renewal and takeover decisions conservative relative to read and commit delay. After the run succeeds, adopt PollResult::next, for example with LocalState::adopt.

Renew well before the local deadline represented by Leadership, leaving headroom for scheduling delay, retries, and commit latency. This affects availability only; it is not a durable expiry or safety condition.

Source

pub async fn state<T>(&self, txn: &T) -> Result<ElectionState>
where T: Deref<Target = Transaction>,

Reads durable state without making any liveness or leadership-validity claim.

This is a snapshot only. It does not create a local observation, permit renewal or takeover, or authorize protected work.

Source

pub async fn resign<T>( &self, txn: &T, participant: &ParticipantId, rank: Rank, lease_duration: Duration, ) -> Result<ResignOutcome>
where T: Deref<Target = Transaction>,

Releases ownership only when participant, rank, and lease_duration still exactly match durable state.

The revision and persisted duration remain, so a later acquisition has a strictly newer fencing rank. A stale delayed resignation is rejected. This conditional operation does not make a liveness claim and may be used to relinquish an otherwise exact durable token after its local renewal window has elapsed.

Trait Implementations§

Source§

impl Clone for LeaderElection

Source§

fn clone(&self) -> LeaderElection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LeaderElection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.