Repository navigation
Move S3 buckets and keys onto the capsule journal - #130
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.
Implement the names half of on-disk format 1. S3 buckets and keys lived only in sled, so losing space.db lost them, and an S3 overwrite bound the new key and deleted the old capsule in separate steps, so a crash in between could leave the old capsule alive with no key pointing at it. - common::format: codecs for NAMESPACE, BIND and UNBIND. A namespace can't be empty or contain NUL, checked on encode and decode. BATCH sub-records drop their frame (kind, version, reserved, header_len, header): embedded whole records made a torn batch look like damage in the middle of the journal, which then refused to open. - CapsuleCatalog has one commit(records) that commits several records as a BATCH and returns the capsules its DROPs removed; create_capsule and delete_capsule are built on it. - capsule-registry: commit checks CAPSULE and DROP records against the index under the journal lock, so a DROP of a capsule that isn't live fails the whole commit and nothing is written. sled indexes names in namespaces and names trees; the s3_buckets and s3_objects trees and the MetadataLog that wrote them are gone. A pre-journal space.db holding S3 buckets is refused like one holding capsules, and a rebuild drops the old trees. The index version goes to 2. - pipeline: finish_write_with commits a write together with other records, commit commits records alone, and release frees a dropped capsule's segments, so a caller can hold them while a reader finishes. stage_from_reader leaves a streamed write for the caller to commit. - protocol-s3: buckets are namespaces "s3:<bucket>" and keys are names. PUT commits the capsule, its key, the bucket if new and the drop of the replaced capsule as one batch; DELETE commits the unbind and the drop as one. Overwrites and DELETEs commit at once; a GET in flight holds the dropped capsule's segments until it ends, instead of delaying the delete. A failed PUT no longer creates its bucket. - Tests: name codecs and namespace rules; a batch cut at every byte is dropped as a torn tail; names rebuilt after deleting space.db; a refused commit writes nothing; a torn overwrite batch leaves the old key; pre-journal S3 names refused or dropped; S3 keys survive a lost index; the GET-during-overwrite test now checks segments stay pinned. - Docs: the spec records PR 3 as done, the new BATCH layout and where the code differs; capsule.md, the S3 quick start, streaming reads, dedup notes and CHANGELOG describe names in the journal. Part of #97.
This was referenced Nov 12, 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 #129, which is stacked on #128 and #127. Merge those first. Until then this diff also shows their commits; this PR's change is
aef538b.This implements the names half of on-disk format 1 (spec §5.5–§5.7 and §7; PR 3 in §14). Two problems motivate it:
S3 buckets and keys lived only in sled, so losing
space.dblost them, even though Commit capsules to a journal and make sled its index #129 made the capsule list recoverable.An S3 overwrite bound the new key and deleted the old capsule in separate steps. A crash in between could leave the old capsule alive with no key pointing at it, or the new one without its key.
Name record codecs (
crates/common/src/format.rs):NAMESPACE,BINDandUNBINDuse the layouts the spec drafted. A namespace can't be empty or contain NUL; both encode and decode check this.BATCHsub-records no longer carry a frame. They are now kind, version, a reserved field, header length and header (spec §5.7). See the first reviewer note for why.One commit path:
CapsuleCatalog::commit(records)commits several records as oneBATCHand returns the capsules itsDROPs removed.create_capsuleanddelete_capsuleare now provided methods built on it.Registry (
crates/capsule-registry):commitchecksCAPSULEandDROPrecords against the index while holding the journal lock (Journal::lock/JournalWriter::append). ADROPof a capsule that isn't live fails the whole commit, and nothing is written.namespacesandnamestrees. Thes3_bucketsands3_objectstrees, and theMetadataLogthat wrote them, are gone.create_namespace,namespace_created_at,name,list_names.Pipeline (
crates/pipeline):finish_write_withcommits a write together with other records.commitcommits records on their own.releasefrees a dropped capsule's segments. Until it's called, those segments stay readable, which is how a GET in flight pins them.stage_from_readerstreams a write and leaves committing it to the caller.S3 view (
crates/protocol-s3):s3:<bucket>and keys are names in them.BATCH. A DELETE commits the unbind and the drop as one.Type
Checklist
Quality gates
cargo fmt --allcargo clippy --all-targets -- -D warnings(run with--workspace)cargo test --workspace): 326 passed, 0 failedcargo xtask audit(if touching crates, deps, or features): not available in this tree; no dependency changesRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depsDocumentation
Security
s3:prefix for buckets), so an oversized one getsInvalidBucketNameorInvalidArgumentinstead of failing after the body is storedunsafeblocks (or they are justified and documented)Dependency changes (skip if none)
None.
What a reviewer should know
BATCHencoding from Commit capsules to a journal and make sled its index #129 had a bug. Sub-records were complete framed records. When a crash cuts off aBATCH, the open scan searches forward for the next valid record. It found one of those embedded sub-records, reported damage in the middle of the journal, and the journal refused to open. Nothing wrote aBATCHuntil this PR, so it never showed up. A new torn-overwrite test caught it. Format 1 hasn't shipped, so I changed the encoding rather than working around it. A unit test now cuts aBATCHat every byte and checks the journal opens with only the earlier record.space.dbthat holds S3 buckets but has no journal position (one written bymain) is refused rather than cleared, so going back tomainstill finds them.Pipeline::garbage_collectdoesn't know about them and would remove a pinned segment, but nothing calls it whileserve-s3runs. The spec (§14) notes this.a_failed_upload_stores_nothing).content_entries(), which has been trivially empty since Commit capsules to a journal and make sled its index #129 moved uncommitted hashes to the pending index. It now waits on the data log.CapsuleRegistry::{create_bucket, bucket_created_at, object, bind_object, unbind_object, list_objects}are replaced by the generic name API.Journal::commitis replaced bylock/append.metadata_log.rsandmetadata_ops.rsare removed.spacectl deleteof a named capsule leaves the name, which reads as missing (open question 6, kept as is).DROPfails the refused-commit test.spacectl serve-s3run: put, overwrite, delete and create an empty bucket, then deletespace.dband restart. The keys, the empty bucket and the deletion all came back, andspacectl listshowed only the live capsules.