An implementation of the Raft distributed consensus protocol for powering a key-value workload (read, write, CAS).
- dependency-free, stdlib-only Rust (cold, release compile in ~1s)
- custom JSON parser and ser/de framework, with OK performance (ballpark of ~220 MB/s throughput on Apple M3 on complex input (UTF-16 surrogate etc.)) and full spec compliance, passing JSON minefield stress test suite
- base64 non-URL
randhelper (Unix only)- Prometheus-style metrics
(example;
n1stepping its term during a partition) with a simple HTTP/1.1 server
- Raft implementation passes Jepsen Maelstrom chaos
testing, for the linearizable KV
workload (the failures in
the graph are expected, it is Jepsen probing for linearizability)
- fully generic (literally and design-wise) core Raft: applicable to any workload backable by Raft; the core just holds opaque commands in its log, with an abstract state machine dependency-injected for committing into
- channel-based glue layer to translate between KV RPCs and Raft core; enables pluggable I/O
- focus on correctness: illegal states made
unrepresentable levering the type
system where feasible, and liberal use of
asserts for pre/post conditions. Nounsafe, no shenanigans
-
TCP/HTTP: I/O and the binary are specific to Jepsen Maelstrom, but that's just a couple hundred lines
-
async: stdlib-only, so threading is used.
This is implemented asynchronously and non-blocking all the same: client and Raft RPCs can be emitted and received at any time. Awaiting responses to emitted RPCs is asynchronous as well, though messages go into single-receiver queues. That serializes requets, but the necessary mutual exclusion on the core Raft state does so anyway (there is only one lock, which incidentally makes deadlock-freedom much simpler to guarantee!)
-
live cluster configuration changes