Skip to content

feat: layout-aware storage chaos (JournalAtlas, FaultFocus, replicated fault patterns) - #291

Merged
PierreZ merged 7 commits into
mainfrom
claude/moonpool-journal-chaos-jyh5r4
Oct 3, 2026
Merged

PierreZ merged 7 commits into
mainfrom
claude/moonpool-journal-chaos-jyh5r4

Conversation

@PierreZ

@PierreZ PierreZ commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Why

The simulator's storage faults don't know the layout or the replication. A random fault hits whatever sector an operation touches; most of a preallocated journal segment is zeros nobody reads. The cases recovery has to judge come in pairs: an entry and its own slot, or both copies of a header or of the metadata. Under uniform damage they almost never happen. Across replicas, independent random damage eventually hits every copy of one record and makes a valid run unwinnable, so harnesses keep their own cross-node ledgers to prevent it.

The motivation is downstream. paros wants to drop its modelled storage world and run on moonpool's disk directly (PierreZ/paros#176). That needs moonpool's faults to land where they matter and to keep every record recoverable, both decided inside moonpool. paros should only describe its layout.

What

Four layers, each knowing only what it must:

moonpool-core: LayoutRegion. A storage format describes its on-disk layout as plain data: a path, a byte range, a kind label, and an optional stripe. The stripe is the replicated record the bytes hold, as a key every replica's copy shares (a Paxos slot, a page number). It doesn't depend on the simulator.

