Skip to content

Commit afca053

Browse files
Phase 4: transactions, MVCC & durability — writer thread, group commit, snapshots, watermark reclamation
1 parent 19a428a commit afca053

17 files changed

Lines changed: 1584 additions & 29 deletions

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@ under a category (`Added` / `Changed` / `Fixed` / `Removed` / `Security`).
88

99
## [Unreleased]
1010

11+
### Phase 4 — Transactions, MVCC & durability
12+
13+
#### Added
14+
- `txn`: the embedded database handle — `Db` (create/open/clone), atomic
15+
multi-op `write` (plus `put`/`delete` helpers), and pinned, consistent read
16+
`Snapshot`s (`get`/`range`/`scan`).
17+
- A single writer thread owning the pager: drains the write queue, coalesces
18+
waiting transactions into one **group commit** (one fsync pair for the whole
19+
batch), and publishes the new version on success.
20+
- **Validate-then-apply** atomicity: every op is checked before any mutation,
21+
so a transaction is applied whole or rejected whole; post-validation I/O
22+
errors are fatal — the writer fans out `WriterStopped` and stops, leaving the
23+
database readable but unwritable (`DECISIONS.md` D8).
24+
- `Registry`: reference-counted snapshot versions and the **reclamation
25+
watermark** — a page superseded by commit `T` is returned to the allocator
26+
only once no live snapshot older than `T` remains.
27+
- A `loom` model check of the registry handoff proving a pinned reader can
28+
never observe its pages reclaimed, over every interleaving; gated behind
29+
`--cfg loom` so it never enters normal builds (`DECISIONS.md` D9).
30+
- Exit-criteria tests: crash-at-every-fsync-boundary durability (acknowledged
31+
commits always recover; interrupted ones land whole or not at all), a
32+
long-pinned reader keeping its exact view across heavy churn while
33+
reclamation defers then catches up, and a seeded deterministic simulation of
34+
interleaved writes and snapshot open/close matched against a model.
35+
36+
#### Changed
37+
- `pager`: `commit()` no longer holds the state lock across fsyncs — readers
38+
proceed during the data/meta syncs; safe under the single-writer regime
39+
(`DECISIONS.md` D10).
40+
- `btree`: entry-size validation extracted as `check_entry` so the `txn` layer
41+
can pre-validate transactions before mutating.
42+
1143
### Phase 3 — Copy-on-write B+tree
1244

1345
#### Added

Cargo.lock

Lines changed: 252 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ thiserror = "2"
3333
unwrap_used = "deny"
3434
expect_used = "deny"
3535
panic = "deny"
36+
37+
[workspace.lints.rust]
38+
# `loom` (txn's concurrency model checker) is only built under `--cfg loom`;
39+
# register the cfg so normal builds don't warn about it as unexpected.
40+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }

0 commit comments

Comments
 (0)