Module ctbnbdl

Module ctbnbdl 

Source
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/writer flock guards on the repository’s permanent ledger lock, standalone pending-transaction recovery, and full .ctbnbdl bundle (id, tokens) verification.

Structs§

CtbnbdlFramingDcs
Framing and relationship Document Characters used when encoding, decoding, and partitioning .ctbnbdl node definitions.
LedgerNode
Single node entry in the System-block .ctbnodes ledger.

Constants§

CHUNKS_PER_SUBFOLDER
Number of .ctbnodes files 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 .ctbnodes lines (# @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 + UUID b0327a84-b745-492c-b39d-77c2827e3a6f).
DCMM_HEADER_V1
Legacy 21-byte DcMixed1 (f642) header (DcMM\0 + UUID d5ab819e-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 .ctbnbdl bundle directory.
GRAPH_BUNDLES_SPLIT_HISTORY_SUBDIR
Subdirectory under assets/data/graph-bundles/ holding gitignored historical (inactive) .ctbnbdl bundles.
GRAPH_BUNDLES_SPLIT_LIVE_SUBDIR
Subdirectory under assets/data/graph-bundles/ holding gitignored live (active) .ctbnbdl bundles.
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 .ctbnbdl binary bundle file (50 MB).
MAX_NODES_PER_BUNDLE
Maximum number of node definitions grouped into a single .ctbnbdl binary bundle file.
MAX_NODES_PER_CHUNK
Maximum number of node declarations stored in a single .ctbnodes chunk file.
ROOT_CHUNKS_BEFORE_SUBFOLDER
Maximum number of .ctbnodes files stored directly in the top-level graph directory before sharding into 1000-file prefix subdirectories.

Functions§

bundles_dir_for_graph_dir
Resolves the .ctbnbdl bundle directory associated with graph_dir:
chunk_rel_path_from_graph_dir
Returns path formatted relative to graph_dir using forward-slash separators.
compile_ctbnodes_dir_to_ctbnbdl
Compiles all .ctbnodes chunk files in src_dir into grouped active .ctbnbdl bundle files in dst_dir (up to MAX_NODES_PER_BUNDLE = 1,000,000 nodes or MAX_BYTES_PER_BUNDLE = 50 MB per bundle), removing any stale .ctbnodes or obsolete .ctbnbdl files in dst_dir.
compile_ctbnodes_dir_to_ctbnbdl_with_limits
Compiles all .ctbnodes chunk files in src_dir into grouped active .ctbnbdl bundle files in dst_dir using custom node-count and byte-size limits, removing any stale .ctbnodes or obsolete .ctbnbdl files in dst_dir.
compile_ctbnodes_file_to_ctbnbdl_bytes
Parses a .ctbnodes file on disk and compiles its node definitions into .ctbnbdl bytes.
compile_graph_bundles_from_ctbnodes_dir
Same as compile_graph_bundles_from_ctbnodes_dir_with_limits using default MAX_NODES_PER_BUNDLE and MAX_BYTES_PER_BUNDLE limits.
compile_graph_bundles_from_ctbnodes_dir_with_limits
Compiles all .ctbnodes chunk files in src_dir into:
compile_inactive_ctbnodes_dir_to_ctbnbdl
Compiles all filtered-out inactive (superseded/retracted) nodes from .ctbnodes chunk files in src_dir into grouped .ctbnbdl bundle files in history_dst_dir (up to MAX_NODES_PER_BUNDLE = 1,000,000 nodes or MAX_BYTES_PER_BUNDLE = 50 MB per bundle).
compile_inactive_ctbnodes_dir_to_ctbnbdl_with_limits
Compiles all filtered-out inactive (superseded/retracted) nodes from .ctbnodes chunk files in src_dir into grouped .ctbnbdl bundle files in history_dst_dir using custom node-count and byte-size limits.
consume_atom_dc_with
Consumes an [atom_dc] token at *idx from tokens, unescaping 255 203, 255 255, and 255 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 (CtbNodeBundle1 or CtbNodeBundle2) 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 (CtbNodeBundle1 or CtbNodeBundle2) binary buffer into its optional leading Dc 641 system block most recent node ID and its list of LedgerNode entries, strictly verifying every Dc 543..544 545 section digest.
decode_nodes_from_ctbnbdl_bytes_with
Decodes a .ctbnbdl (CtbNodeBundle1 or CtbNodeBundle2) binary buffer back into a list of LedgerNode entries (with empty comments, as .ctbnbdl stores 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 LedgerNode into DcMixed2 checksummed-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 its Dc 617 .. Dc 618 token sequence: 617 [atom_dc: l<id>] <escaped body tokens...> 618.
encode_nodes_to_ctbnbdl_bundles_with_limits
Splits a slice of LedgerNode entries into one or more .ctbnbdl bundle 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 LedgerNode entries into one or more .ctbnbdl bundle buffers, each paired with its starting node ID ((first_node_id, bundle_bytes)), stamping each bundle with the provided most_recent_node_id (Dc 641 l<most_recent_node_id>).
encode_nodes_to_ctbnbdl_bytes_with
Compiles a slice of LedgerNode entries into a .ctbnbdl (CtbNodeBundle2) binary buffer: 8-byte CTBNBDL\x02 magic + 21-byte DcMixed2 header + optional 641 l<max_node_id> most_recent
format_chunk_bundle_filename
Formats a global node ID into a .ctbnbdl chunk 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 .ctbnodes chunk filename with _ grouping every 5 digits from the right (e.g., 8589934592 -> "85899_34592.ctbnodes").
format_chunk_rel_path
Formats a .ctbnodes chunk’s relative path inside graph_dir:
is_chunk_prefix_subdir_name
Returns true if dir_name is a valid numeric-prefix .ctbnodes shard subdirectory name (e.g. "85900", "85901", "1_00000").
is_relationship_verb_with
Returns true if tok is one of the canonical relationship verbs in framing.
list_chunk_files
Returns the sorted list of .ctbnodes chunk files in graph_dir (including 1000-file numeric-prefix subdirectories).
load_ledger_nodes_from_dir
Loads all existing LedgerNode entries from .ctbnodes chunk files in graph_dir.
load_ledger_nodes_from_file
Loads all LedgerNode entries from a single .ctbnodes file.
load_ledger_nodes_from_str
Loads all LedgerNode entries from a .ctbnodes text string.
parse_chunk_bundle_filename_start_id
Parses a .ctbnbdl chunk filename (e.g., "85899_34592.ctbnbdl") into its starting node ID.
parse_chunk_filename_start_id
Parses a .ctbnodes chunk filename (e.g., "85899_34592.ctbnodes") into its starting node ID.
parse_chunk_rel_path_start_id
Parses a .ctbnodes relative 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 LedgerNode entries into (active_nodes, inactive_nodes) preserving ascending node ID order in both output vectors.
push_atom_dc_with
Appends tok as an [atom_dc] token to out, escaping Dc 203 (Begin encapsulated binary data), escape (Dc 255), and evaluate_as_atom (Dc 616) with a leading escape (Dc 255).
sanitize_comment
Sanitizes a .ctbnodes comment 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_nodes is a strict append-only extension of baseline_nodes (every node in baseline_nodes must appear at the same index in current_nodes with the exact same id and tokens).
verify_repo_graph_append_only
Verifies current_nodes against both high-water shadow ledgers and git HEAD (when .git and git are available).
write_chunk_file_append_only
Writes or appends a single .ctbnodes chunk file using strictly append-only semantics:
write_ledger_nodes_to_dir
Writes nodes into 100-node chunk files (85899_34592.ctbnodes, …) in graph_dir using strictly append-only file operations (O_APPEND on partial tail chunks, O_CREAT | O_EXCL on new chunks, and no-op on unchanged full chunks). Returns the number of files written.