Repository navigation
Description
Migrated from SergioDemianLerner/rustock#315 (issue by @SDL-A1, 2026-10-20).
Original: SergioDemianLerner/rustock#315
The crash tests rewind the checkpoint and drop the mappings. That exercises the recovery logic and it is why the suite caught real bugs during the port, but it is not a power failure: nothing ever writes half a sector.
The whole durability argument rests on claims no test currently makes:
- A slot cannot be torn, because 8 bytes divide a 512-byte sector exactly and no slot straddles one.
- A checkpoint slot that is torn fails its CRC and the previous one wins.
- A crash anywhere in heap → index → checkpoint leaves a state the next open reads correctly.
The first two are properties of the layout and the third is a property of the ordering. All three deserve a harness rather than an argument, especially since this is the backend being proposed for production state.
What done looks like
- A
TrieStore/file wrapper that drops a configurable subset of sectors on write, so recovery can be asserted after a tear at a chosen point. - The three flush steps exercised as crash boundaries — the
failcrate is the idiomatic way to place them. - A property test over tear positions: for any subset of dropped sectors, the store opens and every key durable before the last completed checkpoint is readable.
loomover the lock-free read path. The release/acquire pairing between a writer's slot store and a reader's load is written down inindex.rsand exercised by concurrent tests, which is not the same as model-checked.
Watch for
The sector-alignment claim is about what the device writes atomically, not the page. A test that tears on 4 KiB boundaries would pass while the real hazard is at 512.
@SDL-A1 commented on 2026-10-20:
Torn-write harness is in: crates/flatdb/tests/torn_writes.rs, six tests. It snapshots a database at a committed point, writes more, kills the process before the checkpoint, then rebuilds the directory with an arbitrary subset of 512-byte sectors reverted to their earlier contents. For any such subset: the store opens, every key durable at the old checkpoint reads back, nothing uncommitted appears, and the store is still writable afterwards.
One test is a control asserting the harness destroys more than twenty sectors — without it the others could pass by tearing nothing.
The first run reported a lost key and the defect was in the harness: it staged the crash by completing the flush and then reverting the checkpoint, but a completed flush also removes the index file the old capacity names, so that pairing is one no crash can reach.
loom is deliberately not here
Tried and rejected rather than skipped, so the issue should not stay open waiting for it.
loom replaces std atomics with instrumented ones that own their storage. The index's slots live inside a memory mapping, so they cannot be loom atomics without abstracting the slot array over its backing. And even then loom would check the slot protocol while the part that is actually subtle stays outside its view: whether a reader that acquires a slot sees the heap bytes the writer wrote through a raw pointer. That rests on the release/acquire pair plus append-only immutability — an argument, not something loom verifies.
A loom harness over a Vec-backed slot array would model the easy half and produce confidence about the hard half it had not earned. Reasoning written up in docs/flatdb.md.
If the concurrency story needs stronger evidence, the better spend is a sanitiser run (-Zsanitizer=thread) over the existing concurrent tests, which sees the real mapping. Filing that separately if wanted.
@SDL-A1 commented on 2026-10-20:
Done in 14aa4d2 on fix/bridge-calls-are-sequential-only (not yet merged, so this did not close itself). See docs/flatdb.md.
Activity