Skip to main content

Module flatdir

Module flatdir 

Source
Expand description

The flat directory layout: a verbatim port of FoundationDB’s DirectoryLayer (foundationdb crate, pinned 0.11.0).

The layout and every algorithm here replicate what DirectoryLayer::default() does in a real FoundationDB keyspace — the node tree, the High Contention Allocator, the version row, the tuple byte encoding, the default layer placement — so that a store written by this layout and one written by the native layer agree on every row. The flat backends (btreemap, redb) execute it over a crate::rawkv::RawKv view; the FDB backend uses the native layer over the identical layouts.

§Row layouts

RowKeyValue
versionlayout::VERSION_KEY12 bytes: major, minor, patch, little-endian u32 (1.0.0)
HCA counterlayout::COUNTERS_BASE ‖ packed i64 window start8-byte LE allocation count
HCA recentlayout::RECENT_BASE ‖ packed i64 candidateempty
childlayout::child_key = node ‖ i64(0) ‖ STRING(segment)the child’s allocated prefix (raw bytes)
layerlayout::layer_key = node ‖ BYTES(“layer”)layer bytes (always empty here)
dataallocated prefix ‖ keythe value

Key regions: 0x00–0xFD data, 0xFE directory nodes (layout::NODE_PREFIX, root node layout::ROOT_NODE), 0xFF reserved. Allocated prefixes are packed i64s (prefix-free, first byte 0x0c..=0x1c), so data keys need no separator and cannot collide with meta or reserved rows.

§Single-writer adaptations

The flat backends have exactly one writer, so the layer’s transactional machinery degrades in documented ways (per module: hca, ops): no write-conflict ranges, the counter increment is a read-modify-write landing at the atomic op’s byte values, the RNG is caller-supplied (thread_rng in production), and a candidate claimed by a leftover recent row is retried rather than version-vector resolved. The row bytes and the operation order are unchanged.

§Fresh stores and versions

A store with no version row is fresh: reads answer empty, and the first create writes the version row lazily (the layer’s check_version behaviour). A store whose version row this layout does not read (newer major or minor) fails closed with error::FlatError::Foreign.

Re-exports§

pub use error::FlatError;
pub use layout::LAYOUT_VERSION;
pub use layout::ROOT_PATH_SEGMENT;
pub use layout::VERSION_KEY;
pub use layout::parse_version;

Modules§

error
The error type shared by the layout machinery and the flat backends.
hca
The High Contention Allocator, ported from the foundationdb crate’s tuple_ext::hca::HighContentionAllocator (pinned foundationdb-0.11.0).
layout
The exact row layouts of the flat directory layout.
ops
The directory operations over a RawKv view: the version check, node lookup, lazy creation, child listing, and recursive removal.
tuple
The tuple byte encoding the flat directory layout uses for its row keys.