Skip to content

Draft on-disk format 1: framed segment log and capsule journal - #127

Merged
saworbit merged 1 commit into
mainfrom
docs/on-disk-format
Nov 12, 2026
Merged

saworbit merged 1 commit into
mainfrom
docs/on-disk-format

Conversation

@saworbit

Copy link
Copy Markdown
Owner

Description

Adds docs/on-disk-format.md, a draft spec for store format 1, and links it from docs/README.md as a draft. Nothing is implemented. This PR exists to agree the format before code lands.

Refs #96, #97, #108. Doesn't close any of them.

Why. Each of those three issues needs a change to the log, and #96's own suggested fix is a header on every record. Fixing them one at a time would change the on-disk format two or three times. This spec does it once, and makes the capsule the durable unit: everything else can be rebuilt from it.

What the spec defines:

  • One rule underneath. Ref counts are the only segment metadata that ever changes. Derive them from manifests and a segment's metadata is written once, so the whole store becomes append-only.
  • Record header. A 48-byte frame on every record, with BLAKE3 checksums. Byte layouts are fixed little-endian structures, not serde output.
  • Segment records. SEGMENT records hold the write-once metadata next to the stored bytes, replacing the JSON sidecar that's rewritten on every append and every ref-count change.
  • Capsule journal. space.journal is a separate file holding CAPSULE manifests (segment entries with content hashes, plus a BLAKE3 digest of the logical bytes), DROP, NAMESPACE, BIND, UNBIND and atomic BATCH.
    • It's separate from the segment log because serve-s3 on SPACE_STORAGE_ROOT has no log, and because rebuilding the index then reads only manifests.
  • sled becomes a rebuildable index that records how far into the journal it has applied changes. Losing space.db costs one replay, and sled stops flushing on every update.
  • Commit points. A write commits with one record, and a delete with one record. S3 overwrite and delete are one BATCH, so a crash can't orphan a capsule. A dedup hit writes nothing until its capsule commits, which fixes the ref-count drift in Interrupted writes leave orphaned segments that nothing ever reclaims #97.
  • Recovery. A half-written record at the end of a file is cut off automatically. Corruption mid-file opens the store read-only and doctor reports it.
  • Compaction. It writes a new file and swaps it in with a rename: no marker files, no manual steps, memory bounded to one record ([Storage] Make NvramLog::compact bounded-memory and crash-safe #108). The S3 read leases from Stream S3 and CLI transfers one segment at a time and honour Range #124 become in-memory pins that compaction respects.

What a reviewer should know:

Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor / cleanup
  • Docs / comments only

Checklist

Quality gates

Not applicable: docs only, no crate changes. typos is clean on both files.

  • cargo fmt --all
  • cargo clippy --all-targets -- -D warnings
  • Tests pass (cargo test --workspace)
  • cargo xtask audit (if touching crates, deps, or features)
  • Docs compile: RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps

Documentation

  • I updated relevant docs (or no user-facing changes)
  • CHANGELOG.md updated (for features, fixes, breaking changes). Not added: it's a draft spec with no behaviour change. The implementation PRs will carry the entries.

Security

  • No hardcoded secrets, tokens, or keys introduced
  • External inputs are validated (if applicable)
  • No new unsafe blocks (or they are justified and documented)

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.
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.

1 participant