-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Raft protocol to replicate KV pairs #10
base: master
Are you sure you want to change the base?
Changes from 15 commits
2051a9d
10396a7
b9b5995
614c2bc
2e6374a
e0a354b
2fa9fca
0832944
2b7359e
f53b501
497b88d
ee68090
f68e8d1
3372412
1b8b93b
ff8edca
7ca37a9
54f02c9
d803bec
9d5cd21
d63a8fe
0bab68f
ece39ad
0834c89
cb376b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,64 @@ | |||||||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||||||||||||
"version": "0.2.0", | ||||||||||||
"configurations": [ | ||||||||||||
{ | ||||||||||||
"name": "rr - RaftMain", | ||||||||||||
"type": "cppdbg", | ||||||||||||
"request": "launch", | ||||||||||||
"program": "${workspaceFolder}/build/RaftMain", | ||||||||||||
"miDebuggerServerAddress": "localhost:50505", | ||||||||||||
"stopAtEntry": false, | ||||||||||||
"cwd": "${workspaceFolder}", | ||||||||||||
"environment": [], | ||||||||||||
"externalConsole": true, | ||||||||||||
"linux": { | ||||||||||||
"MIMode": "gdb", | ||||||||||||
"setupCommands": [ | ||||||||||||
{ | ||||||||||||
"description": "Setup to resolve symbols", | ||||||||||||
"text": "set sysroot /", | ||||||||||||
"ignoreFailures": false | ||||||||||||
} | ||||||||||||
] | ||||||||||||
}, | ||||||||||||
"osx": { | ||||||||||||
"MIMode": "gdb" | ||||||||||||
}, | ||||||||||||
"windows": { | ||||||||||||
"MIMode": "gdb" | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
{ | ||||||||||||
"name": "Debug - RaftMain", | ||||||||||||
"type": "cppdbg", | ||||||||||||
"request": "attach", | ||||||||||||
"program": "${workspaceFolder}/build/RaftMain", // Path to the compiled executable | ||||||||||||
"processId": "${command:pickProcess}", | ||||||||||||
"MIMode": "gdb", // Use "lldb" if you're using clang on macOS | ||||||||||||
"setupCommands": [ | ||||||||||||
{ | ||||||||||||
"description": "Enable pretty-printing for gdb", | ||||||||||||
"text": "-enable-pretty-printing", | ||||||||||||
"ignoreFailures": true | ||||||||||||
} | ||||||||||||
], | ||||||||||||
"preLaunchTask": "build", // Ensure your program is built before launching | ||||||||||||
"miDebuggerPath": "/usr/bin/gdb", // Path to the gdb or lldb debugger | ||||||||||||
"logging": { | ||||||||||||
"trace": true, // Enable trace for debugging the launch.json config | ||||||||||||
"traceResponse": true, | ||||||||||||
"engineLogging": false | ||||||||||||
}, | ||||||||||||
"targetArchitecture": "x86_64", | ||||||||||||
"pipeTransport": { | ||||||||||||
"pipeCwd": "", | ||||||||||||
"pipeProgram": "/bin/bash", | ||||||||||||
"pipeArgs": [ | ||||||||||||
"-c" | ||||||||||||
], | ||||||||||||
"debuggerPath": "/usr/bin/gdb" | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix JSON syntax error Remove the trailing comma after the pipeTransport object. Apply this diff: ],
"debuggerPath": "/usr/bin/gdb"
- },
+ }
}, 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 64-64: Expected a property but instead found '}'. Expected a property here. (parse) |
||||||||||||
{ | ||||||||||||
"name": "Debug - LSMTreeTest", | ||||||||||||
"type": "cppdbg", | ||||||||||||
|
@@ -84,7 +142,7 @@ | |||||||||||
"args": [ | ||||||||||||
"-c", | ||||||||||||
"./assets/tkvpp_config.json" | ||||||||||||
], // Arguments to pass to the program | ||||||||||||
], | ||||||||||||
"stopAtEntry": false, // Set to true to stop at the program's entry point | ||||||||||||
"cwd": "${workspaceFolder}", // Current working directory | ||||||||||||
"environment": [], | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ project(zkv) | |
|
||
add_subdirectory(absl) | ||
add_subdirectory(embedded) | ||
add_subdirectory(raft) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
project(zkv) | ||
|
||
add_executable(RaftMain "main.cpp" "raft.cpp") | ||
set_target_properties(RaftMain PROPERTIES CXX_STANDARD 23) | ||
target_link_libraries(RaftMain PRIVATE DB RaftProtoObjects TKVProtoObjects) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <random> | ||
|
||
#include "raft.h" | ||
|
||
#include <grpcpp/server.h> | ||
|
||
#include <cxxopts.hpp> | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
auto generateRandomTimeout() -> int | ||
{ | ||
const int minTimeout{150}; | ||
const int maxTimeout{300}; | ||
|
||
std::random_device randomDevice; | ||
std::mt19937 gen(randomDevice()); | ||
std::uniform_int_distribution<> dist(minTimeout, maxTimeout); | ||
|
||
return dist(gen); | ||
} | ||
|
||
auto main(int argc, char *argv[]) -> int | ||
{ | ||
cxxopts::Options options("raft"); | ||
options.add_options()("id", "id of the node", cxxopts::value<ID>())( | ||
"nodes", "ip addresses of replicas in a correct order", cxxopts::value<std::vector<IP>>()); | ||
|
||
auto parsedOptions = options.parse(argc, argv); | ||
if ((parsedOptions.count("help") != 0U) || (parsedOptions.count("id") == 0U) || | ||
(parsedOptions.count("nodes") == 0U)) | ||
{ | ||
spdlog::info("{}", options.help()); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
auto nodeId = parsedOptions["id"].as<ID>(); | ||
auto nodeIps = parsedOptions["nodes"].as<std::vector<IP>>(); | ||
for (auto ip : nodeIps) | ||
{ | ||
spdlog::info(ip); | ||
} | ||
|
||
spdlog::info("nodeIps.size()={}", nodeIps.size()); | ||
|
||
if (nodeId == 0) | ||
{ | ||
spdlog::error("ID of the node should be positve integer"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (nodeIps.empty()) | ||
{ | ||
spdlog::error("List of node IPs can't be empty"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ConsensusModule cm(nodeId, nodeIps); | ||
if (!cm.init()) | ||
{ | ||
spdlog::error("Failed to initialize the state machine"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
cm.start(); | ||
|
||
/*cm.stop();*/ | ||
|
||
return EXIT_SUCCESS; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance RaftMain debug configuration for multi-node debugging.
The configuration needs improvements for debugging multiple Raft nodes:
Apply this diff:
Add to the end of the file: