Skip to content

Commit 8eef3fe

Browse files
committed
Improve readme
1 parent 186ac41 commit 8eef3fe

1 file changed

Lines changed: 77 additions & 22 deletions

File tree

README.md

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,85 @@
44
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/resetius/miniraft-cpp)
55
[![GitHub license which is BSD-2-Clause license](https://img.shields.io/github/license/resetius/miniraft-cpp)](https://github.com/resetius/miniraft-cpp)
66

7+
## Table of Contents
8+
- [Overview](#overview)
9+
- [Key Features](#key-features)
10+
- [Project Structure](#project-structure)
11+
- [Getting Started](#getting-started)
12+
- [Prerequisites](#prerequisites)
13+
- [Building the Project](#building-the-project)
14+
- [Running the Application](#running-the-application)
15+
- [Example: State Machine (RSM) with Key-Value Store](#example-state-machine-rsm-with-key-value-store)
16+
- [Server Mode](#server-mode)
17+
- [Client Mode](#client-mode)
18+
- [Media](#media)
19+
20+
---
21+
722
## Overview
8-
MiniRaft-CPP is an implementation of the Raft consensus algorithm using C++20. This project leverages the [coroio library](https://github.com/resetius/coroio) 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.
23+
**MiniRaft-CPP** is a C++20 implementation of the Raft consensus algorithm.
24+
It uses the [coroio library](https://github.com/resetius/coroio) for efficient asynchronous I/O and
25+
aims to provide a straightforward reference for how Raft handles leader election,
26+
log replication, and fault tolerance in a distributed system.
927

28+
---
1029

1130
## Key Features
12-
- **Leader Election**: Manages the election process for choosing a new leader in the cluster.
13-
- **Log Replication**: Consistently replicates logs across all nodes in the cluster.
14-
- **Safety**: Guarantees the integrity and durability of committed entries.
31+
- **Leader Election** (supported)
32+
- **Log Replication** (supported)
33+
- **Persistence** (supported)
34+
- **Snapshots** (not supported yet)
35+
- **Membership Change** (not supported yet)
36+
37+
The project focuses on a clear, modular design that leverages C++20 coroutines to simplify asynchronous flows.
38+
39+
---
40+
41+
## Project Structure
42+
43+
- **`miniraft/`**
44+
This directory contains the **MiniRaft library**, which implements all core components required for Raft consensus.
45+
- **`raft.h` / `raft.cpp`**: Core files defining the Raft algorithm (leader election, log replication, etc.).
46+
47+
- **`miniraft/net/`**
48+
A **network library** that builds on top of MiniRaft and uses [coroio](https://github.com/resetius/coroio) for asynchronous I/O.
49+
- **`server.h` / `server.cpp`**: Main networking/server implementation for node-to-node communication and client handling.
50+
51+
- **`examples/`**
52+
Contains sample applications that demonstrate how to use the MiniRaft libraries:
53+
- **`kv.cpp`**: A distributed key-value store implemented on top of Raft.
54+
55+
56+
### Using MiniRaft as a Git Submodule
57+
If you want to embed this project into your own codebase as a submodule, you can do one of the following:
1558

16-
## Components
17-
- `raft.h` / `raft.cpp`: Implementation of the core Raft algorithm.
18-
- `messages.h` / `messages.cpp`: Message definitions for node communication.
19-
- `timesource.h`: Time-related functionalities for Raft algorithm timings.
20-
- `server.h` / `server.cpp`: Server-side logic for handling client requests and node communication.
21-
- `client.cpp`: Client-side implementation for cluster interaction.
59+
1. **Consensus Only**: If you only need the Raft consensus logic without networking, you can include:
60+
```cmake
61+
add_subdirectory(miniraft)
62+
```
63+
64+
Then link against the miniraft library.
65+
66+
2. **Consensus + Networking**: If you also need the built-in server/network layer, add:
67+
68+
```cmake
69+
add_subdirectory(miniraft)
70+
add_subdirectory(miniraft/net)
71+
```
72+
73+
Then link against miniraft.net which also brings in miniraft internally.
74+
75+
---
2276

2377
## Getting Started
2478

2579
### Prerequisites
26-
- C++20 compatible compiler
27-
- CMake for building the project
28-
- [Cmocka](https://cmocka.org/) for unit testing
80+
- A C++20-compatible compiler
81+
- CMake (for building)
82+
- [Cmocka](https://cmocka.org/) (for unit tests only)
2983

3084
### Building the Project
31-
1. Clone the repository:
85+
1. Clone the repository:
3286
```
3387
git clone https://github.com/resetius/miniraft-cpp
3488
```
@@ -37,19 +91,19 @@ MiniRaft-CPP is an implementation of the Raft consensus algorithm using C++20. T
3791
git submodule init
3892
git submodule update
3993
```
40-
3. Navigate to the project directory:
94+
3. Navigate to the project directory:
4195
```
4296
cd miniraft-cpp
4397
```
44-
4. Build the project using CMake:
98+
4. Build the project using CMake:
4599
```
46100
cmake .
47101
make
48102
```
49103

50104
### Running the Application
51105

52-
This is a simple application designed to demonstrate log replication in the Raft consensus algorithm.
106+
This is a simple application designed to demonstrate log replication in the Raft consensus algorithm.
53107

54108
To start the application, launch the servers with the following commands:
55109
```
@@ -64,12 +118,11 @@ To interact with the system, run the client as follows:
64118
```
65119
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.
66120

121+
### Example: State Machine (RSM) with Key-Value Store
67122

68-
### Distributed Key-Value Store Example
123+
MiniRaft-CPP includes an example of a distributed Key-Value store implemented as a replicated state machine on top of Raft. The source code for this example resides in examples/kv.cpp
69124

70-
Additionally, there's an example implementing a distributed key-value (KV) store.
71-
72-
#### Starting KV Store Servers
125+
#### Server Mode
73126

74127
To start the KV store servers, use:
75128
```
@@ -78,7 +131,7 @@ To start the KV store servers, use:
78131
./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
79132
```
80133

81-
#### Running the KV Client
134+
#### Client Mode
82135

83136
To run the KV client, use:
84137
```
@@ -90,6 +143,8 @@ The KV client expects commands as input:
90143
3. `list` - Displays all key/value pairs in the store.
91144
4. `del <key>` - Deletes a key from the store.
92145

146+
---
147+
93148
## Media
94149
1. [Implementation of the Raft Consensus Algorithm Using C++20 Coroutines](https://dzone.com/articles/implementation-of-the-raft-consensus-algorithm-usi)
95150
2. [Разработка сетевой библиотеки на C++20: интеграция асинхронности и алгоритма Raft (часть 1)](https://www.linux.org.ru/articles/development/17447126)

0 commit comments

Comments
 (0)