Skip to content
/ raft Public
forked from canonical/raft

C implementation of the Raft consensus protocol

License

Notifications You must be signed in to change notification settings

mphyatgh/raft

 
 

Repository files navigation

CI Tests codecov Documentation Status

English|简体中文

Fully asynchronous C implementation of the Raft consensus protocol.

The library has modular design: its core part implements only the core Raft algorithm logic, in a fully platform independent way. On top of that, a pluggable interface defines the I/O implementation for networking (send/receive RPC messages) and disk persistence (store log entries and snapshots).

A stock implementation of the I/O interface is provided when building the library with default options. It is based on libuv and should fit the vast majority of use cases. The only catch is that it currently requires Linux, since it uses the Linux AIO API for disk I/O. Patches are welcome to add support for more platforms.

See raft.h for full documentation.

License

This raft C library is released under a slightly modified version of LGPLv3, that includes a copyright exception letting users to statically link the library code in their project and release the final work under their own terms. See the full license text.

Features

This implementation includes all the basic features described in the Raft dissertation:

  • Leader election
  • Log replication
  • Log compaction
  • Membership changes

It also includes a few optional enhancements:

  • Optimistic pipelining to reduce log replication latency
  • Writing to leader's disk in parallel
  • Automatic stepping down when the leader loses quorum
  • Leadership transfer extension
  • Pre-vote protocol

Install

If you are on a Debian-based system, you can get the latest development release from dqlite's dev PPA:

sudo add-apt-repository ppa:dqlite/dev
sudo apt-get update
sudo apt-get install libraft-dev

Building

To build libraft from source you'll need:

  • A reasonably recent version of libuv (v1.18.0 or beyond).
  • Optionally, but recommended, a reasonably recent version of liblz4 (v1.7.1 or beyond).
sudo apt-get install libuv1-dev liblz4-dev libtool pkg-config build-essential
autoreconf -i
./configure --enable-example
make

Example