Documentation
¶
Index ¶
- Variables
- type LockInfo
- type LockManager
- func (lm *LockManager) GetLockInfo(key []byte) *LockInfo
- func (lm *LockManager) Lock(txnID uint64, key []byte, lockType LockType, timeout time.Duration) error
- func (lm *LockManager) NumLocks() int
- func (lm *LockManager) NumTxnLocks(txnID uint64) int
- func (lm *LockManager) TryLock(txnID uint64, key []byte, lockType LockType) bool
- func (lm *LockManager) Unlock(txnID uint64, key []byte) error
- func (lm *LockManager) UnlockAll(txnID uint64)
- type LockManagerOptions
- type LockRequest
- type LockType
- type PreparedTransaction
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLockTimeout is returned when a lock request times out. ErrLockTimeout = errors.New("db: lock request timed out") // ErrDeadlock is returned when a deadlock is detected. ErrDeadlock = errors.New("db: deadlock detected") // ErrLockNotHeld is returned when trying to unlock a key not held by the transaction. ErrLockNotHeld = errors.New("db: lock not held by transaction") )
Lock Manager errors
Functions ¶
This section is empty.
Types ¶
type LockInfo ¶
type LockInfo struct {
// Holders are transactions that currently hold a lock on this key.
// For shared locks, there can be multiple holders.
// For exclusive locks, there is at most one holder.
Holders map[uint64]LockType
// WaitQueue is an ordered list of pending lock requests.
WaitQueue []*LockRequest
}
LockInfo holds information about locks on a single key.
func (*LockInfo) GetLockType ¶
GetLockType returns the lock type held by the transaction, or -1 if not held.
func (*LockInfo) HasExclusiveHolder ¶
HasExclusiveHolder returns true if there's an exclusive lock holder.
func (*LockInfo) NumHolders ¶
NumHolders returns the number of lock holders.
type LockManager ¶
type LockManager struct {
// contains filtered or unexported fields
}
LockManager manages locks for pessimistic transactions. It supports shared and exclusive locks with deadlock detection.
func NewLockManager ¶
func NewLockManager(opts LockManagerOptions) *LockManager
NewLockManager creates a new lock manager.
func (*LockManager) GetLockInfo ¶
func (lm *LockManager) GetLockInfo(key []byte) *LockInfo
GetLockInfo returns information about a lock (for debugging/testing).
func (*LockManager) Lock ¶
func (lm *LockManager) Lock(txnID uint64, key []byte, lockType LockType, timeout time.Duration) error
Lock attempts to acquire a lock on the given key for the transaction. If the lock cannot be immediately granted, it waits up to the timeout. Returns ErrDeadlock if acquiring the lock would cause a deadlock. Returns ErrLockTimeout if the timeout expires.
func (*LockManager) NumLocks ¶
func (lm *LockManager) NumLocks() int
NumLocks returns the number of keys with active locks.
func (*LockManager) NumTxnLocks ¶
func (lm *LockManager) NumTxnLocks(txnID uint64) int
NumTxnLocks returns the number of locks held by a transaction.
func (*LockManager) TryLock ¶
func (lm *LockManager) TryLock(txnID uint64, key []byte, lockType LockType) bool
TryLock attempts to acquire a lock without waiting. Returns true if the lock was acquired, false otherwise.
func (*LockManager) Unlock ¶
func (lm *LockManager) Unlock(txnID uint64, key []byte) error
Unlock releases the lock held by the transaction on the given key.
func (*LockManager) UnlockAll ¶
func (lm *LockManager) UnlockAll(txnID uint64)
UnlockAll releases all locks held by the transaction.
type LockManagerOptions ¶
LockManagerOptions configures the lock manager.
func DefaultLockManagerOptions ¶
func DefaultLockManagerOptions() LockManagerOptions
DefaultLockManagerOptions returns default options.
type LockRequest ¶
type LockRequest struct {
TxnID uint64
LockType LockType
Granted bool
Waiting chan struct{} // Closed when the lock is granted
}
LockRequest represents a pending or granted lock request.
type PreparedTransaction ¶
type PreparedTransaction struct {
// Name is the transaction identifier (XID)
Name string
// PrepareSeq is the sequence number at prepare time
PrepareSeq uint64
// WriteBatch contains the prepared writes
WriteBatch *batch.WriteBatch
}
PreparedTransaction represents a recovered prepared transaction.