11 releases (6 breaking)
✓ Uses Rust 2018 edition
|0.6.0-alpha||Jul 24, 2019|
|0.5.0||Feb 20, 2019|
|0.4.3||May 8, 2019|
|0.4.0||Sep 21, 2018|
|0.0.0||Jun 17, 2015|
#39 in Algorithms
643 downloads per month
Used in 16 crates (14 directly)
When building a distributed system one principal goal is often to build in fault-tolerance. That is, if one particular node in a network goes down, or if there is a network partition, the entire cluster does not fall over. The cluster of nodes taking part in a distributed consensus protocol must come to agreement regarding values, and once that decision is reached, that choice is final.
Distributed Consensus Algorithms often take the form of a replicated state machine and log. Each state machine accepts inputs from its log, and represents the value(s) to be replicated, for example, a hash table. They allow a collection of machines to work as a coherent group that can survive the failures of some of its members.
Two well known Distributed Consensus Algorithms are Paxos and Raft. Paxos is used in systems like Chubby by Google, and Raft is used in things like
etcd. Raft is generally seen as a more understandable and simpler to implement than Paxos.
Raft replicates the state machine through logs. If you can ensure that all the machines have the same sequence of logs, after applying all logs in order, the state machine will reach a consistent state.
A complete Raft model contains 4 essential parts:
Consensus Module, the core consensus algorithm module;
Log, the place to keep the Raft logs;
State Machine, the place to save the user data;
Transport, the network layer for communication.
Note: This Raft implementation in Rust includes the core Consensus Module only, not the other parts. The core Consensus Module in the Raft crate is customizable, flexible, and resilient. You can directly use the Raft crate, but you will need to build your own Log, State Machine and Transport components.
You can use raft with either rust-protobuf or Prost to encode/decode gRPC messages. We use rust-protobuf by default. To use Prost, build (or depend on) Raft using the
prost-codec feature and without default features.
Raft is built using the latest version of
stable Rust, using the 2018 edition.
Minimum supported version is
rustup you can get started this way:
rustup component add clippy rustup component add rustfmt
In order to have your PR merged running the following must finish without error:
cargo test --all && \ cargo clippy --all -- -D clippy::all && \ cargo fmt --all -- --check
You may optionally want to install
cargo-watch to allow for automated rebuilding while editing:
cargo watch -s "cargo check"
See instructions in the proto subdirectory.
We use Criterion for benchmarking.
It's currently an ongoing effort to build an appropriate benchmarking suite. If you'd like to help out please let us know! Interested?
You can run the benchmarks by installing
gnuplot then running:
You can check
target/criterion/report/index.html for plots and charts relating to the benchmarks.
You can check the performance between two branches:
git checkout master cargo bench --bench benches -- --save-baseline master git checkout other cargo bench --bench benches -- --baseline master
This will report relative increases or decreased for each benchmark.
Thanks etcd for providing the amazing Go implementation!
- TiKV, a distributed transactional key value database powered by Rust and Raft.