Expand description
.ctbnodes (CtbNodes, f639) and .ctbnbdl (CtbNodeBundle, f640)
node ledger parsing and binary compilation.
Re-exports§
pub use journal::*;
Modules§
- journal
- Unified durable append-only journal (
ledger-journal.jsonl), single-inode reader/writerflockguards on the repository’s permanent ledger lock, standalone pending-transaction recovery, and full.ctbnbdlbundle(id, tokens)verification.
Structs§
- Ctbnbdl
Framing Dcs - Framing and relationship Document Characters used when encoding, decoding, and partitioning
.ctbnbdlnode definitions. - Ledger
Node - Single node entry in the System-block
.ctbnodesledger.
Constants§
- CHUNKS_
PER_ SUBFOLDER - Number of
.ctbnodesfiles grouped into each prefix subdirectory starting at the 1000th file. - CREATED_
NS_ COMMENT_ PREFIX - Structured comment prefix recording a node’s creation timestamp in signed nanoseconds
since the Unix epoch inside
.ctbnodeslines (# @created_ns:<i128> ...). - CTBNBDL_
MAGIC - Leading 8-byte magic header for
.ctbnbdl(CtbNodeBundle2,f645) files. - CTBNBDL_
MAGIC_ V1 - Legacy 8-byte magic header for v1
.ctbnbdl(CtbNodeBundle1,f644) files. - DCMM_
HEADER - Standard 21-byte
DcMixed2(f643) header (DcMM\0+ UUIDb0327a84-b745-492c-b39d-77c2827e3a6f). - DCMM_
HEADER_ V1 - Legacy 21-byte
DcMixed1(f642) header (DcMM\0+ UUIDd5ab819e-9b8e-4d61-adbc-933e8851e79a). - DC_
SYSTEM_ BLOCK_ MOST_ RECENT_ NODE_ ID Dc 641(Global graph system block most recent node ID at time of document creation).- GRAPH_
BUNDLES_ REL_ PATH - Relative repository path to the tracked unsplit
.ctbnbdlbundle directory. - GRAPH_
BUNDLES_ SPLIT_ HISTORY_ SUBDIR - Subdirectory under
assets/data/graph-bundles/holding gitignored historical (inactive).ctbnbdlbundles. - GRAPH_
BUNDLES_ SPLIT_ LIVE_ SUBDIR - Subdirectory under
assets/data/graph-bundles/holding gitignored live (active).ctbnbdlbundles. - HIGHWATER_
LEDGER_ REL_ PATH - Relative repository path to the reconstructible high-water ledger cache.
- MAX_
BYTES_ PER_ BUNDLE - Maximum size in bytes of a single
.ctbnbdlbinary bundle file (50 MB). - MAX_
NODES_ PER_ BUNDLE - Maximum number of node definitions grouped into a single
.ctbnbdlbinary bundle file. - MAX_
NODES_ PER_ CHUNK - Maximum number of node declarations stored in a single
.ctbnodeschunk file. - ROOT_
CHUNKS_ BEFORE_ SUBFOLDER - Maximum number of
.ctbnodesfiles stored directly in the top-level graph directory before sharding into 1000-file prefix subdirectories.
Functions§
- bundles_
dir_ for_ graph_ dir - Resolves the
.ctbnbdlbundle directory associated withgraph_dir: - chunk_
rel_ path_ from_ graph_ dir - Returns
pathformatted relative tograph_dirusing forward-slash separators. - compile_
ctbnodes_ dir_ to_ ctbnbdl - Compiles all
.ctbnodeschunk files insrc_dirinto grouped active.ctbnbdlbundle files indst_dir(up toMAX_NODES_PER_BUNDLE= 1,000,000 nodes orMAX_BYTES_PER_BUNDLE= 50 MB per bundle), removing any stale.ctbnodesor obsolete.ctbnbdlfiles indst_dir. - compile_
ctbnodes_ dir_ to_ ctbnbdl_ with_ limits - Compiles all
.ctbnodeschunk files insrc_dirinto grouped active.ctbnbdlbundle files indst_dirusing custom node-count and byte-size limits, removing any stale.ctbnodesor obsolete.ctbnbdlfiles indst_dir. - compile_
ctbnodes_ file_ to_ ctbnbdl_ bytes - Parses a
.ctbnodesfile on disk and compiles its node definitions into.ctbnbdlbytes. - compile_
graph_ bundles_ from_ ctbnodes_ dir - Same as
compile_graph_bundles_from_ctbnodes_dir_with_limitsusing defaultMAX_NODES_PER_BUNDLEandMAX_BYTES_PER_BUNDLElimits. - compile_
graph_ bundles_ from_ ctbnodes_ dir_ with_ limits - Compiles all
.ctbnodeschunk files insrc_dirinto: - compile_
inactive_ ctbnodes_ dir_ to_ ctbnbdl - Compiles all filtered-out inactive (superseded/retracted) nodes from
.ctbnodeschunk files insrc_dirinto grouped.ctbnbdlbundle files inhistory_dst_dir(up toMAX_NODES_PER_BUNDLE= 1,000,000 nodes orMAX_BYTES_PER_BUNDLE= 50 MB per bundle). - compile_
inactive_ ctbnodes_ dir_ to_ ctbnbdl_ with_ limits - Compiles all filtered-out inactive (superseded/retracted) nodes from
.ctbnodeschunk files insrc_dirinto grouped.ctbnbdlbundle files inhistory_dst_dirusing custom node-count and byte-size limits. - consume_
atom_ dc_ with - Consumes an
[atom_dc]token at*idxfromtokens, unescaping255 203,255 255, and255 616. - current_
unix_ timestamp_ ns - Returns the current system wall-clock timestamp in signed nanoseconds since the Unix epoch.
- decode_
ctbnbdl_ bundle_ resilient_ with - Resiliently decodes a
.ctbnbdl(CtbNodeBundle1orCtbNodeBundle2) binary buffer, quarantining any corrupted or checksum-mismatched node section while recovering all remaining valid nodes and returning diagnostic warnings for every skipped section. - decode_
ctbnbdl_ bundle_ with - Decodes a
.ctbnbdl(CtbNodeBundle1orCtbNodeBundle2) binary buffer into its optional leadingDc 641system block most recent node ID and its list ofLedgerNodeentries, strictly verifying everyDc 543..544 545section digest. - decode_
nodes_ from_ ctbnbdl_ bytes_ with - Decodes a
.ctbnbdl(CtbNodeBundle1orCtbNodeBundle2) binary buffer back into a list ofLedgerNodeentries (with empty comments, as.ctbnbdlstores only the semantic Dc stream). - encode_
for_ each_ statement_ tokens_ with - Encodes a
Dc 638 "For each"relationship statement over a typed list of[atom_dc]targets:638 <inner_verb> [atom_dc: <inner_subj>] [atom_dc: <inner_obj>] 310 <list_type> <t_1> [312 <t_2> ...] 311. - encode_
node_ definition_ dcmm2_ bytes_ with - Encodes a single
LedgerNodeintoDcMixed2checksummed-section bytes:543 617 [atom_dc: l<id>] <escaped body tokens...> 618 [<SectionTimestampNodeCreationTime> 390 f487 6 f199 [11?] <base64> 7 391]? 544 545 <SHA-256 checksum>. - encode_
node_ definition_ tokens_ with - Encodes a single
LedgerNode(id+tokens) into itsDc 617 .. Dc 618token sequence:617 [atom_dc: l<id>] <escaped body tokens...> 618. - encode_
nodes_ to_ ctbnbdl_ bundles_ with_ limits - Splits a slice of
LedgerNodeentries into one or more.ctbnbdlbundle buffers, each paired with its starting node ID ((first_node_id, bundle_bytes)). - encode_
nodes_ to_ ctbnbdl_ bundles_ with_ limits_ and_ most_ recent - Splits a slice of
LedgerNodeentries into one or more.ctbnbdlbundle buffers, each paired with its starting node ID ((first_node_id, bundle_bytes)), stamping each bundle with the providedmost_recent_node_id(Dc 641 l<most_recent_node_id>). - encode_
nodes_ to_ ctbnbdl_ bytes_ with - Compiles a slice of
LedgerNodeentries into a.ctbnbdl(CtbNodeBundle2) binary buffer: 8-byteCTBNBDL\x02magic + 21-byteDcMixed2header + optional641 l<max_node_id>most_recent - format_
chunk_ bundle_ filename - Formats a global node ID into a
.ctbnbdlchunk bundle filename with_grouping every 5 digits from the right (e.g.,8589934592->"85899_34592.ctbnbdl"). - format_
chunk_ filename - Formats a global node ID into a
.ctbnodeschunk filename with_grouping every 5 digits from the right (e.g.,8589934592->"85899_34592.ctbnodes"). - format_
chunk_ rel_ path - Formats a
.ctbnodeschunk’s relative path insidegraph_dir: - is_
chunk_ prefix_ subdir_ name - Returns
trueifdir_nameis a valid numeric-prefix.ctbnodesshard subdirectory name (e.g."85900","85901","1_00000"). - is_
relationship_ verb_ with - Returns
trueiftokis one of the canonical relationship verbs inframing. - list_
chunk_ files - Returns the sorted list of
.ctbnodeschunk files ingraph_dir(including 1000-file numeric-prefix subdirectories). - load_
ledger_ nodes_ from_ dir - Loads all existing
LedgerNodeentries from.ctbnodeschunk files ingraph_dir. - load_
ledger_ nodes_ from_ file - Loads all
LedgerNodeentries from a single.ctbnodesfile. - load_
ledger_ nodes_ from_ str - Loads all
LedgerNodeentries from a.ctbnodestext string. - parse_
chunk_ bundle_ filename_ start_ id - Parses a
.ctbnbdlchunk filename (e.g.,"85899_34592.ctbnbdl") into its starting node ID. - parse_
chunk_ filename_ start_ id - Parses a
.ctbnodeschunk filename (e.g.,"85899_34592.ctbnodes") into its starting node ID. - parse_
chunk_ rel_ path_ start_ id - Parses a
.ctbnodesrelative path ("85899_34592.ctbnodes"or"85900/85900_34492.ctbnodes") into its starting node ID, validating any parent directory component. - parse_
for_ each_ statement_ tokens_ with - Parses a
Dc 638 "For each"relationship statement node (638 <inner_verb> <inner_subj> <inner_obj> (310 <list_type> <elem_1> [312 <elem_2> ...] 311 | <atom_dc>)) into(inner_verb, inner_subj, inner_obj, list_type, expanded_targets). - parse_
statement_ tokens_ with - Parses a relationship statement
<verb> [atom_dc] [atom_dc]back into(verb, subj, obj). - partition_
active_ and_ inactive_ nodes_ with - Partitions an ordered slice of
LedgerNodeentries into(active_nodes, inactive_nodes)preserving ascending node ID order in both output vectors. - push_
atom_ dc_ with - Appends
tokas an[atom_dc]token toout, escapingDc 203(Begin encapsulated binary data),escape(Dc 255), andevaluate_as_atom(Dc 616) with a leadingescape(Dc 255). - sanitize_
comment - Sanitizes a
.ctbnodescomment string by escaping carriage returns and newlines. - sync_
highwater_ shadow_ ledgers - Synchronizes the append-only high-water shadow ledgers with
nodes. - verify_
nodes_ append_ only_ against_ baseline - Verifies that
current_nodesis a strict append-only extension ofbaseline_nodes(every node inbaseline_nodesmust appear at the same index incurrent_nodeswith the exact sameidandtokens). - verify_
repo_ graph_ append_ only - Verifies
current_nodesagainst both high-water shadow ledgers andgit HEAD(when.gitandgitare available). - write_
chunk_ file_ append_ only - Writes or appends a single
.ctbnodeschunk file using strictly append-only semantics: - write_
ledger_ nodes_ to_ dir - Writes
nodesinto 100-node chunk files (85899_34592.ctbnodes, …) ingraph_dirusing strictly append-only file operations (O_APPENDon partial tail chunks,O_CREAT | O_EXCLon new chunks, and no-op on unchanged full chunks). Returns the number of files written.