moonpool-journal: JournalAtlas (closes #289). It maps every region recovery reads, JournalRegion::{Header, Slot, Entry, Meta}, each one as a LayoutRegion.

  • Journal::atlas() charts an open journal; JournalAtlas::scan() charts a closed directory without opening or repairing it.
  • last_batch, starts_batch, locate and regions_in round out the API.
  • The journal leaves stripe as None: its caller knows what the tags mean (LayoutRegion::striped).

moonpool-sim: FaultFocus. It sets a weight per byte range of a process's disk, plus a background weight.

  • What it scales: every family rolled per sector or per operation (read and write corruption, read and write EIO, phantom writes, sync lies, the damaging crash outcomes) has its probability multiplied by the weight of the sectors it hits.
  • Limits: weight 0 makes a sector immune. A weight never revives a family the configuration leaves at zero. Misdirected writes honour only the immunity.
  • Determinism: every roll is still drawn, so a focus changes which faults fire, never which draws decide them.
  • How to set it: SimStorageProvider::focus_faults is reachable from process code; FaultFocus::layout(regions, weight_by_kind) builds one from any layout.

moonpool-sim: replicated fault patterns.

  • SimStorageProvider::publish_layout(regions) describes a disk.
  • SimulationBuilder::replicated_storage_faults(ReplicatedFaults::new(level).group(name)) covers one process group, at one domain level (machine, zone or datacenter). Call it once per replicated group: each gets its own pattern, turn and records. Without .group(..) it covers the whole topology; processes outside every covered group keep plain storage chaos.
  • Each seed draws, per group:
    • minority: only a few domains take damage, anywhere on their disks;
    • striped: every domain takes damage, but stripe s only in the domains s mod Z rotates to; node-local and unpublished bytes are damaged only in the drawn domains;
    • rolling: one domain at a time takes damage, anywhere on its disks. The turn moves to the next domain once the damage is repaired, read off the disk: every damaged sector rewritten, truncated away or deleted, or outside every region its process publishes. A domain holding no damage passes the turn on, so an idle domain never stalls the rotation; a domain that never repairs does;
    • spared: fewer than two domains, so nothing is damaged.
  • Guarantee: a record holds damage in at most tolerance domains at once (default 1), and so does node-local data, by construction with no ledger.
  • Keyed by record: the stripe rotation is TigerBeetle's helix, keyed by record instead of file offset. TigerBeetle's replicas are bit-for-bit identical, so an offset names the same record everywhere; a replicated log whose replicas write records at different offsets needs the key.
  • Composes: the pattern works with a focus and the eligibility mask, and is inert without storage chaos.
  • Draw order: it draws after every other per-seed draw, so opting in shifts no other surface's sample.
  • Not covered: disk failure, wipes, lost unsynced directory entries.
  • SimStorageProvider::fault_pattern tells a process what its group drew; SimWorld::fault_turn(ip) names the domains holding a rolling turn.

Evidence

  • moonpool-journal: expose where an entry lives on disk, for targeted fault injection #289 acceptance: the closed scan equals the open chart; damaging each entry gets it reported at its index, corrupt or ambiguous; damaging it with its slot gets DoubleFault.
  • Aimed damage with predicted verdicts: 2,000 seeds pass and reach every verdict (418 refusals, 254 of them double faults, and 398 ambiguous batches).
  • Aimed crash physics (the Aimed crash-loop model, with the focus fed from journal.atlas().layout()): damage reported against acknowledged data went from 40 to 67 on 250 seeds. The guarantee is unchanged: a read never returns wrong data.
  • Replicated patterns:
    • Four replicas in three zones lay out 24 records at different offsets and take crash damage at a 50% rate. Over 40 seeds, under every pattern, no record and no node-local data loses copies in two zones.
    • Letting the stripe rotation damage every stripe everywhere turns that test red at seed 1.
    • Rolling: the turn holds on a damaged zone and spares the next one until the replica is rewritten in place; a truncation or an unpublishing republish frees it too; two groups over the same zones hold damage in different zones at once.
    • Mutations: dropping the damage clear on write, or ignoring the window's damage, each turn the rolling tests red. The first also caught truncate-on-open skipping the recovery re-read, now fixed.
    • Builder tests: a three-zone cluster draws a pattern every seed, none without storage chaos, and none for a process outside the named group.

Behaviour change

A crash on a vetoed (mask-ineligible) sector used to always keep the old bytes; it can now keep the new ones too. Both are legal.

Noted, not changed

the_eligibility_mask_shields_the_sectors_it_names probably checks nothing on about half its seeds: fast_local() reverts the unsynced file length on 50% of crashes, which leaves no sectors to judge. The new tests pin that knob.

Checks

  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings
  • cargo nextest run --workspace (1,281 passed) and cargo nextest run -p moonpool-sim --no-default-features (643 passed)
  • moonpool-sim with --no-default-features: clippy and the wasm32 check
  • cargo doc with no new warnings, and mdbook build. The book covers aiming faults, the replicated fault patterns, the fault reference, and the journal's layout chapter.

🤖 Generated with Claude Code

https://claude.ai/code/session_015RwKdSwzjMSg5xgAdParyr

claude added 6 commits October 3, 2026 06:27
A fault injector that knows the journal's layout can aim where recovery
has to decide instead of spreading damage over a segment that is mostly
preallocated zeros. `Atlas` names every region recovery reads and
locates it as a file and byte range:

- `Region::Header { segment, copy }`, `Slot(id)`, `Entry(id)` and
  `Meta { copy }`, each one tied to its row of the recovery table;
- `Journal::atlas` charts an open journal from what its scan verified;
- `Atlas::scan` charts a closed directory from its slot tables alone,
  without opening or repairing it, for an injector that damages bytes
  before the next boot;
- `last_batch`, `starts_batch` and `regions_in` give the batch
  boundaries and map damaged bytes back to the regions they reach.

tests/atlas.rs checks moonpool#289's acceptance: the scan of a closed
journal equals the open journal's chart, damaging each charted entry
gets it reported at its index (corrupt, or ambiguous in the last batch),
and damaging it together with its slot gets a double fault. A seeded
loop aims damage the way recovery decisions need it: part of the last
batch, an entry beside its own slot, both copies of a twin, a run of
slots. It predicts the verdict from the regions hit and checks the
reopen against it, then checks that a second reopen finds every repair
durable. 2,000 seeds are green and reach every verdict (418 refusals,
254 of them double faults, and 398 ambiguous batches); the default
run is 150 seeds.

Refs #289.

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

The simulator is layout-blind: a random storage fault hits whatever
sector an operation touches, and most of a preallocated file is zeros
nobody reads. The eligibility mask can only veto a sector. A FaultFocus
lets a harness that knows its layout say how likely: a weight per byte
range of a file, plus a background weight for the rest of that disk.

- The probability of every family rolled per sector or per operation is
  multiplied by the weight of the sectors it would hit: read and write
  corruption, read and write EIO, phantom writes, sync lies, and the
  damaging crash outcomes (their bands scale within the one roll, capped
  at the whole roll). A weight of 0 makes a sector immune. The mask
  still vetoes first, and a weight never revives a family that the
  configuration leaves at zero.
- A misdirected write honours only the immunity: its offset draw depends
  on the configured rate alone, so weighting it would move a draw.
- Every roll is drawn whatever the weights: a focus changes which faults
  fire, never which draws decide them.
- SimStorageProvider::focus_faults sets it from process code, scoped to
  that process's disk. The mask and the targeted injections are not
  reachable from a running simulation; this is. SimWorld::set_fault_focus
  does the same from a hand-driven test. A focus survives its process's
  crash and is cleared by a wipe of its storage.

A neutral focus is checked to be a no-op: the same seed produces the
same faults with or without it. Tests also check that a saturating spot
on an immune background loses exactly that sector at every crash, and
that write corruption lands only on the focused sectors. Book: the
storage-faults chapter's "Aiming Faults" and the fault reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015RwKdSwzjMSg5xgAdParyr
A third crash-loop model, Aimed, runs moonpool's full physics. After
every write it hands Journal::atlas to the disk as a FaultFocus: slots
weighted 8, entries and twin copies 4, the preallocated zeros 0.1. The
crash physics then damage identifiers and live entries instead of
zeros. The guarantee is the harsh model's: a read never returns wrong
data.

A crash can only damage the sectors dirty at that moment, so the focus
re-weighs a small set, but the gain is real. On 250 seeds, damage
reported against acknowledged data (corrupt, ambiguous and refused)
rose from 40 to 67: refusals from 1 to 4, acknowledged ambiguous entries
from 15 to 36. The test compares both models on 120 seeds (15 to 26)
and asserts that aiming raises the damage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015RwKdSwzjMSg5xgAdParyr
A storage format that knows its on-disk layout can now describe it
without depending on the simulator: a LayoutRegion is a path, a byte
range and the format's own kind label ("journal slot", "superblock",
and so on). It lives in moonpool-core as plain data, so any storage
crate can produce it.

