Documentation
¶
Overview ¶
Package lock provides deadlock detection for XxSql storage engine.
Package lock provides latch management for B+ tree operations.
Package lock provides lock management for XxSql storage engine.
Index ¶
- type CrabbingProtocol
- type Latch
- type LatchManager
- func (m *LatchManager) Acquire(pageID uint64, latchType LatchType) bool
- func (m *LatchManager) Clear()
- func (m *LatchManager) Release(pageID uint64, latchType LatchType)
- func (m *LatchManager) Remove(pageID uint64)
- func (m *LatchManager) Stats() LatchStats
- func (m *LatchManager) TryAcquire(pageID uint64, latchType LatchType) bool
- type LatchStats
- type LatchType
- type Lock
- type LockID
- type LockLevel
- type LockRequest
- type LockStats
- type LockType
- type Manager
- func (m *Manager) DetectDeadlock() []uint64
- func (m *Manager) GetLockInfo(id LockID) (shared int, exclusive uint64)
- func (m *Manager) IsLocked(id LockID) bool
- func (m *Manager) Lock(id LockID, lockType LockType, txnID uint64) error
- func (m *Manager) LockCatalog(lockType LockType, txnID uint64) error
- func (m *Manager) LockGlobal(lockType LockType, txnID uint64) error
- func (m *Manager) LockPage(tableID, pageID uint64, lockType LockType, txnID uint64) error
- func (m *Manager) LockRow(tableID, pageID, rowID uint64, lockType LockType, txnID uint64) error
- func (m *Manager) LockTable(tableID uint64, lockType LockType, txnID uint64) error
- func (m *Manager) ReleaseAllLocks(txnID uint64)
- func (m *Manager) Stats() LockStats
- func (m *Manager) TryLock(id LockID, lockType LockType, txnID uint64) bool
- func (m *Manager) Unlock(id LockID, txnID uint64) error
- func (m *Manager) UnlockCatalog(txnID uint64) error
- func (m *Manager) UnlockGlobal(txnID uint64) error
- func (m *Manager) UnlockPage(tableID, pageID uint64, txnID uint64) error
- func (m *Manager) UnlockRow(tableID, pageID, rowID uint64, txnID uint64) error
- func (m *Manager) UnlockTable(tableID uint64, txnID uint64) error
- type WaitForGraph
- func (g *WaitForGraph) AddEdge(txn1, txn2 uint64)
- func (g *WaitForGraph) DetectCycle() []uint64
- func (g *WaitForGraph) EdgeCount() int
- func (g *WaitForGraph) GetWaiters(txn uint64) []uint64
- func (g *WaitForGraph) GetWaitersOf(txn uint64) []uint64
- func (g *WaitForGraph) HasEdge(txn1, txn2 uint64) bool
- func (g *WaitForGraph) NodeCount() int
- func (g *WaitForGraph) RemoveAllEdges(txn uint64)
- func (g *WaitForGraph) RemoveEdge(txn1, txn2 uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CrabbingProtocol ¶
type CrabbingProtocol struct {
// contains filtered or unexported fields
}
CrabbingProtocol implements the crabbing protocol for B+ tree traversal. Acquires latches from root to leaf, releasing parent latches when safe.
func NewCrabbingProtocol ¶
func NewCrabbingProtocol(manager *LatchManager) *CrabbingProtocol
NewCrabbingProtocol creates a new crabbing protocol handler.
func (*CrabbingProtocol) AcquireRoot ¶
func (c *CrabbingProtocol) AcquireRoot(pageID uint64, latchType LatchType) bool
AcquireRoot acquires a latch on the root page.
func (*CrabbingProtocol) CrabDown ¶
func (c *CrabbingProtocol) CrabDown(parentID, childID uint64, childType LatchType, isSafe bool) bool
CrabDown moves from parent to child, releasing parent if safe.
func (*CrabbingProtocol) HeldCount ¶
func (c *CrabbingProtocol) HeldCount() int
HeldCount returns the number of held latches.
func (*CrabbingProtocol) ReleaseAll ¶
func (c *CrabbingProtocol) ReleaseAll()
ReleaseAll releases all held latches.
type Latch ¶
type Latch struct {
// contains filtered or unexported fields
}
Latch is a lightweight lock for B+ tree nodes.
func (*Latch) TryAcquire ¶
TryAcquire attempts to acquire a latch without blocking.
type LatchManager ¶
type LatchManager struct {
// contains filtered or unexported fields
}
LatchManager manages latches for B+ tree pages.
func NewLatchManager ¶
func NewLatchManager(timeout time.Duration) *LatchManager
NewLatchManager creates a new latch manager.
func (*LatchManager) Acquire ¶
func (m *LatchManager) Acquire(pageID uint64, latchType LatchType) bool
Acquire acquires a latch on a page.
func (*LatchManager) Clear ¶
func (m *LatchManager) Clear()
Clear removes all latches (use with caution).
func (*LatchManager) Release ¶
func (m *LatchManager) Release(pageID uint64, latchType LatchType)
Release releases a latch on a page.
func (*LatchManager) Remove ¶
func (m *LatchManager) Remove(pageID uint64)
Remove removes a latch for a page.
func (*LatchManager) Stats ¶
func (m *LatchManager) Stats() LatchStats
Stats returns latch manager statistics.
func (*LatchManager) TryAcquire ¶
func (m *LatchManager) TryAcquire(pageID uint64, latchType LatchType) bool
TryAcquire attempts to acquire a latch without blocking.
type LatchStats ¶
type LatchStats struct {
LatchCount int `json:"latch_count"`
TotalAcquires uint64 `json:"total_acquires"`
TotalWaits uint64 `json:"total_waits"`
}
LatchStats holds latch manager statistics.
type LatchType ¶
type LatchType uint8
LatchType represents the type of latch.
const ( LatchTypeExclusive )
type Lock ¶
type Lock struct {
ID LockID
Type LockType
Holder uint64 // Transaction ID
Granted bool
Timestamp int64
}
Lock represents a lock on a resource.
type LockRequest ¶
type LockRequest struct {
ID LockID
Type LockType
TxnID uint64
Granted bool
WaitStart time.Time
ResultChan chan error
}
LockRequest represents a lock request.
type LockStats ¶
type LockStats struct {
WaitCount uint64 `json:"wait_count"`
GrantCount uint64 `json:"grant_count"`
TimeoutCount uint64 `json:"timeout_count"`
TableLocks int `json:"table_locks"`
PageLocks int `json:"page_locks"`
RowLocks int `json:"row_locks"`
}
LockStats holds lock manager statistics.
type LockType ¶
type LockType uint8
LockType represents the type of lock.
const ( LockTypeExclusive )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages locks for the database.
func NewManager ¶
NewManager creates a new lock manager.
func (*Manager) DetectDeadlock ¶
DetectDeadlock checks for deadlocks.
func (*Manager) GetLockInfo ¶
GetLockInfo returns information about locks on a resource.
func (*Manager) LockCatalog ¶
LockCatalog acquires the catalog lock.
func (*Manager) LockGlobal ¶
LockGlobal acquires the global lock.
func (*Manager) ReleaseAllLocks ¶
ReleaseAllLocks releases all locks held by a transaction.
func (*Manager) UnlockCatalog ¶
UnlockCatalog releases the catalog lock.
func (*Manager) UnlockGlobal ¶
UnlockGlobal releases the global lock.
func (*Manager) UnlockPage ¶
UnlockPage releases a page lock.
type WaitForGraph ¶
type WaitForGraph struct {
// contains filtered or unexported fields
}
WaitForGraph represents a wait-for graph for deadlock detection.
func NewWaitForGraph ¶
func NewWaitForGraph() *WaitForGraph
NewWaitForGraph creates a new wait-for graph.
func (*WaitForGraph) AddEdge ¶
func (g *WaitForGraph) AddEdge(txn1, txn2 uint64)
AddEdge adds a wait-for edge from txn1 to txn2.
func (*WaitForGraph) DetectCycle ¶
func (g *WaitForGraph) DetectCycle() []uint64
DetectCycle detects if there is a cycle in the graph. Returns the transaction IDs involved in the cycle, or nil if no cycle.
func (*WaitForGraph) EdgeCount ¶
func (g *WaitForGraph) EdgeCount() int
EdgeCount returns the number of edges in the graph.
func (*WaitForGraph) GetWaiters ¶
func (g *WaitForGraph) GetWaiters(txn uint64) []uint64
GetWaiters returns all transactions that txn is waiting for.
func (*WaitForGraph) GetWaitersOf ¶
func (g *WaitForGraph) GetWaitersOf(txn uint64) []uint64
GetWaitersOf returns all transactions waiting for txn.
func (*WaitForGraph) HasEdge ¶
func (g *WaitForGraph) HasEdge(txn1, txn2 uint64) bool
HasEdge checks if there's an edge from txn1 to txn2.
func (*WaitForGraph) NodeCount ¶
func (g *WaitForGraph) NodeCount() int
NodeCount returns the number of nodes in the graph.
func (*WaitForGraph) RemoveAllEdges ¶
func (g *WaitForGraph) RemoveAllEdges(txn uint64)
RemoveAllEdges removes all edges for a transaction.
func (*WaitForGraph) RemoveEdge ¶
func (g *WaitForGraph) RemoveEdge(txn1, txn2 uint64)
RemoveEdge removes a wait-for edge from txn1 to txn2.