Skip to main content

ThreadLocker

Struct ThreadLocker 

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

A thread-based locker that shares locks with other ThreadLockers on the same thread.

ThreadLocker extends BasicLocker to track which thread created it. All ThreadLockers on the same thread share locks with each other, which allows multiple cursors to operate without lock conflicts.

This is used for auto-commit operations where a transaction context is not explicitly provided.

Implementations§

Source§

impl ThreadLocker

Source

pub fn new(id: i64, lock_manager: Arc<LockManager>) -> Self

Creates a new ThreadLocker for the current thread.

Registers this locker’s thread ID in the LockManager’s sharing registry so that LockImpl::try_lock() can bypass conflict detection for co-owning ThreadLockers on the same thread.

§Arguments
  • id - Unique locker ID
  • lock_manager - Shared lock manager
Source

pub fn with_timeout( id: i64, lock_manager: Arc<LockManager>, timeout_ms: u64, ) -> Self

Creates a ThreadLocker with a specified timeout.

Source

pub fn get_thread_id(&self) -> u64

Returns the thread ID that created this locker.

Source

pub fn release_all_locks(&mut self) -> Result<(), TxnError>

Release all locks held by this locker.

Source

pub fn set_lock_timeout(&mut self, timeout_ms: u64)

Sets the lock timeout.

Trait Implementations§

Source§

impl Drop for ThreadLocker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Locker for ThreadLocker

Source§

fn shares_locks_with(&self, other_id: i64) -> bool

Returns true if the other locker was created on the same thread.

Both lockers must be ThreadLockers and have the same originating thread for sharing. We check via the LockManager’s sharing registry (locker_id → thread_id).

Source§

fn id(&self) -> i64

Returns the unique ID of this locker. Read more
Source§

fn lock( &mut self, lsn: u64, lock_type: LockType, non_blocking: bool, ) -> Result<LockResult, TxnError>

Acquires a lock on the given LSN. Read more
Source§

fn release_lock(&mut self, lsn: u64) -> Result<(), TxnError>

Releases a lock on the given LSN. Read more
Source§

fn owns_write_lock(&self, lsn: u64) -> bool

Returns true if this locker owns a write lock on the given LSN.
Source§

fn is_transactional(&self) -> bool

Returns true if this locker is transactional (supports commit/abort). Read more
Source§

fn lock_timeout_ms(&self) -> u64

Returns the timeout for lock attempts in milliseconds. Read more
Source§

fn default_no_wait(&self) -> bool

Returns true if this locker uses non-blocking lock requests by default. Read more
Source§

fn close(&mut self)

Marks this locker as closed. After close, no operations should occur. Read more
Source§

fn is_open(&self) -> bool

Returns true if this locker is still open.
Source§

fn owns_any_lock(&self, lsn: u64) -> bool

Returns true if this locker owns ANY lock (read or write) on the given LSN. Read more
Source§

fn retains_locks_on_commit(&self) -> bool

Returns true if locks should be retained on commit (serializable isolation). Read more
Source§

fn is_preemptable(&self) -> bool

Returns true if this locker’s locks can be preempted/stolen. Read more
Source§

fn is_importunate(&self) -> bool

Returns true if this locker can steal other lockers’ locks. Read more
Source§

fn is_read_uncommitted_default(&self) -> bool

Returns true if this locker allows read-uncommitted by default. Read more
Source§

fn locking_required(&self) -> bool

Returns true if locking is required for this locker’s current context. Read more
Source§

fn txn_timeout_ms(&self) -> u64

Returns the transaction-level timeout in milliseconds. Read more
Source§

fn is_timed_out(&self) -> bool

Returns true if the transaction-level timeout has expired. Read more
Source§

fn lock_after_lsn_change( &mut self, _old_lsn: u64, _new_lsn: u64, ) -> Result<(), TxnError>

Called by the lock manager when an LN is moved to a new LSN without first acquiring a write lock (e.g. during eviction or cleaning). Read more
Source§

fn operation_end(&mut self) -> Result<(), TxnError>

Called at the end of a non-transactional operation to release locks. Read more
Source§

fn release_non_txn_locks(&mut self) -> Result<(), TxnError>

Releases all non-transactional locks held by this locker. Read more
Source§

fn non_txn_operation_end(&mut self) -> Result<(), TxnError>

Called after a non-transactional operation ends, releasing locks and closing the locker. Read more
Source§

fn is_serializable_isolation(&self) -> bool

Returns true if this locker uses serializable (repeatable-read) isolation. Read more
Source§

fn is_read_committed_isolation(&self) -> bool

Returns true if this locker uses read-committed isolation. Read more
Source§

fn get_txn_locker_id(&self) -> Option<i64>

Returns the transaction ID if this locker is or owns a Txn, else None. Read more

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> 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, 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.