Skip to content

Commit 0285144

Browse files
committed
Merge branch 'backup'
2 parents 6eacd16 + c926ba9 commit 0285144

24 files changed

+1087
-2
lines changed

.github/workflows/cmake-single-platform.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@v4
24+
with:
25+
submodules: 'recursive'
2426

2527
- name: Configure CMake
2628
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*.o
88
*.obj
99
build
10+
.cache
11+
output
1012

1113
# Precompiled Headers
1214
*.gch

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "third_party/abseil-cpp"]
55
path = third_party/abseil-cpp
66
url = [email protected]:abseil/abseil-cpp.git
7+
[submodule "third_party/tomlplusplus"]
8+
path = third_party/tomlplusplus
9+
url = [email protected]:marzer/tomlplusplus.git

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ cmake_minimum_required(VERSION 3.12)
22
project(raft-kv)
33

44
set(CMAKE_CXX_STANDARD 20)
5-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
7+
8+
add_subdirectory(third_party/abseil-cpp)
9+
get_property(targets DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
10+
message(STATUS "Avaiable CMake targets: ${targets}")
11+
add_subdirectory(third_party/spdlog)
12+
add_subdirectory(third_party/tomlplusplus)
13+
add_subdirectory(src)

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
# raft-kv
1+
# raft-kv
2+
3+
This project is just a learning project for Raft consensus algorithm and KV store. I do not want to implement all the details, so I just use lots of libraries to help me implement the project. The project is not production ready, but it can be used for learning and testing purposes.
4+
5+
## Usage
6+
### Use protobuf
7+
8+
```bash
9+
sudo pacman -S protobuf
10+
sudo pacman -S protobuf-c # cpp support
11+
protoc -cpp_out=. message.proto
12+
```
13+
14+
### Use cmake
15+
16+
```bash
17+
cmake -B build -G Ninja
18+
cmake --build build --parallel 16
19+
```

config/config.toml

Whitespace-only changes.

src/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
set(EXECUTABLE_NAME StorageNode)
2+
3+
4+
set(PRIVATE_INCLUDE_DIR
5+
${CMAKE_CURRENT_SOURCE_DIR}/db
6+
${CMAKE_CURRENT_SOURCE_DIR}/db/bitcask
7+
${CMAKE_CURRENT_SOURCE_DIR}/utils
8+
${CMAKE_CURRENT_SOURCE_DIR}/server
9+
${CMAKE_CURRENT_SOURCE_DIR}/server/proto
10+
)
11+
12+
set(SOURCE_FILES
13+
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/db/bitcask/bitcask.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/server/net.cpp
16+
${CMAKE_CURRENT_SOURCE_DIR}/proto/message.pb.cc
17+
)
18+
19+
20+
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
21+
22+
target_include_directories(
23+
${EXECUTABLE_NAME}
24+
PRIVATE
25+
${PRIVATE_INCLUDE_DIR}
26+
)
27+
28+
find_package(Protobuf REQUIRED)
29+
30+
target_link_libraries(
31+
${EXECUTABLE_NAME}
32+
PRIVATE
33+
spdlog::spdlog
34+
tomlplusplus::tomlplusplus
35+
protobuf::libprotobuf
36+
absl::log_internal_check_op # dependency for protobuf
37+
)
38+

src/db/bitcask/bitcask.cpp

Whitespace-only changes.

src/db/bitcask/bitcask.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
#include "db.h"
3+
namespace db {
4+
class Bitcask final : public DbEngine {
5+
public:
6+
private:
7+
};
8+
} // namespace db

src/db/db.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
#include <string>
3+
4+
#include "absl/status/status.h"
5+
6+
namespace db {
7+
8+
using absl::Status;
9+
10+
// define db engine interface for storage
11+
class DbEngine {
12+
public:
13+
using KeyType = std::string; // KeyType & Value Type must can be ser & deser
14+
using ValueType = std::string;
15+
DbEngine(DbEngine&&) = delete;
16+
DbEngine(DbEngine const&) = delete;
17+
DbEngine& operator=(DbEngine const&) = delete;
18+
DbEngine& operator=(DbEngine&&) = delete;
19+
virtual ~DbEngine() = default;
20+
21+
virtual Status Set(KeyType const& key, ValueType const& value) = 0;
22+
virtual Status Get(KeyType const& key, ValueType& value) = 0;
23+
virtual Status Delete(KeyType const& key) = 0;
24+
};
25+
26+
} // namespace db

0 commit comments

Comments
 (0)