Skip to content

Refuse to open a store whose capsule journal is missing - #206

Merged
saworbit merged 1 commit into
mainfrom
fix/missing-journal
Nov 14, 2026
Merged

saworbit merged 1 commit into
mainfrom
fix/missing-journal

Conversation

@saworbit

Copy link
Copy Markdown
Owner

Fixes #194

  • CapsuleRegistry::open refuses to open a space.db that has a journal position when space.journal is missing. It checks before Journal::open, so no new journal is created and nothing in the store changes. The error names both files and says to restore the journal.
  • bind_store takes whether the data log or storage root holds segments, and refuses to let a journal with no records adopt a store that does. This covers the case where space.db is gone too, from a backup that kept only space.nvram or the storage root. For the data log, it checks whether there are any segments. For a storage root, it checks for any segment file, which is the same scan as the id floor. A new store with an empty data log still pairs as before.
  • Every path in the issue now stops at one of the two guards: list, gc and compact at the first, and create and serve-s3 at whichever applies. So neither a manual compaction nor the startup reclaim can run. I left open_registry(Open::Existing) as it was, accepting either file: with only space.db present, the registry's own error is clearer than "no SPACE store".
  • The two tests that deleted the journal on purpose now get what they wanted without doing that. a_lost_index_never_reuses_a_segment_id loses only space.db, after a deleted capsule leaves its segment file behind, which still checks the id floor. The legacy-names test forces its rebuild with another store's journal.
  • The data log side already fails closed: a missing space.nvram makes a new log with another store id, which a journal with records refuses as "different stores". So a missing journal and a missing data log follow the same rule, as your comment asked with [fold] One generation swap for data-log and journal compaction #191 in mind.

Tests: a journal test (missing journal, then missing space.db too, with space.nvram byte-for-byte unchanged), a storage-root test (the segment file unchanged), and a CLI test where list, compact, gc and serve-s3 all exit with the error, no journal is created, and space.nvram is unchanged. Then with space.db gone too, serve-s3 and create refuse. Six mutants each fail a test: either guard removed (caught at the registry and CLI level), and the data log or storage root reporting no segments. By hand, the issue's repro (a 6 MB capsule, rm space.journal, serve-s3) now exits 1 with the message, and space.nvram stays 6000376 bytes.

Docs: CHANGELOG (Fixed), on-disk-format §3, and the failure modes table in capsule.md.

A used space.db without its space.journal used to rebuild the index from a
new, empty journal, leave every segment unreferenced, and let the next
reclaim delete them. The registry now refuses to open a space.db that has
been used without its journal, and a new journal won't pair with a data
log or storage root that already holds segments. Nothing in the store
changes either way.

Fixes #194
@saworbit
saworbit enabled auto-merge (squash) November 14, 2026 02:16
@saworbit
saworbit merged commit a7c9571 into main Nov 14, 2026
3 checks passed
@saworbit
saworbit deleted the fix/missing-journal branch November 14, 2026 21:54
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.

[Audit] Registry: a missing space.journal opens as an empty store, and the next reclaim erases every segment

1 participant