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,
local_state: &LocalState,
attempt_started_at: Duration,
) -> Result<PollResult>where
T: Deref<Target = Transaction>,
pub async fn poll<T>(
&self,
txn: &T,
participant: &ParticipantId,
local_state: &LocalState,
attempt_started_at: Duration,
) -> 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
Leadership token renews ownership with a fresh revision. A first or
changed 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 token becomes
observation/reacquisition state and cannot renew directly.
attempt_started_at must be read from the caller’s monotonic clock
immediately before this call in each retry attempt. It is deliberately
before the durable read, making renewal and takeover decisions
conservative relative to read and commit delay. After the enclosing
Database::run succeeds, pass a fresh caller-clock reading to
PollResult::into_next_state to adopt the returned state.
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,
leadership: &Leadership,
) -> Result<ResignOutcome>where
T: Deref<Target = Transaction>,
pub async fn resign<T>(
&self,
txn: &T,
leadership: &Leadership,
) -> Result<ResignOutcome>where
T: Deref<Target = Transaction>,
Releases ownership only when leadership still exactly matches 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