Struct LockManager

Source
pub struct LockManager { /* private fields */ }
Expand description

LockManager holds the locks that transactions might have taken. A TransactionManager implementation would typically have one of these.

Three different kinds of locks are supported. There are read locks and write locks, which are as one would expect. The third kind of lock is a transaction lock (which is also known as an upgradeable read lock). When first acquired, these block other writes (including other transaction locks) but do not block reads. When it is time to commit a transaction, these locks are upgraded to full write locks (without ever dropping the lock) and then dropped after committing (unless commit_and_continue is used). This way, reads are only blocked for the shortest possible time. It follows that write locks should be used sparingly. Locks are granted in order with one exception: when a lock is in the initial transaction lock state (LockState::Locked), all read locks are allowed even if there are other tasks waiting for the lock. The reason for this is because we allow read locks to be taken by tasks that have taken a transaction lock (i.e. recursion is allowed). In other cases, such as when a writer is waiting and there are only readers, readers will queue up behind the writer.

To summarize:

+———————––+—————–+––––––––+——————+ | | While read_lock | While txn_lock | While write_lock | | | is held | is held | is held | +———————––+—————–+––––––––+——————+ | Can acquire read_lock? | true | true | false | +———————––+—————–+––––––––+——————+ | Can acquire txn_lock? | true | false | false | +———————––+—————–+––––––––+——————+ | Can acquire write_lock? | false | false | false | +———————––+—————–+––––––––+——————+

Implementations§

Source§

impl LockManager

Source

pub fn new() -> Self

Source

pub async fn txn_lock<'a>(&'a self, lock_keys: LockKeys) -> TransactionLocks<'a>

Acquires the locks. It is the caller’s responsibility to ensure that drop_transaction is called when a transaction is dropped i.e. the filesystem’s drop_transaction method should call LockManager’s drop_transaction method.

Source

pub fn drop_transaction(&self, transaction: &mut Transaction<'_>)

This should be called by the filesystem’s drop_transaction implementation.

Source

pub async fn commit_prepare(&self, transaction: &Transaction<'_>)

Prepares to commit by waiting for readers to finish.

Source

pub async fn read_lock<'a>(&'a self, lock_keys: LockKeys) -> ReadGuard<'a>

Acquires a read lock for the given keys. Read locks are only blocked whilst a transaction is being committed for the same locks. They are only necessary where consistency is required between different mutations within a transaction. For example, a write might change the size and extents for an object, in which case a read lock is required so that observed size and extents are seen together or not at all.

Source

pub async fn write_lock<'a>(&'a self, lock_keys: LockKeys) -> WriteGuard<'a>

Acquires a write lock for the given keys. Write locks provide exclusive access to the requested lock keys.

Source

pub fn downgrade_locks(&self, lock_keys: &LockKeys)

Downgrades locks from the WriteLock state to Locked state. This will panic if the locks are not in the WriteLock state.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V