FaultFocus::layout (moonpool-sim) weighs a list of LayoutRegions by
kind. This is how a harness aims the simulator's random faults at a
format the simulator knows nothing about. moonpool-journal's map is the
first producer; a second layout only has to list its regions.

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

The atlas is the journal's layout, not a general one, so its names now
say so:

- Atlas becomes JournalAtlas and Region becomes JournalRegion;
- the module is journal_atlas.rs, and the tests move to
  tests/journal_atlas.rs.

Its Extent type is gone. Each charted region is now a ChartedRegion: the
JournalRegion plus a LayoutRegion whose kind is JournalRegion::kind()
(the SLOT, ENTRY, HEADER and META labels). JournalAtlas::layout lists
them for FaultFocus::layout, and locate replaces extent.

The aimed crash loop now builds its focus through FaultFocus::layout
instead of walking the regions by hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015RwKdSwzjMSg5xgAdParyr
A replicated system survives disk damage only while some replica keeps
a clean copy of every record. Random faults drawn independently per disk
eventually hit every copy of one record, so a harness had to keep a
cross-node ledger to keep a run winnable. The simulator knows the
topology, so it can guarantee this by construction instead.

- LayoutRegion (moonpool-core) gains `stripe`: the replicated record the
  bytes hold, as a key every replica's copy shares (a Paxos slot, a page
  number). `None` marks node-local bytes.
- SimStorageProvider::publish_layout lets a process describe its own
  disk; a wipe clears it.
- SimulationBuilder::replicated_storage_faults(ReplicatedFaults) draws a
  FaultPattern per seed over the domains at a chosen DomainLevel:
  - minority: only a few domains take damage, anywhere on their disks;
  - helical: every domain does, but stripe s only in the domains s mod Z
    rotates to; node-local and unpublished bytes are damaged only in the
    domains drawn for them;
  - spared: fewer than two domains, so nothing inside the topology is
    damaged.
  A record loses copies in at most `tolerance` domains (default 1,
  clamped below the domain count), and so does node-local data.
- The helix is TigerBeetle's, keyed by record instead of file offset, so
  it holds where replicas write records at different offsets.
- It is a weight of zero where damage may not land, composes with a
  FaultFocus and the eligibility mask, and is inert without storage
  chaos. It draws after every other per-seed draw, so opting in shifts
  no other surface's sample.
