Skip to content

Commit 304d7e1

Browse files
authored
docs(master): improve documentation for KV key prefixes (#744)
Enhance clarity on key-value structure and serialization details for prefixes related to metadata sections. Signed-off-by: guillex <guillex@leil.io>
1 parent 6e36ece commit 304d7e1

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/master/kv_common_keys.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,43 @@ inline constexpr std::string_view kMetaDirNodesKey = "META_DIR_NODES";
4242
inline constexpr std::string_view kMetaLinkNodesKey = "META_LINK_NODES";
4343

4444
// Metadata sections prefixes
45+
46+
/// Prefix for FSNode entries
47+
/// Format: NODE_<InodeId>:<SerializedFSNodeData>
48+
/// @note InodeId is serialized as Big Endian to maintain numeric order in lexicographical sorting
49+
/// enabling efficient range queries for all nodes or specific inode ranges.
4550
inline constexpr std::string_view kNodeKeyPrefix = "NODE_"; // Section NODE 1.0
51+
52+
/// Prefix for edges (directory entries)
53+
/// Format: EDGE_<ParentId><Name>:<ChildId>
54+
/// e.g.: EDGE_1999ChildName: 2535
55+
/// @note ParentId is serialized as Big Endian to maintain numeric order in lexicographical sorting,
56+
/// enabling efficient range queries for all edges of a specific parent.
57+
/// @note ChildId is also serialized as Big Endian.
58+
/// @note The in-memory implementation only needs to persist the EDGE section in metadata.sfs,
59+
/// but the KV implementations need additional reverse indexes for efficient lookups and traversals,
60+
/// which are stored as separate keys with their own prefixes (e.g., DIR_PARENT_, PARENT_).
61+
/// @see kEdgeLowerKeyPrefix, kDirParentKeyPrefix, kParentKeyPrefix, kDirNodesCountPrefix,
62+
/// kDirStatsPrefix
4663
inline constexpr std::string_view kEdgeKeyPrefix = "EDGE_"; // Section EDGE 1.0
64+
65+
/// Prefix for free/reusable inode ids
66+
/// Format: FREE_<InodeId>:<TimeStamp>
67+
/// @note InodeId is serialized as Big Endian. TimeStamp is a 32-bit Big Endian value indicating
68+
/// when the inode was freed.
4769
inline constexpr std::string_view kFreeKeyPrefix = "FREE_"; // Section FREE 1.0
70+
71+
/// Prefix for chunk entries (mostly used for chunk locking)
72+
/// Format: CHNK_<ChunkId><ChunkVersion>:<LockedTo><LockId>
73+
/// @note ChunkId (64-bit) and ChunkVersion (32-bit) are serialized as Big Endian in the key.
74+
/// LockedTo and LockId (both 32-bit) are also Big Endian.
75+
inline constexpr std::string_view kChunkKeyPrefix = "CHNK_"; // Section CHNK 1.0
76+
77+
// Reserved for future use
4878
inline constexpr std::string_view kXAttrKeyPrefix = "XATR_"; // Section XATR 1.0
4979
inline constexpr std::string_view kACLsKeyPrefix = "ACLS_"; // Section ACLS 1.2
5080
inline constexpr std::string_view kQuotasKeyPrefix = "QUOT_"; // Section QUOT 1.1
5181
inline constexpr std::string_view kLocksKeyPrefix = "FLCK_"; // Section FLCK 1.0
52-
inline constexpr std::string_view kChunkKeyPrefix = "CHNK_"; // Section CHNK 1.0
5382

5483
// Case-insensitive directory support
5584

@@ -71,7 +100,7 @@ inline constexpr std::string_view kParentKeyPrefix = "PARENT_";
71100
/// Prefix for counting directory nodes without querying all entries
72101
/// Format: DIR_NODES_COUNT_<ParentId>:<DirEntriesCount>.
73102
/// DirEntriesCount is stored as little-endian int64_t for atomic updates.
74-
/// Note: Signed integers are used in FDB storage to enable simpler atomic add/subtract
103+
/// @note Signed integers are used in FDB storage to enable simpler atomic add/subtract
75104
/// operations without unsigned arithmetic underflow concerns.
76105
inline constexpr std::string_view kDirNodesCountPrefix = "DIR_NODES_COUNT_";
77106

@@ -81,7 +110,7 @@ inline constexpr std::string_view kDirNodesCountPrefix = "DIR_NODES_COUNT_";
81110
/// Format: DIR_STATS_<DirId><SuffixByte>:<Value>
82111
/// Each directory has 8 keys with different suffix bytes for each stat field.
83112
/// Values are stored as little-endian int64_t for atomic updates.
84-
/// Note: Although StatsRecord uses unsigned types in memory, signed integers are used
113+
/// @note Although StatsRecord uses unsigned types in memory, signed integers are used
85114
/// in FDB storage to enable simpler atomic add/subtract operations without unsigned
86115
/// arithmetic underflow concerns. Values are converted between types during serialization.
87116
/// Stats are recursively aggregated (sum of all descendants) and maintained incrementally

0 commit comments

Comments
 (0)