Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on May 14, 2020. It is now read-only.
/raftPublic archive

⛵ Raft Consensus Algorithm. gRPC for communication. Tested with a few cases.

License

NotificationsYou must be signed in to change notification settings

iskyzh/raft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Raft Consensus Algorithm implemented in C++. Refer tohttps://raft.github.io/ for original paper.

Usage

  1. Use vcpkg or other tools to install build dependencies (boost, gtest, grpc, protobuf, cpptoml).Use pip to install test dependencies.
apt install libboost-all-devvcpkg install gtest grpc protobuf cpptomlpip3 install -r tests/requirements.txt
  1. Generate protobuf header
export VCPKG_ROOT="$HOME/vcpkg"export VCPKG_DEFAULT_TRIPLET="x64-osx"cd protos&& ./generate.sh
  1. Build and run unit tests
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmakecd build&& cmake --build../RaftTestexport RAFT_EXECUTABLE=$(pwd)/RaftService
  1. Use python to run system tests
pytest tests/

On macOS, there'll be some problems with launching subprocess in Python. Testing scriptwill retry launching until server is reachable.

Design

Some changes were made on Raft RPC described in original paper. Thisimplementation uses gRPC for node communication, but I make requestand reply into 2 separate RPCs. Therefore it's not possible to corresponda response to a request. ForAppendEntries RPC, prevLogTerm in requestshould be known when sending AppendEntries reply. Therefore alastAgreedLogIndex field was added. For other reply RPCs, sender field is added.

Personally I would like to break down Raft protocol to many smallparts as it is more convenient to test.

core/ contains core Raft algorithm. The core algorithm (Instance.cpp) containsonly 200+ lines of code.

rpc/ contains one RPC implementation with gRPC. Here I choose single-thread asynchronizedimplementation. All RPCs requests are pushed into a lock-free queue, and then are processedin the event-loop thread. This choice leads to the split of RPC request and response messagedescribed above. Therefore, thread lock usage is eliminated.

Insrc/,mock_main.cpp can be used to mock a Raft cluster with 'events',which means that there're no RPC requests and all RPC are simulated withevents and callbacks. You may adjustdrop_rate anddelay to mock anunstable network. You may add events to simulate events in network.Currently the mock main will kick off leader and restore it to test log consistency.It will generateRaftMockMain executable.

grpc_main.cpp uses gRPC for communication between clients. It also helps setup a Raft cluster. It will generateRaftMockRPC executable.

service_main.cpp is a real Raft client with server control for system testing.It corresponds toRaftService executable.

System tests intests/ are written in Python. It will automatically run Raft serviceexecutable, build a 5-node cluster and test it with different conditions.

Todo

  • Async log read and write

About

⛵ Raft Consensus Algorithm. gRPC for communication. Tested with a few cases.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp