30 releases

0.9.5 Dec 8, 2022
0.9.1 Feb 12, 2022
0.7.6 Sep 13, 2021
0.7.2 Apr 1, 2021
0.5.3 Nov 30, 2020

#785 in Algorithms

Download history 168/week @ 2024-07-25 22/week @ 2024-08-01 40/week @ 2024-09-19 22/week @ 2024-09-26

81 downloads per month

MIT license

190KB
4.5K SLoC

lol

Crates.io documentation CI MIT licensed Tokei

A Raft implementation in Rust language. To support this project please give it a ⭐

Documentation

Features

  • Implements all basic Raft features: Replication, Leader Election, Log Compaction, Persistency, Dynamic Membership Change, Streaming Snapshot, etc.
  • Based on Tonic and efficient gRPC streaming is fully utilized in log replication and snapshot copying.
  • Phi Accrual Failure Detector is used in leader failure detection. This adaptive algorithm lets you not choose a fixed timeout number before deployment and makes it possible to deploy Raft node in Geo-distributed environment. This algorithm is also used in Akka.
  • Clear Abstractions: RaftApp is your application or state machine in Raft's context. RaftStorage is the abstraction of the backend storage with which both in-memory and persistent (backed by RocksDB) are supported.

Usage

Add this to your Cargo.toml.

[dependencies]
lol-core = "0.9"

Available feature flags:

  • simple: Enables SimpleRaftApp.
  • gateway: Enables Gateway to interact with the cluster.
  • rocksdb-backend: Enables RocksDB-backed RaftStorage.

Example

// Implement RaftApp for YourApp!
struct YourApp { ... }
impl RaftApp for YourApp {
    ...
}
// Initialize your app.
let app = YourApp { ... };
// Choose a backend.
let storage = storage::memory::Storage::new();
// This is the Id of this node.
let uri = "https://192.168.10.15:50000".parse().unwrap();
let config = ConfigBuilder::default().build().unwrap();
// Make a tower::Service.
let service = make_raft_service(app, storage, uri, config);
// Start a gRPC server with the service.
tonic::transport::Server::builder()
    .add_service(service)
    .serve(socket).await;

Development

Use docker container to make an dev environment on your computer.

  • make to build the docker image
  • ./dev to start the dev container

then

  • cargo build to compile the entire project
  • make test to run the regression tests
  • make bench to run the benchmark tests

Dependencies

~7–19MB
~259K SLoC