Trait migrate_state::StateLock [−][src]
pub trait StateLock {
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
The lock over a migration state storage.
It guards the 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 the exclusive lock to the migration state.
Acquiring the exclusive lock means that no other subjects
(threads, current and other remote compute instance’s processes)
can access the state. The future returned by this method should
be resolved only once 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 the returned future to resolve).
The lock has to be held until a call to StateGuard::unlock()
on
the returned StateGuard
implementation.
The described behavior is expected when the force
parameter is false
Boolean force
parameter
When the force
boolean parameter is set to true
, the method must
acquire the exclusive lock even if it currently acquired by some other subject
and provide the access to the unrelying storage for the state regardless.
This operation is dangerous, because it bypasses the locking mechanism which may lead to concurrent state storage mutations. It exists to help circumvent the situations where some subject has died without unlocking the lock, thus leaving it locked potentially forver.