Skip to content

feat(moonpool-journal)!: rewrite as a position-keyed CLSTORE journal - #308

Merged
PierreZ merged 4 commits into
mainfrom
claude/journal-v2-clstore
Oct 7, 2026
Merged

PierreZ merged 4 commits into
mainfrom
claude/journal-v2-clstore

Conversation

@PierreZ

@PierreZ PierreZ commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Why

The old journal was a dense Raft-shaped log (index, epoch, 24-byte tag, suffix truncation only). Paros could not store Paxos state in it, so it journaled operations and folded them at boot, with checkpoint brackets and a second recovery algorithm on top. This rewrite makes the journal protocol-agnostic so paros can use it directly.

What

A from-scratch CLSTORE journal (PAR/CTRL, FAST '18): detect, disentangle crash vs. corruption, identify.

  • Positions in any order. An entry is a u64 position + an opaque 24-byte Id. Batch::put writes any position ≥ floor, with gaps and overwrites (laggy replicas). Payloads go to an arrival-order entry log. clear(range), truncate_prefix(floor), set_meta(bytes) (≤ 4 KiB, two copies). No snapshots, no compaction.
  • Layout. <dir>/meta (two copies, written one after the other) and seg-<first batch>.wal segments: header ×2 | persist log of 64-byte records | guard gap | entry log. Every batch starts on a fresh block in both logs, so no write touches an acknowledged sector. Segment headers link to the previous batch, so a missing segment is refused.
  • Durability. Batched = the paper's write(e); write(p); fsync (last batch's damaged entries are Ambiguous); Ordered = write(e); fsync; write(p); fsync (always decided, the default). Recorded per batch.
  • Recovery table: intact/valid → live; intact/damaged → record rebuilt; damaged/valid → Corrupt (or Ambiguous); both damaged in the last batch → torn, discarded durably; earlier → DoubleFault. Plus LostBatch, MetaLost, BadSegment, WrongJournal.
  • Journal::regions() / layout(position) return LayoutRegions striped by position, replacing JournalAtlas.

Bugs the crash loops found (fixed)

  1. create synced only the immediate parent: a crash lost the whole journal → sync every ancestor.
  2. Open rewrote rebuilt records before their (page-cache) entries were durable → sync entries first.
  3. Open repaired one metainfo copy while the other was unsynced → sync the meta file before any repair.
  4. A latent sector resurrected a record after a later open reused its batch number → every open durably bumps an open generation carried in batch numbers; older-generation records past what the next open saw are garbage.

Testing

  • 24 crate tests: one per recovery-table row, metainfo copies, lost batches/segments, floor/tombstones without resurrection.
  • Crash loops: paper model × moonpool full physics, for Ordered, Batched and a mode drawn per round, with crashes inside recovery. Green at 10,000 seeds per combination (~1.95M commits) before the final change (segments unlinked one at a time, each synced); default 120-seed loops green after it.
  • accept_log example (self-checking), wasm32 check, rustdoc, and sim-journal (50/50 iterations).

Draft until paros validates it on its own simulation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gmo6Uek5zmkF8DrUSpAzCn


Generated by Claude Code

claude added 4 commits October 6, 2026 22:37
The journal is rewritten from scratch. The old design was a dense
Raft-shaped log (index, epoch, 24-byte tag, suffix truncation only), which
forced a Paxos caller to journal operations and fold them at boot, with
checkpoint brackets and a second recovery algorithm on top.

The new journal implements CLSTORE (PAR/CTRL, FAST '18) and knows no
protocol:

- An entry is a u64 position plus an opaque 24-byte Id. Positions are
  written in any order, with gaps and overwrites (a lagging replica fills
  old positions while new ones arrive). Payloads go to an arrival-order
  entry log. Batch::clear adds tombstones, Batch::truncate_prefix raises the
  floor and frees whole segments from the front, and Batch::set_meta
  replaces up to 4 KiB of metainfo. No snapshots, no compaction.
- Each segment holds a persist log of 64-byte records (CLSTORE's identifier
  and persist record in one) and an entry log whose headers repeat the
  record's identity. Every batch starts on a fresh block in both, so no
  write touches an acknowledged sector. A segment header links to the last
  batch before it, so a missing segment is never read as the end.
- The metainfo lives in its own file, as two copies written one after the
  other, so at most one is ever in flight.
- Durability::Batched is the paper's protocol (one fsync; the last batch's
  damaged entries are Ambiguous). Durability::Ordered syncs the entries
  before writing the records (two fsyncs; damage is always decided). It is
  recorded per batch and may change between opens.
- Recovery rebuilds a damaged record from its intact entry, reports a
  damaged entry beside a valid record as Corrupt (or Ambiguous), discards
  torn records of the last batch durably, and refuses double faults, lost
  batches and lost metainfo.
- Journal::regions and Journal::layout list the on-disk regions as
  LayoutRegions striped by position, replacing JournalAtlas.

The crash loops found four bugs on the way, each fixed here:

- create made the directory's name durable only in its immediate parent,
  so a crash lost the whole journal. Every ancestor is now synced.
- open rewrote rebuilt persist records before the entries they came from
  (a predecessor's unsynced writes in the page cache) were durable, so a
  crash produced a record naming an entry that never landed. Entries are
  now synced first.
- open repaired a metainfo copy while the other was still unsynced, so one
  crash could tear both. The meta file is now synced before any repair.
- a record left unreadable by a crash (a latent sector) could read back
  after a later open had reused its batch number. Every open now durably
  bumps an open generation carried in batch numbers, and a record from an
  older generation beyond what the next open found is treated as garbage.

Tests: one per row of the recovery table, metainfo copies, lost batches
and segments, and crash loops under the paper's fault model and moonpool's
full physics for Ordered, Batched and a mode drawn per round, with crashes
inside recovery. All six combinations ran green at 10,000 seeds before the
last change (deleting dead segments one at a time, each unlink synced
before the next); after it, the default 120-seed loops pass. The
accept_log example, the sim-journal example (50/50 iterations), the
README and the book chapter are rewritten for the new API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gmo6Uek5zmkF8DrUSpAzCn
…etainfo

A read-only probe: no recovery, no repair, no sync, nothing created, so a
caller can ask whether a store is formatted without changing what the next
open finds (paros's boot-kind check needs it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gmo6Uek5zmkF8DrUSpAzCn
…ility

The two crash-loop tests ran all three durability settings each, past
CI's 60s kill on a loaded runner. Six tests, about 6s each in the debug
profile, run in parallel within the campaigns group.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gmo6Uek5zmkF8DrUSpAzCn
…y one segment

A batch must fit one empty segment; commit refused a bigger one with
BatchTooLarge and gave the caller no way to know the bound. paros's
acceptor, catching up a long log after a reboot, staged it as one batch
on the small geometry and was refused on every boot. fits is now the one
rule commit checks; fits_another lets a caller pack its writes into
commits that each fit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gmo6Uek5zmkF8DrUSpAzCn
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.

2 participants