Skip to main content

collapse_below

Function collapse_below 

Source
pub fn collapse_below(
    log: &dyn OpLog,
    acks: &AckVector,
    sink: &dyn SnapshotSink,
    snapshot_for_array: impl Fn(&str, Hlc) -> ArrayResult<Option<TileSnapshot>>,
) -> ArrayResult<GcReport>
Expand description

Compact ops below the min-ack frontier into snapshots, then prune the log.

Algorithm:

  1. Determine frontier = acks.min_ack_hlc(). If None, return early with an empty report — GC must not proceed without knowing every peer’s progress.
  2. Collect distinct array names whose ops have hlc < frontier.
  3. For each such array, call snapshot_for_array(name, frontier).
    • Some(snap) → write via sink.write_snapshot(&snap) and increment snapshots_written.
    • None → the caller signals “no live state for this array”; skip the snapshot write (ops will still be dropped).
    • Err → propagate immediately; the log is not mutated.
  4. After all snapshots succeed, call log.drop_below(frontier) and record the count in ops_dropped.
  5. Return the report.