#[non_exhaustive]pub enum LockError {
Conflict,
NotHeld,
}Expand description
Reasons a lock operation can fail.
Every fallible entry point on LockManager returns
Result<_, LockError>. The variants are deliberately coarse: a caller
either got the lock or it did not, and the few ways “did not” can happen are
distinct enough to branch on. The type is #[non_exhaustive] because later
milestones (wait queues, deadlock detection) add variants such as a timeout
and a deadlock-victim signal; matching code must keep a wildcard arm.
§Examples
use lock_db::{LockError, LockManager, LockMode, ResourceId, TxnId};
let lm = LockManager::new();
let row = ResourceId::new(1);
// Txn 1 takes an exclusive lock.
lm.try_acquire(TxnId::new(1), row, LockMode::Exclusive).unwrap();
// Txn 2 cannot get any lock on the same row right now.
assert_eq!(lm.try_acquire(TxnId::new(2), row, LockMode::Shared), Err(LockError::Conflict));
// Releasing a lock you never held is a distinct error.
assert_eq!(lm.release(TxnId::new(9), row), Err(LockError::NotHeld));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Conflict
The lock could not be granted without blocking.
The requested mode is incompatible with a mode another transaction
already holds on the resource, or the request is an upgrade
(shared to exclusive) that other shared holders are blocking. Returned
by the non-blocking try_acquire;
the caller decides whether to retry, wait, or abort.
NotHeld
A release named a (transaction, resource) pair that holds no lock.
Returned by release when the
transaction does not currently hold a lock on the resource. This usually
signals a double release or a bookkeeping bug in the caller’s
transaction layer.
Trait Implementations§
impl Copy for LockError
Source§impl<'de> Deserialize<'de> for LockError
impl<'de> Deserialize<'de> for LockError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for LockError
Source§impl Error for LockError
Available on crate feature std only.
impl Error for LockError
std only.1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()