Expand description
Segments: immutable binary snapshots of a layer.
A segment is one object, <namespace>/segments/<lo>-<hi>/data.bin, holding
the net effect of WAL entries lo through hi. The id carries the range,
so the manifest can be checked for contiguity from the ids alone, and the
bytes are a pure function of the range: any compactor building the same
range produces the same object, which is what lets a rerun or a racing
compactor reuse an existing one.
Three formats exist, and decode reads all of them. Version 1 is a flat
run of sections. Version 2 (in the private v2 module) holds the
same content in blocks with a directory and a Bloom filter at the end, so a
reader can fetch pieces of it. Version 3 (the same module with
columns and zone) stores a typed namespace’s attributes as columns per
block with a zone map beside them. encode_with_schema writes any of
them as compaction does, and the namespace’s segment_format level decides
which one compaction writes.
Ids and tombstones are sorted, strictly ascending, and never overlap.
decode checks every length against the bytes that remain before
allocating and never panics.
Structs§
- Matrix
- A dense
rows x dimmatrix off32, row-major, one allocation for the whole thing.RangedSegment::vectors_ofreturns this instead ofVec<Vec<f32>>(one heap allocation per row) so a rerank walks contiguous memory and the distance kernels see one slice per row of the same buffer. A scan hands one out per batch.
Constants§
- DEFAULT_
FORMAT - The segment level a namespace created by this build starts at, which can
trail
FORMAT_VERSION: a new version is readable first and written by default only once it pays off (version 3 is opt-in until its zone maps are used). - FORMAT_
VERSION - The newest segment version this build reads, and the highest level
Namespace::upgrade_segment_formataccepts.decoderejects a version above it (and 0) withItzmaError::UnsupportedFormat. A change to an encoding must add a version, because correctness relies on two builders producing identical bytes.
Functions§
- decode
- Decode a segment object (version 2 or 3) for a namespace whose vectors
have length
dim.pathis only used to label errors. - encode
- Encode a layer as a segment object of the version a new namespace writes
(
DEFAULT_FORMAT) for vectors of lengthdim. Seeencode_as. - encode_
as - Encode a layer as a segment object of
version(1, 2 or 3) for vectors of lengthdim, with attributes stored as JSON. At version 3 that is the layout of a free-form namespace; a typed namespace’s segments are whatencode_with_schemawrites. - encode_
with_ schema - Encode a layer as the segment object
compactwrites atversionfor a namespace withschema: at version 3 a typed namespace’s attributes become columns and zone maps. Versions 1 and 2 ignore the attribute schema, so this equalsencode_asthere. - parse_
segment_ id - Recover
(lo, hi)from a segment id, orNoneunless the id is exactly whatsegment_idproduces and1 <= lo <= hi. - segment_
id - The id of the segment covering WAL seqs
lothroughhi: both numbers zero-padded to 20 digits, so ids sort in range order. - segment_
path - Object key of a segment:
<namespace>/segments/<id>/data.bin. The directory leaves room for index files beside the data later. - validate_
chain - Check the manifest invariant on its segment list: every id parses, the
first range starts at 1, each next range starts one past the previous end,
and the last range ends at
folded_through. An empty list requiresfolded_through == 0.