Skip to main content

LeaseStore

Struct LeaseStore 

Source
pub struct LeaseStore {
    root: PathBuf,
    ttl_ms: u64,
}

Fields§

§root: PathBuf§ttl_ms: u64

Implementations§

Source§

impl LeaseStore

Source

pub fn open(registry_root: &Path) -> Result<Self>

<registry_root>/leases/. Creates the directory if missing.

Source

fn content_path(&self, instance_id: &str) -> PathBuf

Source

fn lock_path(&self, instance_id: &str) -> PathBuf

Source

fn epoch_path(&self, instance_id: &str) -> PathBuf

Source

fn read(path: &Path) -> Result<OnDisk>

Source

fn next_epoch(&self, instance_id: &str, floor: u64) -> Result<u64>

Next ownership epoch for instance_id: one past the larger of the persisted counter and floor (the current file’s epoch, which a lease written before the counter existed may carry alone). Must be called inside the key’s critical section.

Source

pub fn claim( &self, instance_id: &str, boot_id: &Arc<str>, block_id: &str, session_id_hint: Option<&str>, ) -> Result<Lease, LeaseError>

Attempt to claim the lease for instance_id. Kept for the subprocess controller’s per-turn claim; see Self::claim_as.

Source

pub fn claim_as( &self, instance_id: &str, boot_id: &Arc<str>, block_id: &str, session_id_hint: Option<&str>, info: &ClaimantInfo, ) -> Result<Lease, LeaseError>

Attempt to claim the lease for instance_id.

  • Already held by boot_id (this process) for the same block → idempotent re-claim, timestamp refreshed, epoch kept.
  • Held, not yet expired, by another block of this same process → Err(HeldByOther): one driver per agent holds inside a process too (ReAgent P1 on #3738), and the newcomer is the one refused.
  • Held by another owner, not yet expired, holder not provably dead → Err(HeldByOther).
  • Unreadable and rewritten within the TTL → Err(HeldByOther) (fail closed — see module doc).
  • Free, expired, unreadable-and-stale, or held by a dead process → claimed under a new epoch.

The whole read-decide-write sequence runs inside a per- instance_id exclusive lock (see module doc comment), so there’s no window for a concurrent claimer to observe an inconsistent state.

Source

pub fn renew(&self, lease: &Lease) -> Result<(), LeaseError>

Extend a held lease’s TTL. Runs inside the same per-instance_id critical section as claim, so the ownership check and the write are atomic with respect to any concurrent claim/renew/ release for this instance — a caller that lost the lease to a TTL reclaim between its last renew and this one gets a real HeldByOther, never a silent clobber of the new owner’s file.

Source

pub fn verify(&self, lease: &Lease) -> Result<(), LeaseError>

Is lease still ours? The pre-turn fence check: a holder that was suspended past the TTL and reclaimed must find out before it starts another turn, not only at its next renew tick. Does not write.

Source

fn owned_file(&self, lease: &Lease) -> Result<LeaseFile, LeaseError>

Read the lease file and confirm lease’s owner still holds it. Caller holds the critical section.

Source

pub fn release(&self, lease: &Lease) -> Result<(), LeaseError>

Release a held lease. If it’s no longer ours — already TTL-reclaimed by another process, or re-claimed by another block of this same process — this is a safe no-op: deleting would destroy the current holder’s lease, not ours. Idempotent: releasing an already-missing lease is Ok(()). The epoch counter is never removed (see module doc).

Source

pub fn live_holder_other_than( &self, instance_id: &str, own_boot_id: &str, ) -> Result<Option<LeaseHolder>>

The current holder of instance_id’s lease if it is live — unexpired and not provably dead — and is not own_boot_id. The read-only early check callers run before doing anything shared on the agent’s behalf (spec I9); the binding decision is still claim. An unreadable, still-fresh file is reported as held with an empty holder (fail closed).

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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