Raft Consensus Algorithm. Uses in-house C++20 coroutines-based library for communications. Tested with unit-tests.
BSD-2-CLAUSE License
MiniRaft-CPP is an implementation of the Raft consensus algorithm using C++20. This project leverages the coroio library for efficient asynchronous I/O operations. It aims to provide a clear and efficient representation of the Raft protocol, ensuring consistency and reliability in distributed systems.
raft.h
/ raft.cpp
: Implementation of the core Raft algorithm.messages.h
/ messages.cpp
: Message definitions for node communication.timesource.h
: Time-related functionalities for Raft algorithm timings.server.h
/ server.cpp
: Server-side logic for handling client requests and node communication.client.cpp
: Client-side implementation for cluster interaction.git clone https://github.com/resetius/miniraft-cpp
git submodule init
git submodule update
cd miniraft-cpp
cmake .
make
This is a simple application designed to demonstrate log replication in the Raft consensus algorithm.
To start the application, launch the servers with the following commands:
./server --id 1 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
./server --id 2 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
./server --id 3 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
To interact with the system, run the client as follows:
./client --node 127.0.0.1:8001:1
The client expects an input string to be added to the distributed log. If the input string starts with an underscore (_
), it should be followed by a number (e.g., _ 3
). In this case, the client will attempt to read the log entry at the specified number.
Additionally, there's an example implementing a distributed key-value (KV) store.
To start the KV store servers, use:
./kv --server --id 1 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
./kv --server --id 2 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
./kv --server --id 3 --node 127.0.0.1:8001:1 --node 127.0.0.1:8002:2 --node 127.0.0.1:8003:3
To run the KV client, use:
./kv --client --node 127.0.0.1:8001:1
The KV client expects commands as input:
set <key> <value>
- Adds or updates a value in the KV store.get <key>
- Retrieves a value by its key.list
- Displays all key/value pairs in the store.del <key>
- Deletes a key from the store.