Skip to main content

FlatEngine

Struct FlatEngine 

Source
pub struct FlatEngine<R: RawKv> { /* private fields */ }
Expand description

The flat directory layout over a raw byte view.

Not itself a KvStore: it has no async boundary and no engine error identity. The flat backends wrap it.

Directory paths are the fasm form (&[&[u8]], UTF-8, validated with validate_dir); each fasm directory maps to the layer path [ROOT_PATH_SEGMENT] ‖ dir, so the fasm root [] is the layer’s anchor directory — a real, allocated node, never the layer root.

Implementations§

Source§

impl<R: RawKv> FlatEngine<R>

Source

pub fn new(raw: R) -> Self

Wrap a raw view.

Source

pub fn raw(&self) -> &R

The underlying view, for backends that need to reach it directly (streaming, raw-handle accessors, the open-time probe).

Source

pub fn raw_mut(&mut self) -> &mut R

The mutable underlying view.

Source

pub fn prefix_of( &self, dir: &[&[u8]], ) -> Result<Option<Vec<u8>>, FlatError<R::Error>>

Resolve dir to its allocated prefix.

Ok(None) when the store is fresh or the directory does not exist. Err(FlatError::Foreign) when the store’s version row is one this layout does not read; Err(FlatError::Corrupt) when a node row’s value is malformed. Write operations use allocate_dir instead.

Source

pub fn allocate_dir( &mut self, dir: &[&[u8]], ) -> Result<Vec<u8>, FlatError<R::Error>>

Resolve dir, allocating every missing directory (and only those) along the way — the anchor included, which is what writes the version row on a fresh store. Returns the resolved prefix.

Creation is recursive on the path: creating [a, b] creates both a and b (lazy parent creation, verbatim from the layer). Each new node takes a candidate from the HCA; the allocation and the node rows land in the same transaction view, so a rolled-back creation leaves no trace. Idempotent: an existing directory resolves to its prefix without a new allocation.

Source

pub fn get( &self, dir: &[&[u8]], key: &[u8], ) -> Result<Option<Vec<u8>>, FlatError<R::Error>>

Get key within dir. A missing directory yields Ok(None).

Source

pub fn scan( &self, dir: &[&[u8]], start: Bound<&[u8]>, end: Bound<&[u8]>, forward: bool, ) -> Result<Vec<KvPair>, FlatError<R::Error>>

Scan within dir between start and end (bounds over the key part), ascending or descending. A missing directory yields no rows. The returned keys are the within-directory keys.

Source

pub fn data_bounds( &self, dir: &[&[u8]], start: Bound<&[u8]>, end: Bound<&[u8]>, ) -> Result<Option<DataBounds>, FlatError<R::Error>>

The raw engine range holding dir’s data for start <= k < end (bounds over the within-directory key part): the resolved prefix plus the raw start/end byte bounds, or Ok(None) when dir does not exist or the bound pair names no keys.

The seam for backends that stream a lazy cursor over the engine’s raw range (one page or one reseek at a time) instead of scan’s materialized merge. The raw range is [start, end) in the engine’s whole keyspace; the keys a cursor yields there carry the prefix, which the caller strips (prefix.len() bytes) to get the within-directory key.

Source

pub fn set( &mut self, dir: &[&[u8]], key: &[u8], value: &[u8], ) -> Result<(), FlatError<R::Error>>

Set key within dir, allocating dir (and any missing ancestor, and the anchor) if needed.

Source

pub fn delete( &mut self, dir: &[&[u8]], key: &[u8], ) -> Result<(), FlatError<R::Error>>

Delete key within dir (a no-op if the directory or the key does not exist).

Source

pub fn clear_range( &mut self, dir: &[&[u8]], start: Bound<&[u8]>, end: Bound<&[u8]>, ) -> Result<(), FlatError<R::Error>>

Clear start <= k < end within dir (a no-op if the directory does not exist).

Source

pub fn list_dirs( &self, dir: &[&[u8]], ) -> Result<Vec<Vec<u8>>, FlatError<R::Error>>

The immediate child segment names under dir, sorted ascending. A missing directory yields an empty list.

Source

pub fn dir_exists(&self, dir: &[&[u8]]) -> Result<bool, FlatError<R::Error>>

Whether dir exists. The fasm root [] exists iff its anchor node has been created (the store has been written); any other directory exists iff its node row is present — a directory with zero data keys still exists.

Source

pub fn remove_dir(&mut self, dir: &[&[u8]]) -> Result<bool, FlatError<R::Error>>

Remove dir recursively: its subdirectories (node rows and data) and its own key data. Ok(true) if it existed, Ok(false) otherwise. The root is not removable.

Auto Trait Implementations§

§

impl<R> Forget for FlatEngine<R>

§

impl<R> Freeze for FlatEngine<R>
where R: Freeze,

§

impl<R> Move for FlatEngine<R>

§

impl<R> RefUnwindSafe for FlatEngine<R>
where R: RefUnwindSafe,

§

impl<R> Send for FlatEngine<R>
where R: Send,

§

impl<R> Sync for FlatEngine<R>
where R: Sync,

§

impl<R> Unpin for FlatEngine<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for FlatEngine<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for FlatEngine<R>
where R: 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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

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.