Skip to main content

MappedBase

Struct MappedBase 

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

A read-only V8 snapshot backed by an mmap or owned bytes.

Small sections (IDS, SYMS, META, RULES_META, VIEWS) are CRC-checked on first access. Large sections (TOPOLOGY, COLUMNS, EDGE_PROPS, HNSW, PROVENANCE, IVF_STATE) skip automatic CRC; their rkyv accessors use rkyv::access_unchecked (O(1) root-pointer lookup, no full-section walk). Full integrity audit is available via mushroomdb verify.

Implementations§

Source§

impl MappedBase

Source

pub fn map(path: &Path) -> Result<Self>

Open and mmap a V8 snapshot file at path.

Validates the 4KB header (magic, version, section directory, whole-header CRC32). Per-section CRC validation is deferred until first access.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Result<Self>

Construct a MappedBase from an owned byte buffer (no file required).

Used when the Fs implementation returns bytes directly (e.g. the in-memory MemFs used in unit tests or the generic open_with(fs) path that only exposes Fs::read).

Source

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

Check that every section listed in the directory fits within the backing buffer, and that the four large rkyv sections carry enough bytes for their rkyv root struct. Pure pointer arithmetic — no bytes are read, no CRCs are computed, and no page faults are triggered.

Used by restore_v8_base to detect truncated or corrupt snapshots eagerly at open time before the expensive section content reads are deferred.

The minimum-size check closes the gap between validate_section_bounds (which only verifies (offset, len) fit in the file) and the individual accessor checks in topology() / columns() / edge_props_section() / hnsw_section(). Without this check a crafted snapshot with len = 1 for the TOPOLOGY section would pass bounds validation and then panic inside topology().expect(...) on the first query. After this check all “bounds validated at open” expects become true post-validation invariants.

Source

pub fn verify_integrity( &self, ) -> Vec<(u8, &'static str, usize, Result<(), String>)>

Validate the CRC32 of every section and check rkyv-accessible sections for structural integrity.

This is the on-demand integrity check exposed by mushroomdb verify. Large sections skip automatic CRC during normal operation; this method runs it explicitly.

Returns one entry per directory section: (section_id, section_name, bytes_checked, Ok(()) | Err(msg)).

Source

pub fn topology(&self) -> Result<&ArchivedCsr>

Zero-copy access to the archived topology (CSR).

Uses rkyv::access_unchecked to avoid the O(section-size) pointer validation walk that rkyv::access performs. Section bounds are verified at open by validate_section_bounds; all CSR field accesses in seam.rs go through Rust bounds-checked slice indexing. File corruption is caught by mushroomdb verify (explicit full CRC32).

Source

pub fn mixed_cache(&self) -> &MixedCache

The memo for this base’s Mixed columns.

Pair it with columns via ColumnsView::with_base_cached; the two always describe the same immutable mapping, so a memo can never outlive or mismatch its blobs.

Source

pub fn columns(&self) -> Result<&ArchivedColumns>

Zero-copy access to the archived column store.

Uses rkyv::access_unchecked; see topology() for the full safety rationale. Per-field accesses in ColumnsView go through bounds-checked slice indexing and explicit length guards.

Source

pub fn string_table(&self) -> Option<Result<&ArchivedStringTable>>

Zero-copy access to the shared string table (section 12).

None when the snapshot predates the shared section (pre-V9): every ColumnData::Str carries its own copy and that copy is authoritative. Some(Err(..)) only when the section is present but unreadable, which must not be silently treated as “absent” — that would hand the caller the empty per-column tables a V9 snapshot writes and lose every string.

Uses rkyv::access_unchecked; see topology() for the full safety rationale. Reads in ColumnsView/archived_to_columnstore are bounds-checked against the returned slice.

Source

pub fn ids(&self) -> Result<&ArchivedIdMap>

Zero-copy access to the archived id map.

Source

pub fn syms(&self) -> Result<&ArchivedInterner>

Zero-copy access to the archived symbol interner.

Source

pub fn meta_bytes(&self) -> Result<&[u8]>

Raw bytes for the bincode meta section.

Source

pub fn edge_props_section(&self) -> Result<&ArchivedEdgeProps>

Zero-copy access to the archived edge properties (section 5).

Uses rkyv::access_unchecked; see topology() for the full safety rationale. Per-edge property reads in EdgePropsView go through bounds-checked slice indexing.

Source

pub fn hnsw_section(&self) -> Result<&ArchivedHnsw>

Zero-copy access to the archived HNSW section (section 6).

Uses rkyv::access_unchecked; see topology() for the full safety rationale. Called once at first-use to load HNSW state into the engine.

Source

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

Structurally validate the sections that the hot path reads via access_unchecked (topology, columns, edge_props, hnsw, and — from V9 on — the shared string table), using rkyv’s checked access (bytecheck). This walks every relative pointer and rejects out-of-bounds / malformed archives — the defense the hot path deliberately skips for speed.

Unlike CRC32 (which an attacker who controls the bytes can recompute), this catches a maliciously crafted snapshot whose pointers would otherwise trigger UB in access_unchecked. It is O(section size) and touches every page, so it is intended for a pre-flight check (mushroomdb verify), not the per-query read path. Returns the first section that fails to validate.

Source

pub fn rules_meta_section(&self) -> Result<&ArchivedRulesMeta>

Zero-copy access to the archived rules meta (section 8).

Source

pub fn views_section(&self) -> Result<&ArchivedViews>

Zero-copy access to the archived views (section 9).

Source

pub fn ivf_bytes(&self) -> Result<&[u8]>

Raw bytes for the IVF-state section (section 10).

The caller retains these bytes without decoding until first use. Returns Ok(&[]) when the section is absent from the directory (pre-T5 stores migrated from V5–V7 have no IVF section; treat as empty). Any other error (truncation, CRC mismatch) is propagated so that torn writes are detected rather than silently returning an empty map.

Source

pub fn last_change_bytes(&self) -> Result<&[u8]>

Raw bytes for the last-change section (section 11).

Returns Ok(&[]) when the section is absent from the directory (pre-Task-3 snapshots have no LAST_CHANGE section; treat as empty map). Any other error (truncation, CRC mismatch) is propagated.

Source

pub fn edge_props_raw_bytes(&self) -> Result<&[u8]>

Raw bytes for the edge-props section (section 5). Used for byte-identical passthrough when the overlay has no changes.

Source

pub fn provenance_raw_bytes(&self) -> Result<&[u8]>

Raw bytes for the provenance section (section 7). Retained without decoding until first provenance access.

Auto Trait Implementations§

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.