Repository navigation
Commit capsules to a journal and make sled its index - #129
Merged
Merged
Conversation
Add docs/on-disk-format.md, a draft spec (not implemented) for making every durable fact rebuildable from append-only files: - A 48-byte checksummed frame on every record. - SEGMENT records that carry their write-once descriptor next to the stored bytes, replacing the JSON sidecar. - A separate capsule journal (CAPSULE manifests with a logical digest, DROP, NAMESPACE, BIND, UNBIND, atomic BATCH), with sled demoted to a rebuildable index and ref counts derived from live manifests. - Torn-tail truncation, read-only open on mid-file corruption, and compaction by generation swap. Targets #96, #97 and #108. Link it from docs/README.md as a draft.
Implement the data-log half of on-disk format 1. The NVRAM log no longer needs a sidecar: losing space.nvram.segments made every capsule unreadable (#96), and the file was rewritten whole on every append and ref-count change without an fsync. - common::format: codec for the 48-byte record frame (BLAKE3 head and body checksums), the FILE record and the SEGMENT descriptor, with byte layouts defined field by field. - nvram-sim: the log starts with a FILE record and every append writes one framed record per segment. open() scans the log to rebuild the segment map, truncates a record cut short at the end, and opens read-only when invalid bytes are followed by valid records. Stores from before format 1 are refused with a message saying so. - Ref counts are no longer stored. Opening a registry pipeline recounts them from the capsules in space.db, so an interrupted dedup write can't leave an inflated count (part of #97). Compaction refuses to run until counts have been recounted. - Deletes and GC now change only the in-memory map; a removed segment's record comes back with no references on reopen until compaction drops it. integration_test is updated for that. - Tests: codec layouts and checksums, truncation of the last record at every byte offset, mid-log damage, compaction after a recount, and registry-level reopen, dedup-crash and torn-append cases. - Docs: capsule.md, the S3 quick start, dedup and encryption notes, SECURITY.md, nvram-sim.md and CHANGELOG describe the new log. The spec now records that only the last body is checksummed on open, that an all-zero content hash means none, a forward-search limitation, and how this stands in until the journal exists. Breaking: existing space.nvram stores can't be opened. Closes #96.
Implement the capsule-journal half of on-disk format 1. Capsule records lived only in sled, so losing space.db lost the capsule list, and a crashed write could leave a content-index entry for a segment that compaction later removed. - common::format: codecs for CAPSULE manifests (segment entries with plain length and content hash, BLAKE3 digest, dedupe and requires-encryption flags, write-time policy), DROP and BATCH. Capsule gains a digest field. - nvram_sim::record_file: the open, scan and torn-tail logic from the data log, now shared with the journal. - capsule-registry: space.journal next to space.db. A write commits by appending and fsyncing a CAPSULE record, a delete by a DROP. Each record is applied to sled in one transaction with the journal position. On open, records past that position are replayed; a missing or mismatched index is rebuilt; a space.db from before the journal is refused. sled keeps per-segment reference counts and which segment each indexed hash belongs to. - New segments' hashes wait in an in-memory pending index and reach the durable content index only when their capsule commits. - The pipeline builds the manifest and digest as it writes, commits a delete before releasing segments, and read_capsule checks the digest. - Pipeline opens pair the journal with the data log's store id (a new journal adopts it; a mismatch is refused), keep the segment allocator above every id in the log, and set the log's ref counts from sled. - Tests: journal codecs; index rebuilt after deleting space.db; records an older index missed replayed; torn journal tail; crashed write leaves no index entry; store id mismatch and adoption; digest. Two integration tests move from fixed paths in the crate folder to unique temp directories. - Docs: capsule.md, the S3 quick start, dedup notes and CHANGELOG describe the journal; the spec records PR 2 as done and where the code differs from it. S3 buckets and keys still live only in sled. Part of #97.
This was referenced Nov 12, 2026
This was referenced Nov 13, 2026
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.
Description
Part of #97.
Stacked on #128, which is stacked on #127. Merge those first. Until then this diff also shows their commits; this PR's change is
ae9eb03.This implements the capsule-journal half of on-disk format 1 (spec §5–§7; PR 2 in §14). Two problems motivate it:
Capsule records lived only in sled, so losing
space.dblost the capsule list.A write that crashed after storing a segment left that segment's hash in the content index. Once compaction removed the segment, a later write could dedup against a hash pointing at nothing.
Journal record codecs (
crates/common/src/format.rs):CAPSULEmanifests carry the capsule's segment entries (plain length and content hash each), a BLAKE3 digest of the capsule, dedupe and requires-encryption flags, and the write-time policy.DROPrecords a delete;BATCHgroups records that apply together.Capsulegains adigestfield.Shared scanner (
crates/nvram-sim/src/record_file.rs): the open, scan and torn-tail logic from Store segments as framed records and rebuild the log by scanning #128, now used by both the data log and the journal.The journal (
crates/capsule-registry/src/journal.rs):space.journalsits next tospace.db. A write commits by appending and fsyncing aCAPSULErecord, a delete by aDROP.sled is an index of the journal:
space.dbwritten before the journal existed is refused.DROPcan remove a hash when its last reference goes.Pending index: new segments' hashes wait in memory, where concurrent writes can dedup against them. They reach the durable content index only when their capsule commits.
Pipeline:
read_capsulechecks the digest.Store pairing: opening a pipeline pairs the journal with the data log's store id. A new journal adopts it; a journal with capsules and a mismatched id is refused. The segment allocator is kept above every id in the log, and the log's in-memory ref counts are set from sled.
What a reviewer should know
space.dbloses them until they move onto the journal (PR 3).read_capsulechecks the digest; streaming and range reads, scrub and the S3 ETag don't yet.BATCHis implemented but nothing writes one yet.put_capsule,create_capsule_with_segments,add_segment,add_deduped_bytes), and the capsule and content operations inMetadataOp. Nothing outside the registry used them.Tests added:
BATCHrecords can't nest.crates/capsule-registry/tests/journal_test.rs:space.dbrebuilds identical capsules, ref counts and content index;space.dbcatches up by replay;With replay disabled, the replay test fails. In a real
spacectlrun, deletingspace.dband runninglist/readbrought the capsule back from the journal.Type
Checklist
Quality gates
cargo fmt --allcargo clippy --all-targets -- -D warningscargo test --workspace): 316 passedcargo xtask audit(if touching crates, deps, or features): not available in this tree. No dependency changes.RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depsDocumentation
Security
unsafeblocks (or they are justified and documented)