$ show databendlabs/openraft
OpenRaft (databendlabs/openraft) is a production-grade Raft consensus library written in Rust, not a standalone application. It provides the replicated-log, leader-election, membership-change, and snapshot-streaming machinery that database teams embed in their own systems; known consumers include Databend, CnosDB, Walrus, RocketMQ-rust, and Hiqlite. The repository is structured as a workspace: the core `openraft` crate, a `legacy` crate for the deprecated v1 network API, runtime adapter crates (`rt`, `rt-tokio`, `rt-monoio`, `rt-compio`), example KV-store applications (HTTP/gRPC/RocksDB/WAL/OpenDAL backends), a Jepsen fault-injection suite in Clojure, and a deterministic-simulation test harness (`tests-turmoil`) that checks formal Raft invariants (election safety, log matching, leader completeness, state machine safety, monotonicity) against seeded network-failure scenarios. The codebase is at version 0.10.0-alpha.34: the public API is still churning, but the architecture is mature and unusually well tested.
The LLM identified 5 files worth highlighting for reuse:
A generic segmented multi-range-map supporting overlapping-range insertion, query, and iterator-based segment access. It has no openraft-specific imports and can be extracted as a standalone crate for any interval-indexing or range-scheduling problem (log indexes, resource ranges, time intervals). The segment-iterator design demonstrates non-obvious data-structure craftsmanship.
Defines abstract async primitives (Mutex, Mpsc, Oneshot, Watch, Instant, task-local storage) with pluggable implementations in rt-tokio, rt-monoio, and rt-compio. This is the canonical pattern for Rust libraries that must support multiple async executors without leaking a specific runtime into their public API; it is directly reusable by any async framework that needs runtime-agnostic channel and synchronization types.
A `Wait` utility that asynchronously polls a predicate until it becomes true or a deadline expires, using notification-based wakeups instead of busy loops. Generic over runtime and condition type, it is a clean, extractable building block for any application that must await external state changes (leader election, replication lag, applied index, snapshot progress) with timeout support.
Implements `Leased<T, I>`, a generic wrapper that makes any value expire after a configurable interval using a monotonic clock. Openraft uses it for leader leases and vote leases; the pattern generalizes to any distributed system that needs time-bounded authority grants (licenses, locks, tokens) and can be extracted with minimal modification.
An executable invariant-checking framework that asserts Raft safety properties (election safety, log matching, leader completeness, committed-on-quorum, state-machine monotonicity) after every step of a deterministic turmoil simulation, including crash/restart and network-partition scenarios. Although its concrete types are tied to openraft's test harness, the pattern of compiling protocol safety properties into runtime assertions over a seeded distributed-systems simulation is the gold standard for validating consensus implementations and is directly transferable to any consensus-protocol testbed.