pub trait DistributedLock: Send + Sync {
// Required methods
fn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn release<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
extra_ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Interface for distributed locking mechanisms. Ensures that scheduled tasks or singleton operations run exactly once across the cluster.
Required Methods§
Sourcefn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn try_acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Attempts to acquire a distributed lock.
§Arguments
key- The unique identifier for the lock.ttl_ms- Time-to-live in milliseconds before the lock automatically expires.
§Returns
Ok(true)if the lock was successfully acquired.Ok(false)if the lock is currently held by another node.Errif a cluster or connection error occurred.
Sourcefn release<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn release<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Releases a previously acquired distributed lock.
§Arguments
key- The unique identifier for the lock.
Sourcefn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
extra_ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extend<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
extra_ttl_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<(), ClusterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Extends the expiration time of an actively held lock.
§Arguments
key- The unique identifier for the lock.extra_ttl_ms- Additional time-to-live to add to the lock.