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.
- Leader Election: Manages the election process for choosing a new leader in the cluster.
- Log Replication: Consistently replicates logs across all nodes in the cluster.
- Safety: Guarantees the integrity and durability of committed entries.
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.
- C++20 compatible compiler
- CMake for building the project
- Cmocka for unit testing
- Clone the repository:
git clone https://github.com/resetius/miniraft-cpp
- Initialize and update the submodule:
git submodule init git submodule update
- Navigate to the project directory:
cd miniraft-cpp
- Build the project using CMake:
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.
- Implementation of the Raft Consensus Algorithm Using C++20 Coroutines
- Разработка сетевой библиотеки на C++20: интеграция асинхронности и алгоритма Raft (часть 1)
- Разработка сетевой библиотеки на C++20: интеграция асинхронности и алгоритма Raft (часть 2)
- High-performance network library using C++20 coroutines
- Simplifying Raft with C++20 coroutines