- Not covered: disk failure, wipes, and lost unsynced directory entries.
- SimStorageProvider::fault_pattern tells a process which pattern its
  seed drew.

Tests:
- four replicas in three zones lay out 24 records at different offsets
  and take crash damage at a 50% rate; over 40 seeds no record (and no
  node-local data) loses copies in two zones, a helix reaches every
  zone, and a minority stays in its own;
- a wipe forgets the layout;
- the builder draws a pattern every seed of a three-zone cluster, and
  none without storage chaos;
- unit tests cover the rotation, a sector holding two stripes, node-local
  bytes, the tolerance clamp and the single-domain case.

Letting the helix damage every stripe everywhere turns the first test
red at seed 1. Book: the storage-faults chapter's replicated fault
patterns, and the fault reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015RwKdSwzjMSg5xgAdParyr
@PierreZ PierreZ changed the title feat: aim storage faults by layout (JournalAtlas, FaultFocus, LayoutRegion) feat: layout-aware storage chaos (JournalAtlas, FaultFocus, replicated fault patterns) Oct 3, 2026

PierreZ commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

CI note on e7fe4aa: every job was green except macos, which hung and was killed in moonpool-explorer's frontier::single_worker_explores.

I don't think it comes from this PR:

  • Not in the diff. This PR doesn't touch moonpool-explorer, and the frontier ladder doesn't use moonpool-sim's storage. The explorer is a dependency of moonpool-sim, not the other way round.
  • Where it hung. The sampled stack shows the controller spinning in Explorer::reap_one_and_process → cthread_yield, waiting for a forked worker that never exits. Before that it was in spawn_worker → fork, with macOS's libSystem_atfork_* malloc locks in the trace. That points to a fork/reap liveness problem on macOS, in the territory explorer: forked workers have no timeout, no kill-on-drop, and waitpid(-1) reaps unrelated children #262 covered (worker timeouts, kill-on-drop).
  • Linux. All the Linux jobs passed on the same commit, including sim (frontier-explore) and test.

No fix exists for it yet. The push of 953e4b4 (replicated fault patterns) re-runs every job, macOS included. If macos goes red again in the same test, I'll treat it as a real hang to root-cause rather than a flake.


Generated by Claude Code

The static helix damages every domain at once, each on its own slice of
the records. A rolling turn damages one domain at a time, anywhere on its
disks, and moves on only once that domain has recovered, so each domain
can be hit harder and recovery itself is under test.

- FaultPattern::Rolling: the turn stays on a domain while it holds
  damage and moves to the next domain in order once the damage is
  repaired. Repair is read off the disk: every sector a random fault
  damaged has been rewritten, truncated away or deleted, or is no longer
  inside a region its process publishes. A domain holding no damage
  passes the turn on when another domain's disk is up for a fault, so an
  idle domain never stalls the rotation; one that never repairs does.
  With tolerance > 1 the window spans that many consecutive domains.
- The disk image tracks damaged sectors (a crash's lost, torn or latent
  sectors, a lost synced write, phantom and misdirected writes, planted
  corruption); a write, truncation, delete, wipe or republish triggers a
  re-read before the turn next moves.
- The static helix is renamed FaultPattern::Striped; each seed draws
  minority, striped or rolling.
- ReplicatedFaults::group(name) scopes a pattern to one process group;
  replicated_storage_faults is called once per group, each with its own
  pattern, turn and records. Without a group it covers the whole
  topology. Processes outside every covered group keep plain storage
  chaos. The domain level (machine, zone, datacenter) stays per config.
- SimWorld::fault_turn(ip) names the domains holding a rolling turn;
  SimWorld::fault_pattern takes the ip whose group it asks about.

Tests:
- the turn holds on a damaged zone, spares the next one, and moves on
  once the replica is rewritten in place; a truncation and an
  unpublishing republish free it too;
- two groups over the same zones hold damage in different zones at once;
- under every pattern no record loses copies in two zones over 40 seeds;
- the builder covers only the named group.

Mutations: dropping the damage clear on write turns the repair test red,
and so does ignoring the window's damage. The first one also caught
truncate-on-open skipping the re-read, now fixed.

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

moonpool-journal: expose where an entry lives on disk, for targeted fault injection

2 participants