pub struct ShardedLockTable { /* private fields */ }Expand description
Sharded lock table for row-level locks 256 shards reduce contention by ~256x for uniform key distribution
Implementations§
Source§impl ShardedLockTable
impl ShardedLockTable
Sourcepub fn try_lock(
&self,
row_id: RowId,
mode: LockMode,
txn_id: TxnId,
) -> LockResult
pub fn try_lock( &self, row_id: RowId, mode: LockMode, txn_id: TxnId, ) -> LockResult
Try to acquire a lock on a row
Sourcepub fn unlock_all(&self, txn_id: TxnId) -> usize
pub fn unlock_all(&self, txn_id: TxnId) -> usize
Release all locks held by a transaction
WARNING: This method scans all 256 shards, acquiring each mutex. For a transaction holding k locks across s shards, it still visits all 256 shards at ~15ns per uncontested mutex = ~7.7µs overhead.
For better performance, use try_lock_tracked + unlock_all_tracked
which only visits the shards that actually hold locks for this txn.
Sourcepub fn try_lock_tracked(
&self,
row_id: RowId,
mode: LockMode,
txn_id: TxnId,
lock_set: &mut TransactionLockSet,
) -> LockResult
pub fn try_lock_tracked( &self, row_id: RowId, mode: LockMode, txn_id: TxnId, lock_set: &mut TransactionLockSet, ) -> LockResult
Acquire a lock and record it in the transaction’s lock set
This is the preferred API over try_lock because it enables O(k) unlock
via unlock_all_tracked instead of O(256) unlock via unlock_all.
Sourcepub fn unlock_all_tracked(
&self,
txn_id: TxnId,
lock_set: &TransactionLockSet,
) -> usize
pub fn unlock_all_tracked( &self, txn_id: TxnId, lock_set: &TransactionLockSet, ) -> usize
Release all locks tracked in a TransactionLockSet
O(k) where k is the number of locks held, instead of O(256) for unlock_all. For a typical 3-lock transaction: ~90ns instead of ~7.7µs (85× improvement).
Sourcepub fn stats(&self) -> &LockTableStats
pub fn stats(&self) -> &LockTableStats
Get statistics