Skip to main content

materialize

Function materialize 

Source
pub fn materialize(
    encoder: &dyn SegmentEncoder,
    ctx: &EncodeContext<'_>,
    rows: &[WalRow],
) -> Result<Option<Segment>>
Available on crate feature archive only.
Expand description

Run an encoder over a run of WAL rows and validate the result.

The shared enforcement point for all three callers that build a segment: the writer when it seals, a copy when it carries a live tail across, and a reader materializing a tail. They used to check three different things, and the reader’s was the weakest, so an encoder the seal refused was materialized silently on read: the reader and the next seal disagreed about the tail.

The check is CONTIGUITY, by counting: the rows handed over that fall inside [first_ts, last_ts] must number exactly rows. A hole anywhere inside the claimed span would be rows that end up in no segment and no WAL, because the prune deletes everything up to last_ts. An encoder may still drop a LEADING or TRAILING run — both narrow the span without holing it. first_ts and last_ts must each be the timestamp of an input row, and a segment claiming no rows is refused (return None instead).

A panic inside the encoder is the encoder’s failure and is returned as Error::Encoder, not propagated: on the writer thread a propagating panic left every handle reporting WriterGone. Ok(None) for an empty input without calling the encoder at all.