pub struct ChunkReader { /* private fields */ }Expand description
A block’s chunks/ directory, one segment per numeric file.
With the mmap feature the segments are mapped lazily by the OS; without
it they are held in memory. Either way ChunkReader::chunk does not
allocate and returns a slice into the segment.
Implementations§
Source§impl ChunkReader
impl ChunkReader
Sourcepub fn validate_segments(&self) -> Result<SegmentReport>
pub fn validate_segments(&self) -> Result<SegmentReport>
Walks every record of every segment, validating the framing.
This reads only headers: no chunk body is decoded and no CRC is computed, so it stays cheap even for multi-gigabyte blocks. A segment must be tiled exactly by its records; Prometheus never pads a segment, so leftover bytes mean corruption or a mismatched file.
Sourcepub fn validate_reference(&self, reference: u64) -> Result<()>
pub fn validate_reference(&self, reference: u64) -> Result<()>
Checks that reference points at a framed record with a known encoding.
Mirrors what ChunkReader::chunk enforces, minus the CRC and without
handing out a slice, so a whole index can be validated cheaply.
Source§impl ChunkReader
impl ChunkReader
Sourcepub fn open(dir: &Path, verify_crc: bool, advise: bool) -> Result<Self>
pub fn open(dir: &Path, verify_crc: bool, advise: bool) -> Result<Self>
Opens a block’s chunks/ directory.
Segment files are ordered by their numeric name and must form a
contiguous run starting at 000000 or 000001; a gap would silently
shift every reference, so it is rejected. verify_crc is only honoured
when the crate is built with the crc feature; advise asks the kernel
to read sequentially on unix targets.
Sourcepub fn from_segments(segments: Vec<Vec<u8>>, verify_crc: bool) -> Result<Self>
pub fn from_segments(segments: Vec<Vec<u8>>, verify_crc: bool) -> Result<Self>
Builds a reader from segments that are already in memory.
segments must be ordered by sequence number, exactly like the numeric
files inside a block’s chunks/ directory. Chunk references index into
this slice, so the order is part of the format.
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Number of segment files backing this block.
Sourcepub fn segment_len(&self, index: usize) -> Option<usize>
pub fn segment_len(&self, index: usize) -> Option<usize>
Byte length of one segment.
Sourcepub fn chunk(&self, reference: u64) -> Result<ChunkSlice<'_>>
pub fn chunk(&self, reference: u64) -> Result<ChunkSlice<'_>>
Returns a zero-copy view of the chunk referenced by reference.
Trait Implementations§
Source§impl Debug for ChunkReader
impl Debug for ChunkReader
Source§impl Drop for ChunkReader
Available on Unix and crate feature mmap only.
impl Drop for ChunkReader
mmap only.