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
impl LeaderElection
Sourcepub fn new(subspace: Subspace, lease_duration: Duration) -> Result<Self>
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.
Sourcepub fn lease_duration(&self) -> Duration
pub fn lease_duration(&self) -> Duration
Returns this handle’s desired duration for its future owner records.
Sourcepub async fn poll<T>(
&self,
txn: &T,
participant: &ParticipantId,
input: &PollInput,
) -> Result<PollResult>where
T: Deref<Target = Transaction>,
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.
Sourcepub async fn state<T>(&self, txn: &T) -> Result<ElectionState>where
T: Deref<Target = Transaction>,
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.
Sourcepub async fn resign<T>(
&self,
txn: &T,
participant: &ParticipantId,
rank: Rank,
lease_duration: Duration,
) -> Result<ResignOutcome>where
T: Deref<Target = Transaction>,
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
impl Clone for LeaderElection
Source§fn clone(&self) -> LeaderElection
fn clone(&self) -> LeaderElection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more