SQL Vectorized Execution, Out-of-Core .jcol Segments, Columnar TPC-H Join Engine & Multi-Host WAN TCP Raft (v0.12.0)
This chapter separates JouleDB's query execution engines from its networked TCP Raft consensus engine and states what each test actually exercises.
1. Out-of-Core .jcol Segments, Vectorized SQL & Columnar Multi-Table TPC-H Join Engine (disk_col_segments.rs, columnar_exec.rs, columnar_join.rs, mvcc_adapter.rs)
- Out-of-Core
.jcolSegment Engine (disk_col_segments.rs+execute_segmented,v0.8.0–v0.12.0): Drains tables exceedingJOULEDB_COL_SPILL_ROWS(131,072rows, using disjointJCOL_ID_TAG[1 << 62] segment IDs, owned-batch Parquet streaming, and GNU/Linuxmalloc_trim(0)heap release) into immutable.jcolfiles (I8/I16/I32/I64narrowing, ArrowDecimal128streaming ingest, bitpacked null masks, compactu8/u16/u32local string dictionaries, per-columnglobal_int_sum+min_i64/max_i64ZoneMaps, CRC-32 slice +JCL1footer checksums). Executes all43 / 43Official ClickBench queries on the full99,997,497-row (14.78 GB) dataset in5.90 GBpost-load RSS (2.11×geomean vs DuckDB2.0.1). - Out-of-Core Columnar Multi-Table Join & Subquery Engine (
columnar_join.rs,v0.11.0–v0.12.0): Streams262,144-row.jcolprobe segments in parallel against compact post-order Snowflake dimension hash branches (DenseKeyBits::overlaps_rangezero-I/O ZoneMap pruning, two-stage sparse dictionary loading viaload_filtered_segment,CompactCol,DenseUnique1,HashUnique1,HashMulti1,Hash2,O(1)DictBitsetstring/date predicates, derived-table flattening,WITHCTEs, parallelLEFT OUTER JOINgrouped count forQ13,NeqSummary+ outer-domain pushdown forQ21, 64-shard radix-partitioned single-i64GROUP BYforQ18,<= 20M-row semi-join key propagation forQ10, outer-domain correlated scalarMIN/MAX/SUM/AVGforQ02, Q17, Q20, andOR-branch bounding filters forQ07, Q19) — executing all22 / 22officialTPC-Hqueries (tpch_queries()) exact over TCPpgwireatSF=0.1(1.99×geomean,5wins),SF=1.0(8.66Mrows in1.78 s,4.33×geomean,201.4 MBpost-load RSS), ANDSF=10.0(86.6Mrows /60Mlineitemout-of-core in755.3 MBpost-load RSS,15.46 stotal,8.49×geomean). - Morsel-Parallel In-Memory Engine (
columnar_exec.rs): Executes single-table scans,PrepPredzone-map/dictionary filters,VColvirtual projections (EXTRACT,DATE_TRUNC,STRLEN,REGEXP_REPLACE,CASE WHEN,FloatArith,DictExtractInt), algebraicSUM(col ± k)scan sharing, inlineHKey/GKeygrouped aggregations,HAVING, and parallel Top-KORDER BY ... LIMIT. - 64-Shard
MvccStore/MvccTableStorage+ BinaryJMVR/JWB1/JWU1OLTP (mvcc.rs,mvcc_adapter.rs,amorphic_adapter/*,pgwire.rs): 64-shardMvccStore(find_visible_atzero-HashSet-clone reads), 64-shardtable_id_shards& session table,SchemaMetaCache,try_direct_indexed_eq_query(O(1)point reads andO(k)register-accumulated indexedCOUNT/SUM), binaryJMVR\x01MvccRecord+JWB1batch_ingest_fields+JWU1UpdateFieldsdelta WAL encoding (deferring HDC hypervectors offINSERT/UPDATEcommits), and adaptiveSmallVec/BTreeSetValueIds(1,950.5 TPSvsPostgreSQL 16.161,199.7 TPSatc=1Simple;5,154.1 TPSSimple /5,159.7 TPSPipelined atc=16on physical NVMefdatasync,invariant_verified = true). - Window Frames,
CUBE&WITH RECURSIVE(sql2023_powerhouse.rs): PartitionedROW_NUMBER/RANK/DENSE_RANK/LAG/LEAD/CUME_DIST+ROWS BETWEENsliding frames, 3DCUBEwithGROUPING_IDbitmasks, cycle-pruned recursive CTEs, and runtime Adaptive Query Execution (AQE) join switching. - Out-of-Core Morsel Spill (
morsel_spill.rs):2,048-row columnar morsels spillingCRC-32-checkedJMSBpartitions to disk when hash state exceedsmemory_budget_bytes.
2. Networked TCP Raft Consensus (raft.rs, raft_server.rs, raft_transport.rs)
JouleDB contains two distinct consensus code paths that must not be conflated:
-
Production Networked TCP Raft Engine (
crates/joule-db-server/src/{raft.rs, raft_server.rs, raft_transport.rs}+examples/raft_wan_node.rs+ TLA+ spec):- Full Ongaro & Ousterhout Raft state machine (
Follower,Candidate,Leader),RequestVote,AppendEntries,InstallSnapshot(with optional Reed-Solomon erasure shards), joint-consensus membership changes, andCRC-32on-diskRaftWalrecovery. - Quorum Writes (
RaftNode::propose_and_commit): Appends to the leader WAL and awaits majority replication (commit_index >= index) plus Raft §5.4.2 current-term commit verification before returning. - Quorum Linearizable Reads (
RaftNode::read_index&RaftNode::read_linearizable): Implements Ongaro & Ousterhout Raft §6.4ReadIndex: recordsread_index = commit_index, confirms current-term leadership via a majority round of empty-AppendEntriesheartbeats (zero Raft log / WAL writes), waits untillast_applied >= read_index, and reads the local state machine linearizably while rejecting stale-leader reads on isolated minority nodes. (DirectRaftNode::with_state_machineremains available for explicitly local/bounded-staleness reads.) - 5-Node Multi-Host Cross-Machine WAN/Tailscale Fault-Injection + Official
elle(0.2.8) Verification (bench/raft_multihost_wan.py&tests/raft_tcp_elle_fault_injection.rs):- Cross-Machine WAN Run: Spawns 5 separate OS
raft_wan_nodeprocesses across 2 distinct physical Linux hosts over encrypted Tailscale WAN (framework-128gb-0000bare-metal +openie-core-1Cloud Debian 12 VM,27.58 msmedian WAN TCP RTT), injects a cross-WAN2/5minority split (["n1", "n4"]vs["n2", "n3", "n5"]) isolating initial leadern1, verifies stale write &ReadIndexread rejection onn1while majority quorum electsn3(term2) and commits24ops, sends real OSSIGKILL(kill -9) to cloud noden5(16ops committed during crash), restartsn5fromraft.wal, verifies 5-node state convergence (commit=68, applied=68, x=68, y=39across both hosts), and checks the270-event EDN history (bench/results/raft_wan_multihost_elle_history.edn) with Kyle Kingsbury's official Clojureelle/elle 0.2.8(rw-register,:strict-serializable->{:valid? true}). - Single-Host Integration Test:
cargo test -p joule-db-server --test raft_tcp_elle_fault_injectionruns the deterministic 20-link socket-severingTcpPartitionMatrixcheck (76events ->{:valid? true}).
- Cross-Machine WAN Run: Spawns 5 separate OS
- Full Ongaro & Ousterhout Raft state machine (
-
Fast Scripted In-Memory Unit Simulation (
distributed_jepsen_consensus.rs):- Simulates 5
GeoRaftReplicastructs in aVecto unit-testHlcStampmonotonicity and staleness-bound arithmetic (est_wire_energy_nj = 12analytical constant,energy_evidence = "est_j"). It is a deterministic unit check (simulation_only: true), not a networked Raft or Jepsen run.
- Simulates 5