Skip to content

moonpool-journal: checkpoint batches, a batch that supersedes the prefix before it #302

Closed

Description

@PierreZ

Downstream: PierreZ/paros#202 (checkpoint write amplification) and PierreZ/paros#176. A proposal: it moves the plan #202 keeps in paros into the journal, so it is the owner's call. References: moonpool 9ed1360, paros f2b2502.

Downstream evidence. A journal of operations folded at boot needs periodic compaction: re-emit the folded state, then drop the history before it. moonpool-journal offers only truncate_prefix at segment granularity, so both paros stores built the rest themselves, and both the same way (crates/paros/src/journal/{node,matchmaker}.rs::maybe_checkpoint, journal/plan.rs, the Begin/End/Sealed/Install record kinds in journal/frame.rs):

  • the image is appended as one bracketed batch Begin … End, then truncate_prefix(begin);
  • at boot a plan decides where the fold starts: an open bracket at the tail is a crash-cut append and is removed with truncate_suffix; the newest bracket whose every entry verified is the start; a damaged bracket is skipped while the history before it is still on disk; only when the prefix is gone and no bracket is intact is the oldest trusted record by record; no prefix and no bracket is a lost store.

Every one of those rules is a rule about batches, and the journal already knows its batches: a batch-start flag on every entry and slot, Recovery::ambiguous_batch for the last one, JournalAtlas::starts_batch. paros re-derives the same boundaries from payload kinds. The trigger is also where #202's write amplification lives: checkpoint_after is a count of entries, so a whole image is re-emitted every few entries once it is large.

Smallest API.

impl<P: StorageProvider> Journal<P> {
    /// Append `records` as one batch flagged as a checkpoint: once durable it
    /// supersedes every entry before it. Returns the indexes they got.
    pub async fn append_checkpoint(&mut self, records: &[Record<'_>]) -> Result<Range<u64>, JournalError>;
}
pub struct Recovery {
    /// The newest intact checkpoint batch, if any: where a replay starts.
    pub checkpoint: Option<Range<u64>>,
    …
}
  • A checkpoint flag beside the batch-start flag in slot and entry, so the far identifier alone says "this entry opens a checkpoint".
  • open: a checkpoint batch cut by a crash is the last batch and is handled as today; the newest checkpoint whose entries all verified is reported; a damaged one is reported in Recovery::corrupt like any damaged batch, and checkpoint names the newest intact one before it, or None.
  • read_range is unchanged; a caller replays checkpoint.start..next_index() and prepends nothing.
  • Prefix drop stays the caller's truncate_prefix(checkpoint.start), so a crash between the two is harmless (the old history is still there). With moonpool-journal: truncate_prefix unlinks before the new start is durable; a segment gap deletes the live log or panics on open #301 the start is durable before the unlinks.
  • The trigger stays the caller's (paros amortizes it to k × the image size); the journal only exposes next_index() - start_index() and the checkpoint's length.

paros then deletes plan.rs, the Begin/End/Sealed/Install kinds and the matchmaker twin, and both stores share one implementation. The sim example's writer can checkpoint too, which puts the fold-from-checkpoint-equals-fold-from-history oracle in moonpool, where every journal user needs it.

Determinism. No new draws.

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

  • append, checkpoint, append, crash loop under the Paper model: a replay from Recovery::checkpoint equals the replay from the start, for every boot;
  • damage the newest checkpoint's entries through the atlas: checkpoint names the previous intact one, or None with the whole history still live;
  • crash mid-checkpoint: it is the last batch, truncated or kept per AmbiguousTail, and checkpoint names the one before it.

Activity

  1. added 3 commits that reference this issue on Oct 5, 2026
    36c66e2
    4759962
    8875191
  2. PierreZ commented on Oct 6, 2026

    @PierreZ
    OwnerAuthor

    Superseded by #306. On 2026-10-06 the owner decided that checkpoints belong to the caller, not the journal: moonpool-journal's API is append, read and truncate. Nothing uses append_checkpoint, so #306 removes it and the checkpoint count from the format.


    Generated by Claude Code

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