Giter Club home page Giter Club logo

miniraft-cpp's Introduction

MiniRaft-CPP

Number of GitHub stars GitHub commit activity GitHub license which is BSD-2-Clause license

Overview

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.

Key Features

  • 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.

Components

  • 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.

Getting Started

Prerequisites

  • C++20 compatible compiler
  • CMake for building the project
  • Cmocka for unit testing

Building the Project

  1. Clone the repository:
    git clone https://github.com/resetius/miniraft-cpp
    
  2. Initialize and update the submodule:
    git submodule init
    git submodule update
    
  3. Navigate to the project directory:
    cd miniraft-cpp
    
  4. Build the project using CMake:
    cmake .
    make
    

Running the Application

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.

Distributed Key-Value Store Example

Additionally, there's an example implementing a distributed key-value (KV) store.

Starting KV Store Servers

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

Running the KV Client

To run the KV client, use:

./kv --client --node 127.0.0.1:8001:1

The KV client expects commands as input:

  1. set <key> <value> - Adds or updates a value in the KV store.
  2. get <key> - Retrieves a value by its key.
  3. list - Displays all key/value pairs in the store.
  4. del <key> - Deletes a key from the store.

Media

  1. Implementation of the Raft Consensus Algorithm Using C++20 Coroutines
  2. Разработка сетевой библиотеки на C++20: интеграция асинхронности и алгоритма Raft (часть 1)
  3. Разработка сетевой библиотеки на C++20: интеграция асинхронности и алгоритма Raft (часть 2)
  4. High-performance network library using C++20 coroutines
  5. Simplifying Raft with C++20 coroutines

miniraft-cpp's People

Contributors

resetius avatar saad-hussain31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

miniraft-cpp's Issues

Support disk storage

Add storage abstraction in order to support different log storages (in-memory, disk, etc)

Error while compiling.

Hello, thank you for your work on raft. I'm currently facing some issues while compiling. Can you help me?

zhousy26@zhousy26-virtual-machine:~/Desktop/testc/miniraft-cpp$ make
Consolidate compiler generated dependencies of target coroio
[ 2%] Building CXX object coroio/CMakeFiles/coroio.dir/coroio/uring.cpp.o
[ 5%] Building CXX object coroio/CMakeFiles/coroio.dir/coroio/resolver.cpp.o
[ 7%] Linking CXX static library libcoroio.a
[ 25%] Built target coroio
Consolidate compiler generated dependencies of target miniraft
[ 27%] Building CXX object CMakeFiles/miniraft.dir/src/server.cpp.o
[ 30%] Linking CXX static library libminiraft.a
[ 35%] Built target miniraft
Consolidate compiler generated dependencies of target test_raft
[ 37%] Building CXX object CMakeFiles/test_raft.dir/test/test_raft.cpp.o
[ 40%] Linking CXX executable test_raft
[ 40%] Built target test_raft
Consolidate compiler generated dependencies of target test_read_write
[ 42%] Building CXX object CMakeFiles/test_read_write.dir/test/test_read_write.cpp.o
[ 45%] Linking CXX executable test_read_write
/usr/bin/ld: coroio/libcoroio.a(uring.cpp.o): in function NNet::TUring::TUring(int)': uring.cpp:(.text+0x459): undefined reference to io_uring_queue_init'
/usr/bin/ld: coroio/libcoroio.a(uring.cpp.o): in function NNet::TUring::~TUring()': uring.cpp:(.text+0x758): undefined reference to io_uring_queue_exit'
/usr/bin/ld: coroio/libcoroio.a(uring.cpp.o): in function NNet::TUring::Wait(timespec)': uring.cpp:(.text+0xb92): undefined reference to io_uring_wait_cqe_timeout'
/usr/bin/ld: coroio/libcoroio.a(uring.cpp.o): in function NNet::TUring::Submit()': uring.cpp:(.text+0xde9): undefined reference to io_uring_submit'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test_read_write.dir/build.make:99: test_read_write] Error 1
make[1]: *** [CMakeFiles/Makefile2:180: CMakeFiles/test_read_write.dir/all] Error 2
make: *** [Makefile:101: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.