Skip to main content

next_chain_stamp

Function next_chain_stamp 

Source
pub fn next_chain_stamp(
    segments: &[RemoteLogSegmentMetadata],
    new_epoch_id: EpochId,
) -> Option<ChainStamp>
Expand description

Next chain position for a partition, given every segment the metadata manager knows about.

Picks the receipt on the segment with the greatest start_offset, breaking a tie by the greatest seq, and continues from it. A segment in a delete state is ignored, and so is a record in the request form, which carries no head.

Returns a fresh epoch at genesis when no receipt survives. That is a new partition, or a restart on the non-durable in-memory metadata manager, and in both cases the old chain cannot be continued. A new epoch says so, rather than restarting the old chain at sequence zero and looking like a rewrite. Returns None when the selected receipt is at u64::MAX, because no later sequence exists and restarting at genesis would hide exhaustion as a new chain run. Returns None too when a live segment carries a chain record of a version other than WORM_CHAIN_RECORD_VERSION, because this build cannot tell where that chain ends.

new_epoch_id is a parameter and not a Uuid::new_v4() call inside, so the function stays pure and testable.