In this release (v0.3.0):
- Lock modes — the five standard multi-granularity modes — intention-shared (IS), intention-exclusive (IX), shared (S), shared-intention-exclusive (SIX), and exclusive (X) — with a
constcompatibility matrix at the core of every grant decision - Hierarchical granularities — lock a database / table / page / row hierarchy correctly with intention locks; the manager enforces the matrix at every level
- Range locks — lock a contiguous span of keys (
KeyRange) for predicate / phantom protection, with overlap-based conflict detection - Sharded lock table — the resource space is partitioned across independent shards so acquisitions on unrelated resources never contend on the same mutex
- Acquire / release — non-blocking
try_acquire, single and bulk release, re-entrant acquisition, and lattice upgrades (e.g. S + IX → SIX)
Planned across the rest of the 0.x series (see dev/ROADMAP.md):
- Wait / grant queues — fair, blocking acquisition with upgrade handling
- Deadlock detection — a wait-for graph with cycle detection and configurable victim selection
Installation
[]
= "0.3"
Quick Start
use *;
// One manager, shared across all worker threads behind an `Arc`.
let lm = new;
let row = new;
let = ;
// The writer takes the row exclusively.
lm.try_acquire.unwrap;
// A concurrent reader is refused while the write lock is held.
assert_eq!;
// Once the writer commits and releases, the reader gets in.
lm.release.unwrap;
lm.try_acquire.unwrap;
Range-lock a span of keys to keep another transaction from inserting into it (phantom protection):
use *;
let lm = new;
let index = new; // the key space being protected
// Txn 1 read-locks keys [100, 200].
lm.try_acquire_range.unwrap;
// Txn 2 cannot write key 150 inside that range, but a disjoint range is free.
assert!;
lm.try_acquire_range.unwrap;
A transaction drops its whole lock set — point and range — in one call at commit or abort:
use *;
let lm = new;
let txn = new;
for id in 0..3
assert_eq!;
API Overview
For the complete reference with method tables and examples, see docs/API.md.
LockMode— the five MGL modes and the compatibility matrixLockManager— the sharded lock table (point and range locks)KeyRange— an inclusive key interval for range locksTxnIdandResourceId— opaque identifiersLockError— failure modes
Examples
Runnable examples live in examples/. Run any of them with
cargo run --example <name>:
| Example | Shows |
|---|---|
quick_start |
Acquire, conflict, release on a single row. |
two_phase_locking |
Growing-phase acquires, then release_all at commit. |
shared_upgrade |
Read under a shared lock, then upgrade to exclusive. |
hierarchy |
Intention locks over a database/table/page/row hierarchy. |
range_locks |
Range locking for phantom protection. |
concurrent |
Many threads contending on one row, with a mutual-exclusion check. |
Where It Fits
lock-db is the concurrency-control layer. It is used by:
txn-db— transactions acquire and release locks here to enforce isolationpage-db— page-granularity locks coordinate with the paged storeindex-db— range locks protect B+tree key ranges against phantoms- storage engines — any engine needing pessimistic concurrency control
It has no first-party dependencies, so it builds and tests standalone today.
Cross-Platform Support
Linux (x86_64, aarch64), macOS (x86_64, Apple Silicon), and Windows (x86_64) are first-class and verified by the CI matrix.
Contributing
See CONTRIBUTING.md and dev/DIRECTIVES.md. Before a PR: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean.