HW: Fault-Tolerant Key-Value Service (Rust)
In this assignment, which is based on labs from MIT 6.5840, you will build a fault-tolerant key-value storage service from the ground up. You will start with a single-server key/value store, then implement the Raft consensus algorithm, and finally combine them into a replicated service that continues operating even when servers crash or become partitioned.
This assignment has four parts:
- Simple Key-Value Server
Implement a single-server KV store with versioned puts and a client that communicates via RPC. - Distributed Lock
Build a lock service on top of your KV store. - Raft
Implement the Raft consensus algorithm with leader election, log replication, and persistence. - Fault-Tolerant KV Store
Combine Raft with the KV store to build a replicated state machine, and adapt your client and lock to work with the cluster.
Getting started
Pull the starter code. Build and verify the project compiles.
cd ~/code/personal
git pull staff main
cd hw-kvsrv-rs
rustup override set stable
cargo build
You will see compiler warnings about unused variables and todo!(). Don’t worry, these are expected as long as you do not see any errors.
Testing
Tests use process forking for isolation, so they must run single-threaded:
# Parts 1-2: Single-server KV and Distributed Lock
cargo test --test kvsrv_test -- --test-threads=1
# Part 3: Raft
cargo test --test raft_test -- --test-threads=1
# Part 4: Fault-tolerant KV
cargo test --test kvraft_test -- --test-threads=1
You can run a specific test by name:
cargo test --test kvsrv_test test_reliable_put -- --test-threads=1
Resources
- Raft paper (extended version) Please read this. Sections 5 and 6 along with Figure 2 are most important.
- Raft visualization
- MIT 6.5840 Raft guide. Some practical tips.