pub struct TxnLock<TxnId, T> { /* private fields */ }
Expand description
A futures-aware read-write lock which supports transaction-specific versioning
Implementations§
source§impl<TxnId: Display + Debug + Ord + Copy, T: Clone> TxnLock<TxnId, T>
impl<TxnId: Display + Debug + Ord + Copy, T: Clone> TxnLock<TxnId, T>
sourcepub async fn read(&self, txn_id: TxnId) -> Result<TxnLockReadGuard<T>, Error>
pub async fn read(&self, txn_id: TxnId) -> Result<TxnLockReadGuard<T>, Error>
Lock this value for reading at the given txn_id
.
sourcepub fn try_read(&self, txn_id: TxnId) -> Result<TxnLockReadGuard<T>, Error>
pub fn try_read(&self, txn_id: TxnId) -> Result<TxnLockReadGuard<T>, Error>
Synchronously Lock this value for reading at the given txn_id
, if possible.
sourcepub async fn read_exclusive(
&self,
txn_id: TxnId
) -> Result<TxnLockReadGuardExclusive<T>, Error>
pub async fn read_exclusive(
&self,
txn_id: TxnId
) -> Result<TxnLockReadGuardExclusive<T>, Error>
Lock this value for exclusive reading at the given txn_id
.
sourcepub fn try_read_exclusive(
&self,
txn_id: TxnId
) -> Result<TxnLockReadGuardExclusive<T>, Error>
pub fn try_read_exclusive(
&self,
txn_id: TxnId
) -> Result<TxnLockReadGuardExclusive<T>, Error>
Synchronously lock this value for exclusive reading at the given txn_id
, if possible.
sourcepub async fn write(&self, txn_id: TxnId) -> Result<TxnLockWriteGuard<T>, Error>
pub async fn write(&self, txn_id: TxnId) -> Result<TxnLockWriteGuard<T>, Error>
Lock this value for writing at the given txn_id
.
sourcepub fn try_write(&self, txn_id: TxnId) -> Result<TxnLockWriteGuard<T>, Error>
pub fn try_write(&self, txn_id: TxnId) -> Result<TxnLockWriteGuard<T>, Error>
Synchronously lock this value for writing at the given txn_id
, if possible.
source§impl<TxnId: Debug + Display + Copy + Ord, T: Clone> TxnLock<TxnId, T>
impl<TxnId: Debug + Display + Copy + Ord, T: Clone> TxnLock<TxnId, T>
sourcepub async fn commit(&self, txn_id: TxnId) -> Option<TxnLockCommit<TxnId, T>>
pub async fn commit(&self, txn_id: TxnId) -> Option<TxnLockCommit<TxnId, T>>
Commit the value of this TxnLock
at the given txn_id
.
This will wait until any earlier write locks have been committed or rolled back.
Panics:
- when called with a
txn_id
which has already been finalized. - when attempting to commit a version at a
txn_id
less than the last committed version
sourcepub async fn rollback(&self, txn_id: &TxnId) -> Option<TxnLockRollback<T>>
pub async fn rollback(&self, txn_id: &TxnId) -> Option<TxnLockRollback<T>>
Roll back the value of this TxnLock
at the given txn_id
.
Returns the version that was rolled back, if any lock was acquired at txn_id
.
Panics:
- if the initial version is rolled back
- if a committed version is rolled back
sourcepub async fn finalize(&self, txn_id: &TxnId) -> Option<TxnLockFinalize<T>>
pub async fn finalize(&self, txn_id: &TxnId) -> Option<TxnLockFinalize<T>>
Drop all values of this TxnLock
as old as than the given txn_id
up to the last commit.
Returns Some(Arc<T>)
with the finalized version, if any lock was acquired at txn_id
.
Panics:
- if the initial version is finalized before being committed
- if the last commit is finalized