pub struct LeaseStore { /* private fields */ }Expand description
Wraps an AtomicRemoteBackend with lease primitives. The lease
object is stored under a deterministic key derived from
database_key; the store reads/writes that one key.
The trait bound AtomicRemoteBackend is the type-system version
of “this backend can enforce CAS” — backends that cannot
(Turso, D1, plain HTTP without ETag) deliberately do not
implement the trait, so wiring them into a LeaseStore becomes
a compile error rather than a runtime fail-closed.
Implementations§
Source§impl LeaseStore
impl LeaseStore
pub fn new(backend: Arc<dyn AtomicRemoteBackend>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Sourcepub fn current(
&self,
database_key: &str,
) -> Result<Option<WriterLease>, LeaseError>
pub fn current( &self, database_key: &str, ) -> Result<Option<WriterLease>, LeaseError>
Read whatever lease object is currently published. None means
no lease has ever been written for this key.
Sourcepub fn try_acquire(
&self,
database_key: &str,
holder_id: &str,
ttl_ms: u64,
) -> Result<WriterLease, LeaseError>
pub fn try_acquire( &self, database_key: &str, holder_id: &str, ttl_ms: u64, ) -> Result<WriterLease, LeaseError>
Try to acquire the lease for database_key on behalf of
holder_id, valid for ttl_ms. Returns the WriterLease we
own on success. Errors:
LeaseError::Heldif a different holder owns a non-expired lease.LeaseError::LostRaceif a concurrent contender beat us.
Sourcepub fn refresh(
&self,
lease: &WriterLease,
ttl_ms: u64,
) -> Result<WriterLease, LeaseError>
pub fn refresh( &self, lease: &WriterLease, ttl_ms: u64, ) -> Result<WriterLease, LeaseError>
Refresh lease.expires_at_ms to now + ttl_ms. Fails with
Stale if the holder/generation no longer matches what’s
currently published. The returned lease is the new
in-effect record.
Sourcepub fn release(&self, lease: &WriterLease) -> Result<(), LeaseError>
pub fn release(&self, lease: &WriterLease) -> Result<(), LeaseError>
Release the lease. Only succeeds when the published lease
matches lease.holder_id + lease.generation. A stolen or
already-replaced lease returns Stale.
Auto Trait Implementations§
impl Freeze for LeaseStore
impl !RefUnwindSafe for LeaseStore
impl Send for LeaseStore
impl Sync for LeaseStore
impl Unpin for LeaseStore
impl UnsafeUnpin for LeaseStore
impl !UnwindSafe for LeaseStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request