pub struct DefaultLease { /* private fields */ }Expand description
Default lease implementation with single-index lock-free architecture.
§Performance Characteristics
is_expired(): O(1), ~10-20ns, lock-freeregister(): O(1), ~20ns, lock-free (single shard write lock)unregister(): O(1), ~20ns, lock-free (single shard write lock)cleanup(): O(N), time-limited, shard read locks (rare: 1/1000 applies)
§Memory Usage
- Per-key overhead: ~50 bytes (single DashMap entry)
- Expired keys are removed automatically during cleanup
Implementations§
Source§impl DefaultLease
impl DefaultLease
Sourcepub fn new(config: LeaseConfig) -> DefaultLease
pub fn new(config: LeaseConfig) -> DefaultLease
Creates a new default lease manager with the given configuration.
§Arguments
config- Lease cleanup strategy configuration
Sourcepub fn get_expiration(&self, key: &[u8]) -> Option<SystemTime>
pub fn get_expiration(&self, key: &[u8]) -> Option<SystemTime>
Sourcepub fn from_snapshot(data: &[u8], config: LeaseConfig) -> DefaultLease
pub fn from_snapshot(data: &[u8], config: LeaseConfig) -> DefaultLease
Restore from snapshot data (used during initialization).
Filters out already-expired keys during restoration.
§Arguments
data- Serialized snapshot dataconfig- Lease configuration to use
Sourcepub fn config(&self) -> &LeaseConfig
pub fn config(&self) -> &LeaseConfig
Returns reference to the lease configuration.
Used by StateMachine implementations to check cleanup strategy.
Trait Implementations§
Source§impl Debug for DefaultLease
impl Debug for DefaultLease
Source§impl Lease for DefaultLease
impl Lease for DefaultLease
Source§fn register(&self, key: Bytes, ttl_secs: u64)
fn register(&self, key: Bytes, ttl_secs: u64)
Register a key with TTL (Time-To-Live).
§TTL Semantics
- Absolute expiration time: The expiration time is calculated as
expire_at = SystemTime::now() + Duration::from_secs(ttl_secs)and stored internally. - Crash-safe: The absolute expiration time survives node restarts. After crash recovery, expired keys remain expired (no TTL reset).
- Persistent: The expiration time is persisted to disk during snapshot generation and graceful shutdown.
§Example
T0: register(key="foo", ttl=10) → expire_at = T0 + 10 = T10
T5: CRASH
T12: RESTART
→ WAL replay: expire_at = T10 < T12 (already expired)
→ Key is NOT restored (correctly expired)§Arguments
key- The key to register expiration forttl_secs- Time-to-live in seconds from now
§Performance
O(1) - Completely lock-free, only acquires single shard write lock
Source§fn unregister(&self, key: &[u8])
fn unregister(&self, key: &[u8])
Unregister a key’s TTL.
§Performance
O(1) - Completely lock-free, only acquires single shard write lock
Source§fn is_expired(&self, key: &[u8]) -> bool
fn is_expired(&self, key: &[u8]) -> bool
Source§fn get_expired_keys(&self, now: SystemTime) -> Vec<Bytes>
fn get_expired_keys(&self, now: SystemTime) -> Vec<Bytes>
Get all expired keys (without time limit).
This method is rarely used directly. Most cleanup happens via on_apply().
§Performance
O(N) - Iterates all keys with shard read locks
Source§fn on_apply(&self) -> Vec<Bytes>
fn on_apply(&self) -> Vec<Bytes>
Piggyback cleanup on apply operations (DEPRECATED - no longer used).
This method is kept for backward compatibility but is no longer called. Cleanup is now handled by:
- Lazy strategy: cleanup in get() method
- Background strategy: dedicated async task
§Performance
- Fast path: O(1) - always returns empty vec
Source§fn has_lease_keys(&self) -> bool
fn has_lease_keys(&self) -> bool
Source§fn may_have_expired_keys(&self, now: SystemTime) -> bool
fn may_have_expired_keys(&self, now: SystemTime) -> bool
Quick check if there might be expired keys.
This is a heuristic check - samples first 10 entries. May return false negatives but never false positives.
§Performance
O(1) - Checks first few entries only
Source§fn to_snapshot(&self) -> Vec<u8> ⓘ
fn to_snapshot(&self) -> Vec<u8> ⓘ
Serialize current lease state to snapshot.
§Performance
O(N) - Iterates all keys with shard read locks
Auto Trait Implementations§
impl !Freeze for DefaultLease
impl !RefUnwindSafe for DefaultLease
impl Send for DefaultLease
impl Sync for DefaultLease
impl Unpin for DefaultLease
impl UnwindSafe for DefaultLease
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> 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