Skip to main content

InMemoryLeaseCoordinator

Struct InMemoryLeaseCoordinator 

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

The honest in-process reference coordinator: a linearizable CAS register behind Arc<Mutex> (genuinely linearizable within one process — the mutex serializes every CAS), over an injected WallClock for server-authoritative expiry. Clone shares the same register, so two device handles contend over one linearizable cell — exactly the concurrency the exclusivity/fencing tests exercise.

This cannot be backed by an eventually-consistent store. A synced-folder / FsRelay-style backend gives no consensus, so two sites could each “win” the same acquire — the split-brain the whole design exists to prevent. The distributed coordinator (Cosmos if_match, single-writer daemon, etc.) is B6; it must supply real single-key linearizability, and this type is the contract it implements.

Implementations§

Trait Implementations§

Source§

impl Clone for InMemoryLeaseCoordinator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for InMemoryLeaseCoordinator

Source§

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

Formats the value using the given formatter. Read more
Source§

impl LeaseCoordinator for InMemoryLeaseCoordinator

Source§

fn acquire( &mut self, agent_id: &str, device_id: &str, ttl_ms: u64, ) -> Result<Lease, LeaseError>

Compare-and-swap acquire. Grants iff the agent is unheld or its lease has expired; on grant the epoch is bumped (last_epoch + 1, monotone, never reused) and expires_at_ms = now + ttl_ms. A still-valid lease (held by anyone, including the caller) returns LeaseError::Held — the holder keeps it alive with Self::renew.
Source§

fn renew( &mut self, agent_id: &str, device_id: &str, epoch: u64, ttl_ms: u64, ) -> Result<Lease, LeaseError>

Heartbeat: extend expires_at_ms without bumping the epoch. Ok iff the caller is still the current holder at epoch (even slightly past wall-clock expiry, as long as no one has stolen it — expiry only enables stealing). Otherwise LeaseError::Lost.
Source§

fn release( &mut self, agent_id: &str, device_id: &str, epoch: u64, ) -> Result<(), LeaseError>

Clean release (hook this to the supervisor’s graceful stop): iff the caller holds epoch, drop the holder so the next acquire grants immediately with the next epoch — no TTL wait. Otherwise LeaseError::Lost. The epoch counter is retained across a release so epochs never repeat.
Source§

fn current(&mut self, agent_id: &str) -> Result<Option<Lease>, LeaseError>

Linearizable read of the current lease (the tier-3 fence’s “am I still the holder at epoch?” check reads this). None when the agent is unheld (never acquired, or cleanly released). Note an expired but un-stolen lease still reports its holder — expiry alone doesn’t clear the register, only a steal or release does.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more