2 releases

0.1.1 Mar 7, 2024
0.1.0 Jan 25, 2024

#1210 in Asynchronous

Download history 24/week @ 2024-02-19 9/week @ 2024-02-26 151/week @ 2024-03-04 29/week @ 2024-03-11 37/week @ 2024-04-01

72 downloads per month

MIT/Apache

29KB
613 lines

one-file-raft

This is a concise, demonstrative implementation of the Raft consensus algorithm contained within a single Rust file, approximately 300 lines in length.

The primary objective is to provide an educational demo that shows the core principles of a distributed consensus protocol, free from the complexities of application-specific business logic, edge case management, and error handling.

The implementation focuses on the fundamental aspects of Raft, such as leader election, log replication and log commit, while omitting advanced features like log compaction and log purging.

./loc.sh
     300

For a production use of Raft, refer to Openraft


lib.rs:

Features:

  • Election(Raft::elect())
  • Log replication(Raft::handle_replicate_req())
  • Commit
  • Write application data(Raft::write())
  • Membership store(Store::configs).
  • Membership change: joint consensus.
  • Event loop model(main loop: Raft::run()).
  • Pseudo network simulated by mpsc channels(Net).
  • Pseudo Log store simulated by in-memory store(Store).
  • Raft log data is a simple String
  • Metrics

Not yet implemented:

  • State machine(Raft::commit() is a no-op entry)
  • Log compaction
  • Log purge
  • Heartbeat
  • Leader lease
  • Linearizable read

Implementation details:

  • Membership config takes effect once appended(not on-applied).
  • Standalone Leader, it has to check vote when accessing local store.
  • Leader access store directly(not via RPC).
  • Append log when vote?

Dependencies

~4–5.5MB
~97K SLoC