30个版本

0.9.5 2022年12月8日
0.9.1 2022年2月12日
0.7.6 2021年9月13日
0.7.2 2021年4月1日
0.5.3 2020年11月30日

#793 in 算法

Download history 2/week @ 2024-03-09 72/week @ 2024-03-30 7/week @ 2024-04-06

81 每月下载量

MIT 许可证

190KB
4.5K SLoC

lol

Crates.io documentation CI MIT licensed Tokei

Rust语言中的Raft实现。请为该项目点赞以支持它:

文档

特性

  • 实现了所有基本的Raft特性:复制、领导人选举、日志压缩、持久性、动态成员变更、流式快照等。
  • 基于Tonic,并充分利用高效的gRPC流式传输在日志复制和快照复制中。
  • 使用Phi累加故障检测器进行领导人故障检测。这个自适应算法让你在部署前不必选择一个固定的超时时间,并使得在地理分布式环境中部署Raft节点成为可能。这个算法也用于Akka
  • 清晰的抽象:RaftApp是你在Raft上下文中的应用或状态机。RaftStorage是对后端存储的抽象,它支持内存和持久(由RocksDB支持)。

使用方法

将以下内容添加到你的Cargo.toml中。

[dependencies]
lol-core = "0.9"

可用的功能标志

  • simple:启用SimpleRaftApp
  • gateway:启用Gateway与集群交互。
  • rocksdb-backend:启用基于RocksDB的RaftStorage

示例

// 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;

开发

使用docker容器在你的计算机上创建开发环境。

  • 使用make构建docker镜像
  • ./dev 启动开发容器

然后

  • cargo build 编译整个项目
  • make test 运行回归测试
  • make bench 运行基准测试

依赖项

~7-15MB
~260K SLoC