Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2051a9d
Raft leader election in progress
lnikon Dec 24, 2024
10396a7
Implement leader election
lnikon Dec 28, 2024
b9b5995
Refactor timer thread
lnikon Dec 28, 2024
614c2bc
A little refactoring
lnikon Dec 29, 2024
2e6374a
Refactor into separate headers & fix bugs
lnikon Dec 29, 2024
e0a354b
Implement coderabbit reviews #1
lnikon Dec 30, 2024
2fa9fca
Fix PR reviews & bugs #2
lnikon Dec 31, 2024
0832944
Fix PR reviews #3
lnikon Dec 31, 2024
2b7359e
Refactor election thread & implement log replication
lnikon Jan 2, 2025
f53b501
Fix state machine modification during log replication
lnikon Jan 3, 2025
497b88d
Implement persistence
lnikon Jan 7, 2025
ee68090
Fix docker image build errors & Implement CR suggestions
lnikon Jan 9, 2025
f68e8d1
Implement CR suggestions
lnikon Jan 9, 2025
3372412
Implement CR suggestions
lnikon Jan 9, 2025
1b8b93b
BestPractice improvement
lnikon Jan 9, 2025
ff8edca
Check fstream failures when persisting raft's state & code style changes
lnikon Jan 11, 2025
7ca37a9
Support dependency injection for raft classes & prepare for mock testing
lnikon Jan 12, 2025
54f02c9
Graceful shutdown in progress
lnikon Jan 14, 2025
d803bec
Bug fixes
lnikon Jan 15, 2025
9d5cd21
Remove unused headers
lnikon Jan 15, 2025
d63a8fe
Graceful shutdown in progress
lnikon Jan 18, 2025
0bab68f
Implement graceful shutdown
lnikon Jan 22, 2025
ece39ad
Add unit test for leader election
lnikon Jan 22, 2025
0834c89
Fix unsynced access to heartbeat atomic
lnikon Jan 23, 2025
cb376b9
Add new unit test
lnikon Jan 25, 2025
68b3dc5
Add prometheus-cpp client & basic example
lnikon Jan 26, 2025
2bf300c
Refactor shutdown logic & integrate raft::consensus_module_t with db_…
lnikon Feb 1, 2025
0399a43
Fix multiple RaftLib dependencies & better shutdown via atomic bool
lnikon Feb 5, 2025
89e0afb
Fix error messages during config parsing
lnikon Feb 5, 2025
95b8026
Handle return value std::signal
lnikon Feb 5, 2025
11f20af
Make id and peers mandatory
lnikon Feb 5, 2025
cd86702
Better rnd generation
lnikon Feb 5, 2025
38f581e
Refactor election thread
lnikon Feb 5, 2025
411b21b
Add KV service into main gRPC server
lnikon Feb 6, 2025
a49c478
Rework of WAL in-progress
lnikon Mar 2, 2025
7d94f83
WAL refactoring & impl persistent log storage
lnikon Mar 19, 2025
8d5456c
Make append_only_file_t move-only
lnikon Mar 20, 2025
868d7f4
Add wal/log files
lnikon Mar 22, 2025
859bbb9
Add .gitignore
lnikon Mar 22, 2025
1809806
Code cleanup
lnikon Mar 28, 2025
b3b9173
"Re-implement fs::append_only_file_t with monadic interface & io_uring"
lnikon Mar 30, 2025
74e2b41
Move election thread into separate method
lnikon Apr 5, 2025
90acbea
Use sendAppendEntriesRPC instead to send heartbeats
lnikon Apr 5, 2025
88446f4
Use separate method to cleanup election & run heartbeat
lnikon Apr 5, 2025
0eb35f7
Rearrange consensus module methods
lnikon Apr 6, 2025
f7f23db
Add nextIndex handling into sendAppendEntriesRPC & reduce its complexity
lnikon Apr 6, 2025
f8f8194
Update clang-format & clang-tidy configs
lnikon Apr 7, 2025
6c344eb
Integrating WAL with consesus module
lnikon Apr 20, 2025
8677d89
Reformat all files
lnikon Apr 20, 2025
beadef1
Reformat .json files
lnikon Apr 20, 2025
3aabcd1
Test reformat commit hook
lnikon Apr 20, 2025
a46add0
Test reformat commit hook
lnikon Apr 20, 2025
0168836
Test reformat commit hook
lnikon Apr 20, 2025
f11e4df
Test reformat commit hook
lnikon Apr 20, 2025
50df1b1
Implement move ctors & general refactoring
lnikon Apr 28, 2025
720ee8c
Fix CodeRabbit reviews
lnikon Apr 29, 2025
7b9c4a0
Implement Raft protocol to replicate KV pairs:
lnikon May 1, 2025
14de60c
Initial implementation of follower node integration with the db_t::pu…
lnikon Jun 21, 2025
d02c889
Integrate follower node with db_t::put()
lnikon Jun 22, 2025
42842fc
General refactoring. Fixes for several potential deadlocks.
lnikon Jul 1, 2025
93f9e63
Implement Raft protocol to replicate KV pairs:
lnikon Jul 23, 2025
896e33d
Implement Raft protocol to replicate KV pairs:
lnikon Jul 24, 2025
bd4ec4a
Add CODE_STYLE.md
lnikon Jul 25, 2025
c7dd269
Add infra
lnikon Jul 25, 2025
8656053
Implement Raft protocol to replicate KV pairs:
lnikon Aug 4, 2025
e8a7bf3
Implement Raft protocol to replicate KV pairs:
lnikon Aug 7, 2025
cb2f23e
Implement Raft protocol to replicate KV pairs:
lnikon Aug 8, 2025
dd6d247
Implement Raft protocol to replicate KV pairs:
lnikon Aug 9, 2025
2950058
Implement Raft protocol to replicate KV pairs:
lnikon Aug 10, 2025
188828c
Implement Raft protocol to replicate KV pairs:
lnikon Aug 18, 2025
875cb6f
Implement Raft protocol to replicate KV pairs:
lnikon Aug 18, 2025
c25b0a1
Implement Raft protocol to replicate KV pairs:
lnikon Aug 21, 2025
fcd2b97
Merge branch 'feature/raft-in-progress' into feature/raft
lnikon Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@
// 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 - LSMTreeTest",
"type": "cppdbg",
Expand Down Expand Up @@ -84,7 +111,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": [],
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic-errors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wthread-safety -pedantic-errors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wthread-safety -pedantic-errors")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ project(zkv)

add_subdirectory(absl)
add_subdirectory(embedded)
add_subdirectory(raft)
6 changes: 6 additions & 0 deletions examples/raft/CMakeLists.txt
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)
70 changes: 70 additions & 0 deletions examples/raft/main.cpp
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);
}

int main(int argc, char *argv[])
{
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;
}
Loading