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:
| Row | Key | Value |
|---|---|---|
| version | VERSION_KEY | 12 bytes: major, minor, patch as little-endian u32 (1.0.0) |
| HCA counter | COUNTERS_BASE ‖ packed i64 window start | 8-byte little-endian allocation count |
| HCA recent | RECENT_BASE ‖ packed i64 candidate | empty |
| child | child_key: node ‖ i64(0) ‖ STRING(segment) | the child’s allocated prefix (raw bytes) |
| layer | layer_key: node ‖ BYTES(“layer”) | layer bytes (always empty in this layout) |
| data | allocated prefix ‖ key | the value |
Key regions by first byte:
| First byte | Content |
|---|---|
0x00–0xFD | Data keys: an allocated prefix ‖ key |
0xFE | Directory 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 |
0xFF | Reserved (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_PREFIXis 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 prefix0xFE). - 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
nodefor segmentname(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)), wherestrincis the FoundationDB successor (increment the last non-0xFFbyte, drop trailing0xFFs) — exactly the crate’snext_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).Nonewhen the value is shorter than 12 bytes (trailing bytes beyond 12 are tolerated, matching the layer’slen < 12check). - recent_
key - The HCA recent key for a candidate:
RECENT_BASE ‖ INT(candidate).