Skip to content

moonpool-journal: an append must not rewrite sectors a sync already made durable #299

Closed

Description

@PierreZ

Downstream: PierreZ/paros#176 (every paros role on moonpool-journal under Chaos::Storage). References: moonpool 9ed1360, paros f2b2502.

Downstream evidence. Every append rewrites bytes an earlier fdatasync already made durable:

  • Segment::append starts its data write at the block the previous batch ended in, filling the lead of the buffer from a cached copy of that block's acknowledged bytes (crates/moonpool-journal/src/segment.rs:595-648, the tail cache);
  • write_slots rewrites whole 4 KiB slot-table blocks from memory, so one new slot rewrites up to 63 acknowledged ones (segment.rs:471-496).

The simulated disk drops a sector's durability stamp on any write (crates/moonpool-sim/src/storage/image.rs:293-311), so those sectors re-enter the unsynced set and the crash model may resolve them Lost, LatentFault or Shorn. StorageConfiguration::random_for_seed, what Chaos::Storage(Random) and Swarm draw, sets crash_lost_probability up to 10 % and crash_latent_fault_probability up to 5 % (storage/config.rs:442-500). A crash in the window between the two writes of a batch and its sync can then destroy an acknowledged entry, its slot, or both: a DoubleFault on an acknowledged Paxos vote, and the journal refuses to open. The crate docs call this "harsher disks" (lib.rs, The fault model) and the crash loop only checks that the damage is reported under the Harsh model (tests/journal.rs:870-884). The lost-synced-write oracle cannot see it, by design: the sector was legitimately rewritten.

For paros this is the difference between "every storage fault moonpool can inject is in contract" and not: an acceptor that loses an acknowledged accept breaks quorum intersection, and ReplicatedFaults cannot keep a record safe when the journal's own write pattern is what exposes it. The same pattern is a torn-sector hazard on a real disk (a 512-byte sector shared by an old entry and a new one). TigerBeetle pads every prepare to its own sectors and writes a redundant header sector only after the prepare landed; FoundationDB's DiskQueue starts every commit on a fresh page.

Smallest change.

  1. Start every batch's entries on a fresh I/O-alignment block (BlockFile block, or the file's constraints() alignment when direct I/O is on). The last block of a batch is padded; data_end moves to the next block boundary. The tail cache goes.
  2. For the slot table, either write only the sectors that hold new slots (sector-granular writes through write_at, keeping the block arithmetic for direct I/O), or accept that a slot block is rewritten and rely on the existing rebuild from an intact entry row: with (1) in place the entry can no longer be lost by the same crash, so a lost slot is always rebuilt and never a DoubleFault. The docs should say which.

Cost: up to one block of padding per batch, which paros batches per Ready, so a few hundred bytes to 4 KiB per sync. Space, not syncs.

Determinism. No new draws. The write pattern changes, so every seed names a different run; the same seed must still replay.

Acceptance. In crates/moonpool-journal/tests/journal.rs:

  • the Harsh crash loop gains the Paper model's oracle: no acknowledged entry is ever lost, reported corrupt, or reported ambiguous, under crash_lost_probability 0.3, crash_latent_fault_probability 0.1, shorn_write_probability 0.2. Red today (the current harsh oracle only requires the damage to be reported).
  • A targeted test: append batch A, sync, append batch B of one small entry that shares A's last block today, crash with every dirty sector Lost, reopen: A's last entry is intact.
  • cargo xtask sim run journal under Chaos::Storage(ChaosMode::Random) with the Keep policy, and the example's assert_always! triple unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions