{"id":13607024,"url":"https://github.com/iskyzh/raft","last_synced_at":"2025-04-12T11:31:13.717Z","repository":{"id":85472253,"uuid":"195269864","full_name":"iskyzh/raft","owner":"iskyzh","description":"⛵ Raft Consensus Algorithm. gRPC for communication. Tested with a few cases.","archived":true,"fork":false,"pushed_at":"2019-08-08T03:23:46.000Z","size":197,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-07T12:42:25.395Z","etag":null,"topics":["boost","cmake","cpp","grpc","gtest","protobuf","raft"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iskyzh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-04T16:01:28.000Z","updated_at":"2024-09-18T05:24:01.000Z","dependencies_parsed_at":"2023-04-04T00:33:19.895Z","dependency_job_id":null,"html_url":"https://github.com/iskyzh/raft","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iskyzh%2Fraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iskyzh%2Fraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iskyzh%2Fraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iskyzh%2Fraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iskyzh","download_url":"https://codeload.github.com/iskyzh/raft/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560078,"owners_count":21124590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boost","cmake","cpp","grpc","gtest","protobuf","raft"],"created_at":"2024-08-01T19:01:14.851Z","updated_at":"2025-04-12T11:31:12.762Z","avatar_url":"https://github.com/iskyzh.png","language":"C++","readme":"# Raft\n\n[![Build Status](https://travis-ci.com/skyzh/raft.svg?branch=master)](https://travis-ci.com/skyzh/raft)\n\nRaft Consensus Algorithm implemented in C++. Refer to [https://raft.github.io/](https://raft.github.io/) for original paper.\n\n## Usage\n\n1. Use vcpkg or other tools to install build dependencies (boost, gtest, grpc, protobuf, cpptoml).\nUse pip to install test dependencies.\n```bash\napt install libboost-all-dev\nvcpkg install gtest grpc protobuf cpptoml\npip3 install -r tests/requirements.txt\n```\n2. Generate protobuf header\n```bash\nexport VCPKG_ROOT=\"$HOME/vcpkg\"\nexport VCPKG_DEFAULT_TRIPLET=\"x64-osx\"\ncd protos \u0026\u0026 ./generate.sh\n```\n3. Build and run unit tests\n```bash\ncmake -H. -Bbuild -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake\ncd build \u0026\u0026 cmake --build .\n./RaftTest\nexport RAFT_EXECUTABLE=$(pwd)/RaftService\n```\n4. Use python to run system tests\n```bash\npytest tests/\n```\n\nOn macOS, there'll be some problems with launching subprocess in Python. Testing script\nwill retry launching until server is reachable.\n\n## Design\n\nSome changes were made on Raft RPC described in original paper. This\nimplementation uses gRPC for node communication, but I make request \nand reply into 2 separate RPCs. Therefore it's not possible to correspond\na response to a request. For `AppendEntries` RPC, prevLogTerm in request\nshould be known when sending AppendEntries reply. Therefore a \n`lastAgreedLogIndex` field was added. For other reply RPCs, sender field is added.\n\nPersonally I would like to break down Raft protocol to many small \nparts as it is more convenient to test.\n\n`core/` contains core Raft algorithm. The core algorithm (`Instance.cpp`) contains\nonly 200+ lines of code.\n\n`rpc/` contains one RPC implementation with gRPC. Here I choose single-thread asynchronized\nimplementation. All RPCs requests are pushed into a lock-free queue, and then are processed\nin the event-loop thread. This choice leads to the split of RPC request and response message\ndescribed above. Therefore, thread lock usage is eliminated.\n\nIn `src/`, `mock_main.cpp` can be used to mock a Raft cluster with 'events',\nwhich means that there're no RPC requests and all RPC are simulated with\nevents and callbacks. You may adjust `drop_rate` and `delay` to mock an \nunstable network. You may add events to simulate events in network. \nCurrently the mock main will kick off leader and restore it to test log consistency. \nIt will generate `RaftMockMain` executable.\n\n`grpc_main.cpp` uses gRPC for communication between clients. It also helps set\nup a Raft cluster. It will generate `RaftMockRPC` executable.\n\n`service_main.cpp` is a real Raft client with server control for system testing. \nIt corresponds to `RaftService` executable.\n\nSystem tests in `tests/` are written in Python. It will automatically run Raft service\nexecutable, build a 5-node cluster and test it with different conditions.\n\n# Todo\n\n- [ ] Async log read and write\n","funding_links":[],"categories":["资源清单"],"sub_categories":["CS1956 (原 MS125) - 编程综合实践 (荣誉)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiskyzh%2Fraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiskyzh%2Fraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiskyzh%2Fraft/lists"}