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>
impl<R: RawKv> FlatEngine<R>
Sourcepub fn raw(&self) -> &R
pub fn raw(&self) -> &R
The underlying view, for backends that need to reach it directly (streaming, raw-handle accessors, the open-time probe).
Sourcepub fn prefix_of(
&self,
dir: &[&[u8]],
) -> Result<Option<Vec<u8>>, FlatError<R::Error>>
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.
Sourcepub fn allocate_dir(
&mut self,
dir: &[&[u8]],
) -> Result<Vec<u8>, FlatError<R::Error>>
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.
Sourcepub fn get(
&self,
dir: &[&[u8]],
key: &[u8],
) -> Result<Option<Vec<u8>>, FlatError<R::Error>>
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).
Sourcepub fn scan(
&self,
dir: &[&[u8]],
start: Bound<&[u8]>,
end: Bound<&[u8]>,
forward: bool,
) -> Result<Vec<KvPair>, FlatError<R::Error>>
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.
Sourcepub fn data_bounds(
&self,
dir: &[&[u8]],
start: Bound<&[u8]>,
end: Bound<&[u8]>,
) -> Result<Option<DataBounds>, FlatError<R::Error>>
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.
Sourcepub fn set(
&mut self,
dir: &[&[u8]],
key: &[u8],
value: &[u8],
) -> Result<(), FlatError<R::Error>>
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.
Sourcepub fn delete(
&mut self,
dir: &[&[u8]],
key: &[u8],
) -> Result<(), FlatError<R::Error>>
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).
Sourcepub fn clear_range(
&mut self,
dir: &[&[u8]],
start: Bound<&[u8]>,
end: Bound<&[u8]>,
) -> Result<(), FlatError<R::Error>>
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).
Sourcepub fn list_dirs(
&self,
dir: &[&[u8]],
) -> Result<Vec<Vec<u8>>, FlatError<R::Error>>
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.