Skip to main content

BlockReader

Struct BlockReader 

Source
pub struct BlockReader { /* private fields */ }
Expand description

A block opened for reading: index, chunk segments and tombstones.

The reader owns the underlying mappings or buffers. On unix with the mmap feature the files stay mapped for the lifetime of the reader, which means they must not be truncated by another process while it is in use.

BlockReader is Send but not Sync: the symbol cache is a RefCell, so index traversal belongs to one thread. Chunk segments are shared freely via BlockReader::chunk_reader or BlockReader::into_parts.

Implementations§

Source§

impl BlockReader

Source

pub fn open(path: &Path, opts: ReaderOptions) -> Result<Self>

Opens a block directory: parses meta.json, then the index, chunk segments and tombstones.

Available with the meta feature. Without it, use BlockReader::open_with_meta or BlockReader::open_info.

Source

pub fn open_with_meta( path: &Path, meta: BlockMeta, opts: ReaderOptions, ) -> Result<Self>

Opens a block whose meta.json the caller already parsed.

This is the entry point for builds without the meta feature and for callers that keep block metadata in their own store.

Source

pub fn open_info(info: BlockInfo, opts: ReaderOptions) -> Result<Self>

Opens a block reusing metadata that was already discovered.

The passed BlockInfo stays authoritative: tenant, remote and warnings cannot be derived from the block directory, so they are never overwritten. Only the byte counts measured while opening are refreshed, and meta is filled from disk when the caller left its ULID empty.

Source

pub fn path(&self) -> &Path

Directory this block was opened from.

Source

pub fn info(&self) -> &BlockInfo

Metadata plus the sizes measured when the block was opened.

Source

pub fn meta(&self) -> &BlockMeta

Parsed meta.json.

Source

pub fn block_id(&self) -> &str

Block ULID, taken from meta.json or the directory name.

Source

pub fn index(&self) -> &IndexReader

The index reader backing this block.

Source

pub fn tombstones(&self) -> &Tombstones

Deletion intervals loaded for this block.

Source

pub fn series(&self, start_offset: u64) -> SeriesIter<'_> ⓘ

Iterates series in lexicographic label order.

start_offset is a byte offset previously reported by crate::SeriesIter::position; pass 0 to start at the beginning.

Source

pub fn chunk(&self, meta: &ChunkMeta) -> Result<ChunkSlice<'_>>

Reads the chunk described by meta, verifying its checksum when the reader was opened with verify_crc.

Source

pub fn chunk_reader(&self) -> &ChunkReader

Shared chunk reader for decode workers (immutable, thread-safe). Shared chunk reader, safe to hand to several decode threads.

Source

pub fn chunk_bytes(&self) -> u64

Total size of the chunk segments in bytes.

Source

pub fn stats_from_meta(&self) -> IndexStats

Series/chunk totals derived from meta.json (cheap, may be zero for blocks written by old versions or custom tooling).

Source

pub fn scan_stats(&self) -> Result<IndexStats>

Exact totals by scanning the index series section (no label resolution).

Source

pub fn into_parts(self) -> (IndexReader, ChunkReader, Tombstones, BlockInfo)

Splits the reader so that the index can be moved into a single reader thread while chunk segments and tombstones are shared with workers.

Source

pub fn validate_tombstones(&self) -> Result<()>

Ensures the tombstone refs look plausible for this block. Prometheus block tombstones use the same series refs as the index.

Source§

impl BlockReader

Source

pub fn samples(&self, range: TimeRange) -> SampleIterator<'_>

Iterates every sample in the given range, filtering tombstones.

Source

pub fn samples_with(&self, opts: SampleIterOptions) -> SampleIterator<'_>

Iterates samples with explicit options.

Source§

impl BlockReader

Source

pub fn validate(&self) -> Result<ValidationReport>

Cross-checks metadata, index, chunk segments and tombstones.

Errors mean the block is corrupt (or written by something incompatible); warnings point at suspicious but readable data. Nothing here decodes samples, so a block that passes can still contain a bad chunk payload — crate::chunkenc::decode reports that when the chunk is read.

Trait Implementations§

Source§

impl Debug for BlockReader

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for BlockReader

§

impl !RefUnwindSafe for BlockReader

§

impl !Sync for BlockReader

§

impl Forget for BlockReader

§

impl Move for BlockReader

§

impl Send for BlockReader
where RawVecInner: Send, MmapInner: Send, RefCell<Vec<Option<(u32, Arc<str>)>>>: Send, RefCell<Option<Arc<PostingsTable>>>: Send, RawTable<(u64, Vec<(i64, i64)>)>: Send,

§

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

§

impl UnsafeUnpin for BlockReader

§

impl UnwindSafe for BlockReader
where RawVecInner: UnwindSafe, *mut c_void: UnwindSafe, Arc<str>: UnwindSafe, Arc<PostingsTable>: UnwindSafe, HashMap<u64, Vec<(i64, i64)>>: 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.