Skip to content

Storage simulation gaps from paros#176: journal ancestor durability, striped tolerance, damage report, targeted bytes, boot-set tolerance, crash_self - #298

Closed
PierreZ wants to merge 8 commits into
mainfrom
claude/moonpool-issues-293-297-167usn
Closed

PierreZ wants to merge 8 commits into
mainfrom
claude/moonpool-issues-293-297-167usn

Conversation

@PierreZ

@PierreZ PierreZ commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Fixes #293, #294, #295, #296 and #297, one commit per fix (three for #297, one per item). These came up downstream in PierreZ/paros#176 and #202.

Commits

  • moonpool-journal: Journal::open must make every created ancestor directory durable #293 fix(moonpool-journal): Journal::open now syncs the parent of every component of dir, starting at the root. It used to sync only the immediate parent, so a crash after the first open of data/journals/<t>/<j> could drop an ancestor, and the whole journal with it. Ancestors that already existed get synced too, because an earlier open may have failed before its syncs completed.
  • ReplicatedFaults Striped: node-local damage must count against every stripe's tolerance #294 fix(moonpool-sim): under Striped, a domain allowed node-local damage now counts as damaged for every stripe. local holds tolerance - 1 domains, and the stripes rotate over the remaining domains, one domain per stripe. So no stripe can lose copies in more than tolerance domains, even when the format gives up the whole replica on node-local damage. At tolerance 1, Striped never damages node-local bytes; Minority and Rolling still do.
  • A process-visible, owner-scoped damage report #295 feat(moonpool-sim): adds SimStorageProvider::damaged() and SimWorld::damaged(ip). Each returns the caller's own damaged sectors as DamagedRange { path, sectors, kind }, sorted by path then sector. The file image now records a DamageKind for each damaged sector, in a sparse map. The call only reads and draws no randomness. A rewrite or truncation clears the entry.
  • Owner-scoped, byte-range targeted injection on FaultContext #296 feat(moonpool-sim): adds SimWorld::corrupt_process_file_bytes(ip, path, bytes), fail_process_file_with_eio and clear_process_file_eio, plus FaultContext::corrupt_bytes, fail_file_with_eio and clear_file_eio. Each one touches only the named owner's file. The byte corruption changes exactly the requested bytes, using an XOR mask computed from each byte's offset (no randomness). It updates the durability stamp, so a later crash does not report a lost synced write. A range past the durable end returns StorageError::OutOfRange.
  • Sim: per-seed replicated tolerance, a locality for .processes() groups, and SimContext::crash_self #297.1: the fault tolerance can now be set per seed. SimStorageProvider::set_fault_tolerance(k) can be called at boot; the first caller in a group wins and later calls return the value already in force. The domains are drawn as a full permutation when the pattern is drawn, and the tolerance takes a prefix of it, so setting it draws nothing. A tolerance of 0 spares the whole group.
  • Sim: per-seed replicated tolerance, a locality for .processes() groups, and SimContext::crash_self #297.2: in a group-scoped ReplicatedFaults, each .processes() member with no locality now counts as its own failure domain at every level, named after its IP. Previously the group was always Spared. This only affects the replication plan: the machine registry, link latency and attrition are unchanged. While here I found that ReplicaProcess in tests/topology.rs reported an unexpected pattern by returning an error. A process error only ends the process and never fails the run, so those tests could not fail. It now panics instead, and the existing tests still pass.
  • Sim: per-seed replicated tolerance, a locality for .processes() groups, and SimContext::crash_self #297.3: adds SimContext::crash_self(kind, recovery_delay). It schedules the same ProcessForceKill a fault injector would, one tick later, for the caller's own IP, and draws no randomness. It returns an error when called from a workload or with Graceful. The process manager now records any force-killed process as dead until it restarts, so a self-crash counts against attrition budgets.

Behaviour changes to note

  • A Striped or Minority seed now draws a full permutation instead of tolerance picks, so seeds that draw those patterns get a different random stream.
  • At tolerance 1, Striped no longer damages node-local bytes.

Tests

Each issue's acceptance test was added. Where the issue expected red on the old code (#293, #294, #297.2, and the oracle re-stamp in #296), I confirmed the test fails before the fix and passes after.

  • cargo fmt: clean
  • cargo clippy --all-targets -D warnings: clean on the workspace and on each commit
  • cargo nextest run: 1297 passed
  • cargo clippy -p moonpool-sim --no-default-features --all-targets: clean
  • wasm32 check of moonpool-sim --no-default-features: passes
  • rustdoc with -D warnings: clean
  • mdbook build: builds

The book chapters on storage faults and attrition are updated.

🤖 Generated with Claude Code

https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy


Generated by Claude Code

claude added 8 commits October 4, 2026 21:29
…able

`Journal::open` synced only the immediate parent of `dir`, so for a nested
directory (`data/journals/<tenant>/<journal>`) a crash after the first open
could drop an ancestor's name, and with it the meta, the format marker and
every synced entry: a power loss turned into an amnesiac node.

