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 .jcol Segment Engine (disk_col_segments.rs + execute_segmented, v0.8.0–v0.12.0): Drains tables exceeding JOULEDB_COL_SPILL_ROWS (131,072 rows, using disjoint JCOL_ID_TAG [1 << 62] segment IDs, owned-batch Parquet streaming, and GNU/Linux malloc_trim(0) heap release) into immutable .jcol files (I8/I16/I32/I64 narrowing, Arrow Decimal128 streaming ingest, bitpacked null masks, compact u8/u16/u32 local string dictionaries, per-column global_int_sum + min_i64/max_i64 ZoneMaps, CRC-32 slice + JCL1 footer checksums). Executes all 43 / 43 Official ClickBench queries on the full 99,997,497-row (14.78 GB) dataset in 5.90 GB post-load RSS (2.11× geomean vs DuckDB 2.0.1).
  • Out-of-Core Columnar Multi-Table Join & Subquery Engine (columnar_join.rs, v0.11.0–v0.12.0): Streams 262,144-row .jcol probe segments in parallel against compact post-order Snowflake dimension hash branches (DenseKeyBits::overlaps_range zero-I/O ZoneMap pruning, two-stage sparse dictionary loading via load_filtered_segment, CompactCol, DenseUnique1, HashUnique1, HashMulti1, Hash2, O(1) DictBitset string/date predicates, derived-table flattening, WITH CTEs, parallel LEFT OUTER JOIN grouped count for Q13, NeqSummary + outer-domain pushdown for Q21, 64-shard radix-partitioned single-i64 GROUP BY for Q18, <= 20M-row semi-join key propagation for Q10, outer-domain correlated scalar MIN/MAX/SUM/AVG for Q02, Q17, Q20, and OR-branch bounding filters for Q07, Q19) — executing all 22 / 22 official TPC-H queries (tpch_queries()) exact over TCP pgwire at SF=0.1 (1.99× geomean, 5 wins), SF=1.0 (8.66M rows in 1.78 s, 4.33× geomean, 201.4 MB post-load RSS), AND SF=10.0 (86.6M rows / 60M lineitem out-of-core in 755.3 MB post-load RSS, 15.46 s total, 8.49× geomean).
  • Morsel-Parallel In-Memory Engine (columnar_exec.rs): Executes single-table scans, PrepPred zone-map/dictionary filters, VCol virtual projections (EXTRACT, DATE_TRUNC, STRLEN, REGEXP_REPLACE, CASE WHEN, FloatArith, DictExtractInt), algebraic SUM(col ± k) scan sharing, inline HKey/GKey grouped aggregations, HAVING, and parallel Top-K ORDER BY ... LIMIT.
  • 64-Shard MvccStore/MvccTableStorage + Binary JMVR/JWB1/JWU1 OLTP (mvcc.rs, mvcc_adapter.rs, amorphic_adapter/*, pgwire.rs): 64-shard MvccStore (find_visible_at zero-HashSet-clone reads), 64-shard table_id_shards & session table, SchemaMetaCache, try_direct_indexed_eq_query (O(1) point reads and O(k) register-accumulated indexed COUNT/SUM), binary JMVR\x01 MvccRecord + JWB1 batch_ingest_fields + JWU1 UpdateFields delta WAL encoding (deferring HDC hypervectors off INSERT/UPDATE commits), and adaptive SmallVec/BTreeSet ValueIds (1,950.5 TPS vs PostgreSQL 16.16 1,199.7 TPS at c=1 Simple; 5,154.1 TPS Simple / 5,159.7 TPS Pipelined at c=16 on physical NVMe fdatasync, invariant_verified = true).
  • Window Frames, CUBE & WITH RECURSIVE (sql2023_powerhouse.rs): Partitioned ROW_NUMBER/RANK/DENSE_RANK/LAG/LEAD/CUME_DIST + ROWS BETWEEN sliding frames, 3D CUBE with GROUPING_ID bitmasks, 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 spilling CRC-32-checked JMSB partitions to disk when hash state exceeds memory_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:

  1. 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, and CRC-32 on-disk RaftWal recovery.
    • 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.4 ReadIndex: records read_index = commit_index, confirms current-term leadership via a majority round of empty-AppendEntries heartbeats (zero Raft log / WAL writes), waits until last_applied >= read_index, and reads the local state machine linearizably while rejecting stale-leader reads on isolated minority nodes. (Direct RaftNode::with_state_machine remains 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_node processes across 2 distinct physical Linux hosts over encrypted Tailscale WAN (framework-128gb-0000 bare-metal + openie-core-1 Cloud Debian 12 VM, 27.58 ms median WAN TCP RTT), injects a cross-WAN 2/5 minority split (["n1", "n4"] vs ["n2", "n3", "n5"]) isolating initial leader n1, verifies stale write & ReadIndex read rejection on n1 while majority quorum elects n3 (term 2) and commits 24 ops, sends real OS SIGKILL (kill -9) to cloud node n5 (16 ops committed during crash), restarts n5 from raft.wal, verifies 5-node state convergence (commit=68, applied=68, x=68, y=39 across both hosts), and checks the 270-event EDN history (bench/results/raft_wan_multihost_elle_history.edn) with Kyle Kingsbury's official Clojure elle/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_injection runs the deterministic 20-link socket-severing TcpPartitionMatrix check (76 events -> {:valid? true}).
  2. Fast Scripted In-Memory Unit Simulation (distributed_jepsen_consensus.rs):

    • Simulates 5 GeoRaftReplica structs in a Vec to unit-test HlcStamp monotonicity and staleness-bound arithmetic (est_wire_energy_nj = 12 analytical constant, energy_evidence = "est_j"). It is a deterministic unit check (simulation_only: true), not a networked Raft or Jepsen run.