Skip to content

moonpool-journal: truncate_prefix unlinks before the new start is durable; a segment gap deletes the live log or panics on open #301

Closed

Description

@PierreZ

Downstream: PierreZ/paros#176, PierreZ/paros#202 (paros checkpoints with truncate_prefix, crates/paros/src/journal/node.rs:258-279). Distinct from #293, which is about ancestors on open. References: moonpool 9ed1360, paros f2b2502.

Downstream evidence. Journal::truncate_prefix deletes the dropped segments oldest first and then runs one sync_dir (crates/moonpool-journal/src/journal.rs:603-631). Nothing durable says the log's start moved before the unlinks. With unsynced_dir_entry_loss_probability (in the default random profile, storage/config.rs:442-500) each name resolves on its own at a crash (storage/sim/engine.rs:798-835), so a crash in that window can bring back seg-1 while seg-2 stays deleted: [seg-1, seg-3, …], a gap.

On the next open Segment::walk computes its index limit from the next segment's name (segment.rs:430, limit = next_first - first):

  • if seg-1 rolled over because its data region filled, the walk meets the first empty slot past its real end, sets ended, and open deletes every later segment, newest first (journal.rs:240-249): the whole live log, acknowledged entries included, is gone;
  • if seg-1 rolled over because its slot table filled, limit exceeds slot_count, and failed[at / BLOCK] / table[at..] index past the table (segment.rs:441-444): a panic.

Neither crash loop calls truncate_prefix and neither enables directory-entry loss (tests/journal.rs:1217-1278), so this is untested. For paros it is a lost acceptor after a checkpoint plus a power loss, in production too.

Smallest change.

  1. Record the new start durably before any unlink: a start_index field in the two-copy metadata (DualFile, beside the caller's payload, or its own start.0/1 pair), written and synced first. start_index() reads it; open deletes any segment wholly below it (a resurrected one) and treats a segment missing between the start and the tail as JournalError::BadSegmentHeader-class damage, never as the end of the log. walk's limit comes from the slot table, with the next segment's name only a cross-check.
  2. This also gives a caller an index-granular floor the journal remembers: today a reopen reports the oldest segment's first index, so paros keeps its own floor in every Truncate record.

Determinism. No new draws.

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

  • fill three small segments, truncate_prefix past the second, crash with unsynced_dir_entry_loss_probability = 1.0 arranged so the first deletion is undone and the second kept, reopen: every live entry is readable, nothing past the start is deleted, no panic. Red today in both shapes (the data-full and the table-full rollover).
  • the crash loop's write plan gains truncate_prefix, under the Paper model with directory-entry loss on, with the existing "nothing acknowledged is lost" oracle.

Activity

  1. added 6 commits that reference this issue on Oct 5, 2026
    5f897dc
    36c66e2
    acdfe00
    4759962
    949e2c5
    8875191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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