`open` now syncs the parent of every component of `dir`, root first. It
syncs pre-existing ancestors too, since an earlier open may have created
them and failed before its syncs completed.

The new `a_nested_journal_survives_a_crash_after_its_first_open` test opens
`a/b/c/wal` with `unsynced_dir_entry_loss_probability = 1.0`, appends,
crashes and reopens; it fails on the old code.

Closes #293

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
Under `FaultPattern::Striped`, stripe `s` could be damaged in the domains
its rotation picked, and node-local bytes in the independently drawn
`local` domains. A format that gives up its whole replica on node-local
damage (moonpool-journal refusing to open on a double fault, say) then
lost stripe `s` in two domains at tolerance 1: an unwinnable run.

A domain allowed node-local damage now counts as damaged for every stripe:
it may damage anything, and the stripes rotate over the other domains,
one each. So `local` holds `tolerance - 1` domains and stripe `s` is
damaged in at most `local` plus the one domain it rotates to. At the
default tolerance of 1 no node-local byte is damaged under this pattern
(minority and rolling still cover it). A striped seed draws one fewer
index than before.

The new `node_local_damage_counts_against_every_stripe` test treats any
node-local loss as the loss of every stripe in that zone and checks, over
40 seeds at tolerance 1 and 2, that no stripe loses copies in more than
`tolerance` zones; it fails on the old code.

Closes #294

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
A harness that judges storage with a 1:1 ledger (every injected fault
surfaces as one decision) needs to know what moonpool damaged on this
process's disk. The world-wide drains (`take_storage_fault_records`,
`take_storage_crash_reports`) live on `SimWorld` only, and the fault trace
is off-limits to checks.

- `SimStorageProvider::damaged()` (and `SimWorld::damaged(ip)`) list the
  sectors of the owner's named files that a random fault or a crash
  currently leaves damaged, as `DamagedRange { path, sectors, kind }`
  runs sorted by path, then sector. Read-only, no draws.
- The file image now keeps a `DamageKind` per damaged sector (`Corrupt`,
  `Lost`, `Shorn`, `Phantom`, `Misdirected`, `LostSyncedWrite`) in a
  sparse map instead of a bitset; the rolling turn reads it as before.
  A rewrite or truncation clears the entry.

Tests: a crash with `crash_lost_probability = 1` on one process and write
corruption on another, both on the same path, each report only their own
sectors, and a rewrite clears the entry; asking for the report does not
shift the random stream.

Closes #295

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
`SimWorld::corrupt_file` and `fail_file_with_eio` are path-global and
sector-granular, and a scripted `FaultInjector` cannot reach them. A
replicated format whose nodes share a path and pack several records per
sector could not damage one copy of one record on one node.

- `SimWorld::corrupt_process_file_bytes(ip, path, bytes)` durably mutates
  exactly `bytes` of `ip`'s file: each byte XORed with a nonzero mask of
  its offset (no draws), in the durable image and in the visible one
  wherever no unsynced write covers it. The durability stamp is
  recomputed, so a later crash does not report a lost synced write. A
  range past the durable end is `StorageError::OutOfRange`.
- `SimWorld::fail_process_file_with_eio` / `clear_process_file_eio`
  scope EIO to one owner's file.
- `FaultContext::corrupt_bytes`, `fail_file_with_eio` and
  `clear_file_eio` expose the three to fault injectors, by process IP.

Tests: two owners of the same path, the corruption changes only the named
bytes (across a sector boundary) of one, survives a crash without tripping
the lost-synced-write oracle (it trips without the re-stamp), and is
deterministic; owner-scoped EIO fails only its owner; a scripted fault
injector damages one replica of three byte for byte.

Closes #296

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
`ReplicatedFaults::tolerance` was a builder constant, but a system's
tolerated loss can itself be drawn per seed (a majority, a flexible
quorum, a grid that tolerates none).

- A minority or stripe rotation now draws a whole permutation of the
  group's domains up front; the damaged (or node-local) domains are a
  prefix of it, so a tolerance set later picks among them with no draw.
- `SimStorageProvider::set_fault_tolerance(k)` (and
  `SimWorld::set_fault_tolerance(ip, k)`) set the tolerance of the
  pattern covering the caller, once: the first caller in the group wins,
  later calls change nothing and return the tolerance in force. It is
  clamped below the domain count; 0 spares every member, and a rolling
  turn with no window never moves.
- The builder's tolerance stays the per-seed default.

Tests: a later tolerance takes a prefix of the drawn order and the first
caller wins; tolerance 0 spares every member under each pattern; over 40
seeds of five zones, a tolerance of 0, 2 or 3 set from each replica at
boot bounds every stripe's damaged zones, and 2 and 3 are reached.

Part of #297

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

