Skip to main content

FencedLock

Trait FencedLock 

Source
pub trait FencedLock: DistributedLock {
    // Required methods
    fn acquire_fenced<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Option<FenceGuard>, LockError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn validate_fence<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        fence: u64,
    ) -> Pin<Box<dyn Future<Output = Result<bool, LockError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}

Required Methods§

Source

fn acquire_fenced<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<Option<FenceGuard>, LockError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

获取锁并返回单调 fence;锁已被别人持有时返回 None (fence 仍会递增,单调性不受影响)。

Source

fn validate_fence<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, fence: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, LockError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

当前 fence 计数是否仍等于 fence。

fence 在每次获取尝试(成功或失败)时递增,release 不会删除或减少它, 因此旧持有者只有在有人重新获取过之后才会被拒绝;干净释放且无人 重取时旧 fence 仍然相等。资源侧应记录已见的最大 fence 并拒绝更小的值。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§