A C++17 library implementing the Raft consensus algorithm and a sharded key-value store on top of it.
| Module | Source | Description |
|---|---|---|
| raft | raft_cpp/src/raft.cpp |
Core Raft consensus: leader election, log replication, snapshotting, persistence |
| kvraft | raft_cpp/src/kvraft_server.cpp |
Fault-tolerant KV store on Raft, with client deduplication and linearizable semantics |
| shardctrler | raft_cpp/src/shardctrler.cpp |
Configuration cluster managing dynamic shard-to-group assignment |
| shardkv | raft_cpp/src/shardkv.cpp |
Sharded KV store with cross-group data migration, garbage collection, and concurrent reconfiguration |
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ ShardKVClerk │ │ KVClerk │ │ SCClerk │ ← Client
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
┌──────▼───────┐ ┌──────▼───────┐ ┌──────▼───────┐
│ ShardKV │ │ KVServer │ │ ShardCtrler │ ← Service
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
┌──────▼─────────────────▼─────────────────▼───────┐
│ Raft │ ← Consensus
└───────────────────────────────────────────────────┘
include/raft/*.h exposes all types and interfacesInMemPeer / InMemRaftPeer for fast single-process testinggrpc_server.cpp / grpc_client.cpp for real network deploymentExecute()Persister with readPersist() / persist() for crash recoverycd raft_cpp
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(sysctl -n hw.logicalcpu)
# Run all tests
./raft_test # Raft: 12 tests
./kvraft_test # KV Raft: 4 tests
./shardctrler_test # ShardCtrler: 4 tests
./shardkv_test # ShardKV: 6 tests
macOS:
brew install cmake grpc protobuf googletest rocksdb