Skip to content

moonpool-journal: reserved slot records, and a torn identifier in the last batch ends the log #300

Closed

Description

@PierreZ

Downstream: PierreZ/paros#176. The second half is the "also worth deciding" note of #289, which PR #291 did not address. References: moonpool 9ed1360, paros f2b2502.

Downstream evidence. Two rules of the slot table disagree with the record contract paros decided on in PierreZ/paros#20 and recorded in docs/analysis/storage/clstore-record-contract.md ("every slot is formatted with a real, checksummed reserved record carrying its own slot identity, so all-zeros is always faulty, never empty"), and with the contract doc on LogStorage::boot_scan (crates/paros/src/storage/mod.rs:246-273). Today paros's doc describes a journal that does not exist; one side has to move, and this issue proposes the journal does.

  1. All zeros means "never written" (crates/moonpool-journal/src/layout.rs:301, SlotState::Empty). So a synced slot that comes back zeroed (a Lost sector past the garbage-fill prefix, a zero-filled EIO block that the walk treats as Bad today only because the read failed, a misdirected write of a zero page) reads as absent and, beside a damaged entry, ends the log: scan::decide takes (None, Empty) as the torn tail (scan.rs:100-103). That is CTRL's Figure 2 bug in disguise: an acknowledged entry past it is silently cut. TigerBeetle's answer is a reserved header per slot whose op is the slot index, fully checksummed, so zeros are always a fault and a reserved record in the wrong slot is a misdirect (vsr/journal.zig, "the op for reserved headers is set to the corresponding slot index"). The segment file is already preallocated and written whole at creation (segment.rs:229-271), so formatting the table with reserved slots costs nothing extra.

  2. A bad slot beside a bad entry is a DoubleFault everywhere, the last batch included (scan.rs:104). The last batch's entries and slots reach the disk through two unordered writes and one sync (lib.rs, Appending); a crash before that sync, with shorn_write_probability or a garbage fill, tears both and the node never boots again although nothing was acknowledged. moonpool-journal: expose where an entry lives on disk, for targeted fault injection #289 raised this and it is still open in the code.

Smallest change.

  • Format every slot of a new segment with a reserved record: index = its slot's index, epoch 0, a reserved flag, CRC over the lot. SlotState becomes Reserved(index) / Valid / Bad; a reserved record naming another index is Bad (misdirected). truncate_suffix and the open-time clean-up write reserved records instead of zeros, so "past the end" stays loud.
  • In decide, a slot that is Bad beside a damaged entry inside the last batch ends the log like a reserved slot does (the batch-start flag already locates the last batch, segment.rs:565-572); outside the last batch it stays a DoubleFault.
  • Recovery reports which rule fired: torn_tail for a reserved or torn identifier in the last batch, DoubleFault otherwise.

Format version bump (FORMAT_VERSION, layout.rs); no deployment runs the old one.

Determinism. No new draws.

Acceptance (crates/moonpool-journal/tests/journal.rs, tests/journal_atlas.rs):

  • zero a synced slot (through its JournalAtlas::slot region) beside an intact entry: the slot is rebuilt, the log is not cut; beside a damaged entry before the last batch: DoubleFault, never a truncation. Red today (the second case truncates silently).
  • Damage both the entry and the slot of an entry in the last batch: opens with torn_tail, the batch is gone, everything before it intact. Red today (DoubleFault).
  • The crash loop under shorn_write_probability 0.2 and garbage_fill_probability 1.0 never refuses to open when nothing in the last batch was acknowledged.

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