Skip to main content

ChunkReader

Struct ChunkReader 

Source
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

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn bytes(&self) -> u64

Total size of all segments in bytes.

Source

pub fn segment_count(&self) -> usize

Number of segment files backing this block.

Source

pub fn segment_len(&self, index: usize) -> Option<usize>

Byte length of one segment.

Source

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for ChunkReader

Available on Unix and crate feature mmap only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Forget for ChunkReader

§

impl Freeze for ChunkReader
where *const u8 is !null: Freeze, PhantomData<Segment>: Freeze,

§

impl Move for ChunkReader

§

impl RefUnwindSafe for ChunkReader

§

impl Send for ChunkReader
where RawVecInner: Send, MmapInner: Send,

§

impl Sync for ChunkReader
where RawVecInner: Sync, MmapInner: Sync,

§

impl Unpin for ChunkReader
where *const u8 is !null: Unpin, *mut c_void: Unpin,

§

impl UnsafeUnpin for ChunkReader
where *const u8 is !null: UnsafeUnpin, PhantomData<Segment>: UnsafeUnpin,

§

impl UnwindSafe for ChunkReader
where RawVecInner: UnwindSafe, *mut c_void: 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.