pub struct IndexReader { /* private fields */ }Expand description
Reader for the index of one block.
The symbol table and the series section are parsed eagerly; the postings offset table is parsed on first lookup and kept in its sampled form. No full label index is ever built.
IndexReader is Send + Sync. Mutable state lives elsewhere: each
SeriesIter owns its symbol cache and cursor, and the postings table is
initialised once through a OnceLock. Several threads can therefore query
the same reader concurrently, each with its own iterators.
Implementations§
Source§impl IndexReader
impl IndexReader
Sourcepub fn postings_for_all_label_values<'a>(
&'a self,
name: &str,
) -> Result<BoxPostings<'a>>
pub fn postings_for_all_label_values<'a>( &'a self, name: &str, ) -> Result<BoxPostings<'a>>
Postings of every series that has name set to a non-empty value.
This is what name=~".+" selects.
Sourcepub fn postings_for_matchers<'a>(
&'a self,
matchers: &[LabelMatcher],
) -> Result<BoxPostings<'a>>
pub fn postings_for_matchers<'a>( &'a self, matchers: &[LabelMatcher], ) -> Result<BoxPostings<'a>>
Turns a matcher list into one lazy postings source.
The plan follows Prometheus’ PostingsForMatchers:
- a single
{""=""}matcher selects all series; - matchers that cannot match
""prove the label is present, which lets negative matchers subtract instead of scan every value; - when only excluding matchers remain, the base is all series;
- matchers that must hold are intersected, excluding ones subtracted.
=~".*" is a no-op, !~".*" selects nothing, and =~".+" selects all
series that have the label — the same special cases Prometheus applies.
Source§impl IndexReader
impl IndexReader
Sourcepub fn label_names(&self) -> Result<Vec<String>>
pub fn label_names(&self) -> Result<Vec<String>>
Label names in the block, sorted, excluding the all-series key.
Costs one pass over the sampled offset table, cached after the first call.
Sourcepub fn label_values(&self, name: &str) -> Result<Vec<String>>
pub fn label_values(&self, name: &str) -> Result<Vec<String>>
Every value of name, in the index’s (sorted) order.
Returns an empty vector when the label name is absent.
Sourcepub fn postings(&self, name: &str, value: &str) -> Result<PostingsList<'_>>
pub fn postings(&self, name: &str, value: &str) -> Result<PostingsList<'_>>
Postings list for name=value, in ascending series-reference order.
An unknown pair yields an empty list, matching Prometheus. The list is decoded lazily: only the frame is read up front.
Sourcepub fn postings_multi(
&self,
name: &str,
values: &[&str],
) -> Result<MergedPostings<'_>>
pub fn postings_multi( &self, name: &str, values: &[&str], ) -> Result<MergedPostings<'_>>
Union of the postings lists for several values of one label name.
Values do not need to be sorted; duplicates and unknown values are
ignored. This is the shape a label=~"a|b" matcher needs.
Sourcepub fn all_postings(&self) -> Result<PostingsList<'_>>
pub fn all_postings(&self) -> Result<PostingsList<'_>>
Postings list of every series in the block.
This is the empty-key entry, which is also what Prometheus uses for “match everything”.
Sourcepub fn series_by_ref(&self, reference: u64) -> Result<SeriesRef>
pub fn series_by_ref(&self, reference: u64) -> Result<SeriesRef>
Resolves a series reference from Postings into its record.
v2/v3 references are offset / 16, so the byte offset has to be
reconstructed; v1 references are already byte offsets.
Sourcepub fn postings_for_values<'a>(
&'a self,
name: &str,
predicate: impl Fn(&str) -> bool,
) -> Result<BoxPostings<'a>>
pub fn postings_for_values<'a>( &'a self, name: &str, predicate: impl Fn(&str) -> bool, ) -> Result<BoxPostings<'a>>
Union of the postings of every value of name accepted by predicate.
The label values are streamed from the offset table (borrowed, no per-value allocation); only the offsets of the selected lists are kept. This is the primitive a regex matcher needs, since it has to inspect every value of one label.
Sourcepub fn for_each_label_value(
&self,
name: &str,
f: impl FnMut(&str),
) -> Result<usize>
pub fn for_each_label_value( &self, name: &str, f: impl FnMut(&str), ) -> Result<usize>
Calls f for every value of name, in index order, without collecting
them.
Returns the number of values visited. Useful for a query layer that wants to inspect a label’s cardinality without allocating the value strings.
Sourcepub fn validate_postings(&self) -> Result<PostingsStats>
pub fn validate_postings(&self) -> Result<PostingsStats>
Validates the offset table and every postings list.
Walks all entries (not just the sampled ones), decodes each list once and checks that references are strictly increasing and addressable in this index version. Cost is proportional to the total number of references, so this is the expensive half of block validation.
Source§impl IndexReader
impl IndexReader
Sourcepub fn validate_layout(&self) -> Result<IndexLayout>
pub fn validate_layout(&self) -> Result<IndexLayout>
Checks TOC ordering, section bounds and series alignment.
This is a pure metadata check: no series record is parsed and the symbol table is not walked again, so it is safe to call on every open.
Source§impl IndexReader
impl IndexReader
Sourcepub fn from_mmap(mmap: Mmap, verify_crc: bool) -> Result<Self>
pub fn from_mmap(mmap: Mmap, verify_crc: bool) -> Result<Self>
Wraps an already-mapped index file.
Sourcepub fn from_bytes(bytes: Vec<u8>, verify_crc: bool) -> Result<Self>
pub fn from_bytes(bytes: Vec<u8>, verify_crc: bool) -> Result<Self>
Wraps an index file that is already in memory.
Useful when the bytes come from an object store, a network stream or a test fixture instead of the local filesystem.
Sourcepub fn series_start(&self) -> u64
pub fn series_start(&self) -> u64
Byte offset where the series section starts, after alignment.
Sourcepub fn series_end(&self) -> u64
pub fn series_end(&self) -> u64
Byte offset where the series section ends.
Sourcepub fn symbol_count(&self) -> usize
pub fn symbol_count(&self) -> usize
Number of symbols declared by the symbol table.
Sourcepub fn verify_crc(&self) -> bool
pub fn verify_crc(&self) -> bool
True when series records carry a CRC that is being verified.
Sourcepub fn series(&self, start_offset: u64) -> SeriesIter<'_> ⓘ
pub fn series(&self, start_offset: u64) -> SeriesIter<'_> ⓘ
Iterates series beginning at the given byte offset (0 means “from the start of the series section”).
Sourcepub fn scan_stats(&self) -> Result<IndexStats>
pub fn scan_stats(&self) -> Result<IndexStats>
Scans the series section without resolving symbols, collecting exact series and chunk counts.
Use this when meta.json carries no stats. It walks every record but
never touches the symbol table, so it stays cheap on wide label sets.
Records are still bounds-checked: a corrupt section is reported instead
of being counted.