Trait migrate_state::StateLock[][src]

pub trait StateLock {
    #[must_use]
    fn lock<'async_trait>(
        self: Box<Self>,
        force: bool
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn StateGuard>>> + Send + 'async_trait>>
    where
        Self: 'async_trait
; }
Expand description

Lock over a migration state storage.

It guards underlying migration state preventing concurrent access from multiple threads and processes. Ideally, this should be a distributed lock implementation.

The main method of this trait is StateLock::lock(), see its docs for more details.

Required methods

General concept

Acquires exclusive lock to migration state.

Acquiring exclusive lock means that no other subjects (threads, current and other remote compute instance’s processes) can access the state. Future returned by this method should be resolved only after the lock is unlocked (via StateGuard::unlock()) if it is currently locked, or resolve right away if no other subject is holding the lock.

This means that if some other subject is already holding a lock, we should wait for it to unlock it (by awaiting returned future to resolve).

The lock has to be held until a call to StateGuard::unlock() on returned StateGuard implementation.

Described behavior is expected when the force parameter is false

Boolean force parameter

When the force boolean parameter is set to true, method must acquire exclusive lock even if it currently acquired by some other subject and provide the access to underlying state storage regardless.

This operation is dangerous, because it bypasses locking mechanism which may lead to concurrent state storage mutations. It exists to help circumvent situations where some subject has died without unlocking the lock, thus leaving it locked potentially forver.

Implementors