pub struct ExportLease { /* private fields */ }Expand description
Coordinates “at most one export per round” across every replica of a fold. See the module docs for the CAS + embedded-expiry mechanism.
Implementations§
Source§impl ExportLease
impl ExportLease
Sourcepub fn new(
store: &dyn KvStore,
key: impl Into<String>,
holder_id: impl Into<String>,
) -> Result<Self, KvError>
pub fn new( store: &dyn KvStore, key: impl Into<String>, holder_id: impl Into<String>, ) -> Result<Self, KvError>
A lease on key in store, identifying this node as holder_id.
Fails with KvError::OperationFailed if the store has no writer.
Sourcepub async fn try_acquire(
&self,
ttl: Duration,
) -> Result<Option<LeaseGuard>, KvError>
pub async fn try_acquire( &self, ttl: Duration, ) -> Result<Option<LeaseGuard>, KvError>
Try to win this export round. Exactly one caller fleet-wide gets
Ok(Some(guard)) per round; everyone else gets Ok(None) and skips.
ttl is the round period: the winner’s lease suppresses further rounds
until it lapses, whether or not the winner survives. Crash mid-round →
the key expires → the next trigger elects someone else.
Sourcepub async fn current(&self) -> Result<Option<LeaseRecord>, KvError>
pub async fn current(&self) -> Result<Option<LeaseRecord>, KvError>
Read the current lease record, if any — the fleet-visible “last export”
state. None when no round has ever run (or the key was tombstoned);
KvError::SerializationError when the key holds unparseable bytes —
distinct from None so an operator can see “present but corrupt” (a
state try_acquire will repair by takeover) rather
than a false “never ran”.