Skip to content

Add exclusive table lock manager - #100

Merged
writemorecode merged 1 commit into
mainfrom
feat/lock_manager
Sep 1, 2026
Merged

Add exclusive table lock manager#100
writemorecode merged 1 commit into
mainfrom
feat/lock_manager

Conversation

@writemorecode

@writemorecode writemorecode commented Aug 30, 2026

Copy link
Copy Markdown
Owner

This PR introduces a lock manager. The locks are per-table and exclusive-only. This means that each table can be locked by at most one transaction, whether the transaction is reading or writing. We use strict two-phase locking, where all held locks are released only after a transaction has been committed. For detecting deadlocks between transaction, we maintain a directed graph where an edge (T1,T2) represents transaction T1 waiting on a table lock held by transaction T2. A cycle in this graph is a deadlock. A FIFO queue of waiting transactions is maintained for each table in order to ensure that transactions are granted table locks in the expected order.

We use Loom for testing for correctness under concurrency.

This PR only implements this lock manager module, but does not integrate it with the rest of the database system.

Introduce transaction-owned table leases with strict two-phase locking, FIFO wait queues, direct ownership handoff, and wait-for deadlock detection. Locks remain held until commit or rollback finalization completes.

Add typed lifecycle and invariant errors, database-wide DDL admission, and focused tests for contention, cancellation, deadlocks, and lease behavior.
@writemorecode
writemorecode marked this pull request as ready for review September 1, 2026 18:17
@writemorecode
writemorecode merged commit d5a2a2b into main Sep 1, 2026
2 checks passed
@writemorecode
writemorecode deleted the feat/lock_manager branch September 1, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant