Skip to main content

IndexReader

Struct IndexReader 

Source
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 but not Sync because both caches are RefCells; see the crate level threading notes.

Implementations§

Source§

impl IndexReader

Source

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.

Source

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.

Source

pub fn postings(&self, name: &str, value: &str) -> Result<Postings<'_>>

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.

Source

pub fn postings_multi( &self, name: &str, values: &[&str], ) -> Result<Postings<'_>>

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.

Source

pub fn all_postings(&self) -> Result<Postings<'_>>

Postings list of every series in the block.

This is the empty-key entry, which is also what Prometheus uses for “match everything”.

Source

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.

Source

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

Source

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

Source

pub fn open(path: &Path, verify_crc: bool) -> Result<Self>

Opens and validates an index file.

Source

pub fn from_mmap(mmap: Mmap, verify_crc: bool) -> Result<Self>

Wraps an already-mapped index file.

Source

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.

Source

pub fn version(&self) -> u8

Index format version (1, 2 or 3).

Source

pub fn toc(&self) -> Toc

Raw table of contents of the file.

Source

pub fn series_start(&self) -> u64

Byte offset where the series section starts, after alignment.

Source

pub fn series_end(&self) -> u64

Byte offset where the series section ends.

Source

pub fn bytes(&self) -> &[u8] ⓘ

The whole index file as bytes.

Source

pub fn symbol_count(&self) -> usize

Number of symbols declared by the symbol table.

Source

pub fn verify_crc(&self) -> bool

True when series records carry a CRC that is being verified.

Source

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”).

Source

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.

Trait Implementations§

Source§

impl Debug for IndexReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for IndexReader

§

impl !RefUnwindSafe for IndexReader

§

impl !Sync for IndexReader

§

impl Forget for IndexReader

§

impl Move for IndexReader

§

impl Send for IndexReader
where MmapInner: Send, RawVecInner: Send, RefCell<Vec<Option<(u32, Arc<str>)>>>: Send, RefCell<Option<Arc<PostingsTable>>>: Send,

§

impl Unpin for IndexReader
where *mut c_void: Unpin, *const u8 is !null: Unpin, Arc<str>: Unpin, Arc<PostingsTable>: Unpin,

§

impl UnsafeUnpin for IndexReader

§

impl UnwindSafe for IndexReader
where *mut c_void: UnwindSafe, RawVecInner: UnwindSafe, Arc<str>: UnwindSafe, Arc<PostingsTable>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.