Skip to main content

DLockBackend

Trait DLockBackend 

Source
pub trait DLockBackend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn try_acquire<'a>(
        &'a self,
        key: &'a str,
        token: &'a str,
        ttl_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, String>> + Send + 'a>>;
    fn release<'a>(
        &'a self,
        key: &'a str,
        token: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'a>>;
    fn renew<'a>(
        &'a self,
        key: &'a str,
        token: &'a str,
        ttl_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'a>>;
}
Expand description

Storage backend (Redis in production). Implementations MUST make try_acquire atomic (single Lua script / transaction).

Required Methods§

Source

fn try_acquire<'a>( &'a self, key: &'a str, token: &'a str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, String>> + Send + 'a>>

Atomically: if key is free, store token with ttl_ms and return Some(fencing_token) from a monotonic cluster counter; else None.

Source

fn release<'a>( &'a self, key: &'a str, token: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'a>>

Compare-and-delete: remove key only if it still holds token.

Source

fn renew<'a>( &'a self, key: &'a str, token: &'a str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'a>>

Extend the TTL only if key still holds token.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§