A `.processes()` group has no locality, so a group-scoped
`ReplicatedFaults` over it saw fewer than two domains and spared every
member. Each member of a covered group without a locality now counts as
its own domain at every level, named after its IP; a `.cluster()` group
keeps its topology, and a whole-topology config is unchanged. Only the
replication plan sees these domains: the machine registry, link latency
and attrition are untouched.

The `ReplicaProcess` of the topology tests returned an error on an
unexpected pattern, which only ends the process and never fails a run;
it now panics, so those checks (old and new) can fail. The new
`a_processes_group_draws_a_pattern_over_its_members` fails without the
builder change.

The book covers both this and the boot-set tolerance.

Part of #297

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
A process that wants a power loss at an exact point of its own protocol
(a crash while a journal append's sync is in flight) had to round-trip
through a fault injector polling the state handle.

`SimContext::crash_self(kind, recovery_delay)` schedules the same
`ProcessForceKill` a fault injector does, for the caller's IP, one tick
from now: tasks aborted, connections reset, storage through crash
resolution (`CrashAndWipe` also wipes). With a delay the process
restarts after it; without one it stays down until an injector restarts
it. No draws. It fails from a workload and for `RebootKind::Graceful`.

A force-killed process is now recorded dead by the process manager
itself, so a self-crash counts against attrition budgets until it
restarts like an injector's kill does.

Test: a process syncs old bytes, writes new ones, crashes itself and
then syncs; nothing runs past the crash, every sector reads back old or
new on the next boot, and across ten seeds some sector rolled back.

Closes #297

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

Checked against paros's call sites (paros#176, #202):

- paros's driver hooks (`BuggifyHooks`) live inside the provider-generic
  driver and never hold a `SimContext`, so `crash_self` could not reach
  the kill-during-sync location #202 wants. `SimContext::self_crash()`
  returns a `SelfCrash` handle (`Clone + Send + Sync + 'static`) whose
  `crash(kind, delay)` schedules the same kill; `crash_self` is now a
  shorthand for it.
- A scripted injector aiming `corrupt_bytes` at one journal record needs
  the record's bytes, e.g. `JournalAtlas::scan` on the crashed node's
  disk. `FaultContext::storage(ip)` returns a provider scoped to that
  process's disk.

paros at 29b23e3 builds unchanged (paros-sim, parosd, tests) against this
branch through a local [patch].

Part of #297, #296

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
@PierreZ PierreZ closed this Oct 5, 2026
PierreZ pushed a commit that referenced this pull request Oct 6, 2026
…cluster() group

#297 asked for two more things besides `crash_self`; neither becomes an
API.

- A locality for `.processes()` groups (item 2). Several `.cluster()`
  groups are already supported, each with its own IP range, so a second
  role that needs failure domains (paros's matchmakers beside its
  acceptors) is a second `.cluster()` group with its own
  `replicated_storage_faults` call. Giving `.processes()` members phantom
  domains that only the replication plan would see (#298's draft) would
  make attrition, the machine registry and the fault plan disagree on
  which processes share fate. `a_second_cluster_group_draws_its_own_pattern`
  shows two `.cluster()` groups each drawing a pattern over their own
  domains (zones for one, machines for the other); registered with
  `.processes()` instead, the matchmakers draw none and it fails. The
  storage-faults chapter says so.
- A tolerance a process sets at boot (item 1) is left out: the system
  under test would configure the faults aimed at it ("first caller wins",
  with damage already done kept). The tolerance stays the builder's.

The topology tests' `ReplicaProcess` reported a wrong pattern by
returning an error, which only ends the process and never fails the run,
so those checks could not fail (found by #298's draft); it now panics.

Closes #297

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
PierreZ pushed a commit that referenced this pull request Oct 6, 2026
…cluster() group

#297 asked for two more things besides `crash_self`; neither becomes an
API.

- A locality for `.processes()` groups (item 2). Several `.cluster()`
  groups are already supported, each with its own IP range, so a second
  role that needs failure domains (paros's matchmakers beside its
  acceptors) is a second `.cluster()` group with its own
  `replicated_storage_faults` call. Giving `.processes()` members phantom
  domains that only the replication plan would see (#298's draft) would
  make attrition, the machine registry and the fault plan disagree on
  which processes share fate. `a_second_cluster_group_draws_its_own_pattern`
  shows two `.cluster()` groups each drawing a pattern over their own
  domains (zones for one, machines for the other); registered with
  `.processes()` instead, the matchmakers draw none and it fails. The
  storage-faults chapter says so.
- A tolerance a process sets at boot (item 1) is left out: the system
  under test would configure the faults aimed at it ("first caller wins",
  with damage already done kept). The tolerance stays the builder's.

The topology tests' `ReplicaProcess` reported a wrong pattern by
returning an error, which only ends the process and never fails the run,
so those checks could not fail (found by #298's draft); it now panics.

Closes #297

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tq9joyAz9Y6ptfKQB1bnnh
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: Journal::open must make every created ancestor directory durable

2 participants