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
impl BlockReader
Sourcepub fn open(path: &Path, opts: ReaderOptions) -> Result<Self>
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.
Sourcepub fn open_with_meta(
path: &Path,
meta: BlockMeta,
opts: ReaderOptions,
) -> Result<Self>
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.
Sourcepub fn open_info(info: BlockInfo, opts: ReaderOptions) -> Result<Self>
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.
Sourcepub fn index(&self) -> &IndexReader
pub fn index(&self) -> &IndexReader
The index reader backing this block.
Sourcepub fn tombstones(&self) -> &Tombstones
pub fn tombstones(&self) -> &Tombstones
Deletion intervals loaded for this block.
Sourcepub fn series(&self, start_offset: u64) -> SeriesIter<'_> ⓘ
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.
Sourcepub fn chunk(&self, meta: &ChunkMeta) -> Result<ChunkSlice<'_>>
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.
Sourcepub fn chunk_reader(&self) -> &ChunkReader
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.
Sourcepub fn chunk_bytes(&self) -> u64
pub fn chunk_bytes(&self) -> u64
Total size of the chunk segments in bytes.
Sourcepub fn stats_from_meta(&self) -> IndexStats
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).
Sourcepub fn scan_stats(&self) -> Result<IndexStats>
pub fn scan_stats(&self) -> Result<IndexStats>
Exact totals by scanning the index series section (no label resolution).
Sourcepub fn into_parts(self) -> (IndexReader, ChunkReader, Tombstones, BlockInfo)
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.
Sourcepub fn validate_tombstones(&self) -> Result<()>
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
impl BlockReader
Sourcepub fn samples(&self, range: TimeRange) -> SampleIterator<'_>
pub fn samples(&self, range: TimeRange) -> SampleIterator<'_>
Iterates every sample in the given range, filtering tombstones.
Sourcepub fn samples_with(&self, opts: SampleIterOptions) -> SampleIterator<'_>
pub fn samples_with(&self, opts: SampleIterOptions) -> SampleIterator<'_>
Iterates samples with explicit options.
Source§impl BlockReader
impl BlockReader
Sourcepub fn validate(&self) -> Result<ValidationReport>
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.