Skip to main content

Module layout

Module layout 

Source
Expand description

The exact row layouts of the flat directory layout.

This module holds the layout constants and the builders that turn a directory node, a segment name, or an allocated prefix into the raw row keys and regions the layout operates on. Every row form replicates what the FoundationDB directory layer (DirectoryLayer::default()) writes into a real FoundationDB keyspace:

RowKeyValue
versionVERSION_KEY12 bytes: major, minor, patch as little-endian u32 (1.0.0)
HCA counterCOUNTERS_BASE ‖ packed i64 window start8-byte little-endian allocation count
HCA recentRECENT_BASE ‖ packed i64 candidateempty
childchild_key: node ‖ i64(0) ‖ STRING(segment)the child’s allocated prefix (raw bytes)
layerlayer_key: node ‖ BYTES(“layer”)layer bytes (always empty in this layout)
dataallocated prefix ‖ keythe value

Key regions by first byte:

First byteContent
0x00–0xFDData keys: an allocated prefix ‖ key
0xFEDirectory nodes: NODE_PREFIX ‖ BYTES(allocated prefix), each holding its child rows and layer row; the version key and the HCA counter/recent rows live under the root node in this region
0xFFReserved (empty forever)

Allocated prefixes are packed i64s: prefix-free (no one is a byte-prefix of another) and always starting 0x0c..=0x1c, so a data key needs no separator byte and no data key can collide with another directory’s data keys, the meta region, or the reserved region.

The 0xFE/0xFF node and reserved regions, and the content range 0x00..0xFE, match DirectoryLayer::default() exactly (its DEFAULT_NODE_PREFIX is 0xFE, its content subspace is the whole keyspace).

Constants§

COUNTERS_BASE
HCA counters subspace: HCA ‖ INT(0).
HCA_SUBSPACE
The HCA subspace: root node ‖ BYTES(“hca”) — DEFAULT_HCA_PREFIX is a byte string in the layer’s own code.
LAYER_TAG
The layer-row tag: a node’s layer row is node ‖ BYTES("layer").
LAYOUT_VERSION
The version this layout writes and reads: 1.0.0 as three little-endian u32s.
NODE_PREFIX
The raw first byte of every directory-node key.
RECENT_BASE
HCA recents subspace: HCA ‖ INT(1).
RESERVED_BYTE
The reserved first byte: no row of this layout starts with it.
ROOT_NODE
The root node: NODE_PREFIX ‖ BYTES([0xFE]) — verbatim from the layer constructor (root_node = node_subspace.subspace(&node_subspace.bytes()) with the default node prefix 0xFE).
ROOT_PATH_SEGMENT
The fasm root directory maps to the layer path starting with this segment; every fasm directory path is [ROOT_PATH_SEGMENT] ‖ dir. The segment is valid UTF-8 and contains a NUL, which no user segment validation would reject but which keeps the anchor unforgeable from a single user path level. The fdb backend shares this constant, so the flat layout and the native layer agree on the anchor mapping.
VERSION_KEY
The version key: root node ‖ BYTES(“version”).

Functions§

child_key
The child-row key under node for segment name (UTF-8): node ‖ INT(0) ‖ STRING(name).
children_key_range
The raw keyspace range of a node’s child rows: [node ‖ INT(0) ‖ 0x00, node ‖ INT(0) ‖ 0xFF] inclusive at both ends.
counter_key
The HCA counter key for a window start: COUNTERS_BASE ‖ INT(start).
data_region
The raw keyspace range of a directory’s data: [prefix, strinc(prefix)), where strinc is the FoundationDB successor (increment the last non-0xFF byte, drop trailing 0xFFs) — exactly the crate’s next_prefix, pinned by test.
layer_key
The layer-row key of a node: node ‖ BYTES("layer").
node_key_range
The raw keyspace range of a node’s own rows (children rows + layer row): [node ‖ 0x00, node ‖ 0xFF] inclusive at both ends, expressed with the flat engine’s half-open end.
node_subspace
The node subspace of an allocated prefix: NODE_PREFIX ‖ BYTES(prefix).
parse_version
Parse a version value: three little-endian u32s (major, minor, patch). None when the value is shorter than 12 bytes (trailing bytes beyond 12 are tolerated, matching the layer’s len < 12 check).
recent_key
The HCA recent key for a candidate: RECENT_BASE ‖ INT(candidate).