Repository navigation
Open a store to read it without repairing it - #9
Merged
Merged
Conversation
`GlobalStore::open` is not a read: it runs recovery. It drops a staged `index.bin.tmp`, sweeps `.part` packs and half-staged record packs, cuts a torn journal tail back to the last sealed record, restores quarantined packs, and writes a fresh snapshot when there is no ledger at all. Every one of those is right after a crash, and every one of them assumes this process is the only one here. Beside a live writer they are not repairs, they are sabotage: `index.bin.tmp` is not a leftover but the snapshot being staged between its two renames, and a reader that removes it makes the writer's own `rename` fail with `ENOENT`. That is not hypothetical — it is what a concurrent test did the first time a second handle was allowed to open a store somebody was writing. So `open_read_only` reads the ledger and touches nothing: no create, no delete, no rename, no truncate. What it gives up is that a store left mid-crash reads as it stood before the interrupted save, which is a state a reader could have seen a moment earlier rather than a wrong one — and the next writer to open still performs every repair. `save_index` refuses such a handle, which makes read-only a property of the handle rather than a promise about how the caller uses it. Refused and not ignored: a dropped save would leave a caller believing it had written.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GlobalStore::openis not a read: it runs recovery. It drops a stagedindex.bin.tmp, sweeps.partpacks and half-staged record packs, cuts a torn journal tail back to the last sealed record, restores quarantined packs, and writes a fresh snapshot when there is no ledger at all.Every one of those is right after a crash, and every one of them assumes this process is the only one here. Beside a live writer they are not repairs:
index.bin.tmpis not a leftover but the snapshot being staged between its two renames, and a reader that removes it makes the writer's ownrenamefail withENOENT.That is not hypothetical. It is what a concurrent test did the first time a second handle was allowed to open a store somebody was writing — the writer failed with
store: io error: No such file or directoryand the reader withdisk I/O errordownstream of it.What this adds
GlobalStore::open_read_onlyreads the ledger and touches nothing: no create, no delete, no rename, no truncate.save_index— the one place every durable mutation reaches the disk — refuses such a handle withStoreError::ReadOnly, which makes read-only a property of the handle rather than a promise about how the caller uses it. Refused and not ignored: a dropped save would leave a caller believing it wrote.What it gives up: a store left mid-crash reads as it stood before the interrupted save. That is a state a reader could have seen a moment earlier rather than a wrong one, and the next writer to open still performs every repair.
Nothing about the on-disk format changes, and
openis untouched.Why it is safe to read a store somebody is writing
Not a new invariant — the crash-safety already there:
index.binis replaced byrename, and the open path already falls back toindex.bin.prevfor the window where the live snapshot does not exist;next_journal_recordverifies a BLAKE3 seal and stops a replay at the first incomplete record either way.Tested
cargo test -p cavs-storegreen (46 + 3), clippy clean. Two new tests:a_read_only_open_does_not_repair_anythingstages the three files each repair targets — a.tmpsnapshot, a.partpack, a torn journal tail — asserts a read-only open leaves all three exactly where they are while still reading the store, and then asserts a writer still repairs all three, so nothing is lost, only deferred to the process allowed to do it.a_read_only_store_refuses_to_savechecks the refusal is an error and that nothing landed.Consumed by
cavsdb, where the end-to-end effect is measured: achi overviewduring a full index went from 6.9 s to 291 ms ongrafana, and onlinuxfrom failing outright to 113 of 113 reads answered.