https://github.com/redislabs/raft
C implementation of the Raft Consensus protocol, BSD licensed
https://github.com/redislabs/raft
Last synced: 12 months ago
JSON representation
C implementation of the Raft Consensus protocol, BSD licensed
- Host: GitHub
- URL: https://github.com/redislabs/raft
- Owner: RedisLabs
- License: other
- Created: 2018-02-23T21:55:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-09-08T06:18:20.000Z (almost 3 years ago)
- Last Synced: 2025-04-06T17:01:34.305Z (about 1 year ago)
- Language: C
- Homepage:
- Size: 973 KB
- Stars: 71
- Watchers: 5
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/RedisLabs/raft/actions/workflows/daily.yml)
[](https://codecov.io/gh/RedisLabs/raft)
A complete implementation of the [Raft Consensus Algorithm](https://raft.github.io) as a C library, licensed under BSD.
This is a fork of the original library created by Willem-Hendrik Thiart, which is now actively maintained by Redis Ltd. and used as part of [RedisRaft](https://github.com/redislabs/redisraft).
See [raft.h](https://github.com/redislabs/raft/blob/master/include/raft.h) for full API documentation.
Main Features
=============
The library implements all basic features of Raft as well as some extensions, including:
* Leader election
* Log replication and FSM interface
* Compaction and snapshot support
* Cluster membership changes
* Quorum check and step-down by leader
* Pre-vote
* Leadership transfer
The library is completely abstract and it is up to the caller to implement things like:
* RPC and networking
* Log storage and access
* Generation of snapshots from FSM state
Getting Started
===============
To build and run basic tests:
```
make tests
```
If you prefer, you can also use cmake:
```
mkdir build
cd build
cmake ..
make
make test
```
Tests
=====
The library uses the following testing methods:
* A simulator (virtraft2) is used to test the Raft invariants on unreliable networks
* All bugs have regression tests
* Many unit tests
virtraft2
---------
This cluster simulator checks the following:
* Log Matching (servers must have matching logs)
* State Machine Safety (applied entries have the same ID)
* Election Safety (only one valid leader per term)
* Current Index Validity (does the current index have an existing entry?)
* Entry ID Monotonicity (entries aren't appended out of order)
* Committed entry popping (committed entries are not popped from the log)
* Log Accuracy (does the server's log match mirror an independent log?)
* Deadlock detection (does the cluster continuously make progress?)
Chaos generated by virtraft2:
* Random bi-directional partitions between nodes
* Message dropping
* Message duplication
* Membership change injection
* Random compactions
Run the simulator using:
```
mkdir .env
virtualenv .env
source .env/bin/activate
pip install -r tests/requirements.txt
make test_virtraft
```
Requirements
---------
* Python 3.9 or later