Skip to content

Commit

Permalink
ad ci build flow
Browse files Browse the repository at this point in the history
  • Loading branch information
LLiuJJ committed Aug 11, 2024
1 parent 895f25a commit 5b05c7b
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 49 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on: [push, pull_request]

jobs:
test-ubuntu:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install gcc-10 and g++-10
run: |
sudo apt install -y gcc-10 g++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 20
- name: Install build dependencies
run: sudo apt-get update && sudo apt-get install -y clang-format build-essential autoconf automake libtool lcov libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev
- name: Install RocksDB
run: sudo apt-get update && sudo apt-get install librocksdb-dev
- name: Install latest version cmake
run: |
sudo wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.sh -q -O /tmp/cmake-install.sh && sudo chmod u+x /tmp/cmake-install.sh
sudo mkdir /opt/cmake-3.26.3 && sudo /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.26.3
sudo rm /tmp/cmake-install.sh && sudo ln -sf /opt/cmake-3.26.3/bin/* /usr/local/bin
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- name: Install grpc
run: sudo git clone https://github.com/grpc/grpc.git && cd grpc && sudo git checkout v1.28.0 && sudo git submodule update --init && sudo mkdir .build && cd .build && sudo cmake .. -DgRPC_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && sudo make install -j4 && cd .. && sudo rm -rf .build/CMakeCache.txt && cd .build && sudo cmake .. -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release && sudo make install -j4
- name: Install Google benchmark
run: sudo git clone https://github.com/google/benchmark.git && sudo git clone https://github.com/google/googletest.git benchmark/googletest && cd benchmark && sudo cmake -E make_directory "build" && sudo cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../ && sudo cmake --build "build" --config Release --target install
- name: Build
run: |
mkdir build && cd build
cmake ..
make -j4
17 changes: 8 additions & 9 deletions raftcore/include/eraft/kv_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ class Storage {
*/
virtual std::pair<std::string, bool> GetKV(std::string key) = 0;

/**
* @brief
*
* @param key
* @return EStatus
*/
virtual EStatus DelKV(std::string key) = 0;

/**
* @brief
*
Expand Down Expand Up @@ -145,15 +153,6 @@ class Storage {
virtual EStatus ProductSST(std::string snap_base_path,
std::string sst_file_path) = 0;

/**
* @brief
*
* @param key
* @return EStatus
*/
virtual EStatus DelKV(std::string key) = 0;


/**
* @brief Create a Checkpoint
*
Expand Down
19 changes: 19 additions & 0 deletions raftcore/include/eraft/log_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class LogStore {
*/
virtual ~LogStore() {}

/**
* @brief
*
* @return EStatus
*/
virtual EStatus Reinit() = 0;

/**
Expand Down Expand Up @@ -146,8 +151,22 @@ class LogStore {
*/
virtual eraftkv::Entry* GetLastEty() = 0;

/**
* @brief
*
* @param commit_idx
* @param applied_idx
* @return EStatus
*/
virtual EStatus PersisLogMetaState(int64_t commit_idx,
int64_t applied_idx) = 0;

/**
* @brief
*
* @param commit_idx
* @param applied_idx
* @return EStatus
*/
virtual EStatus ReadMetaState(int64_t* commit_idx, int64_t* applied_idx) = 0;
};
32 changes: 0 additions & 32 deletions raftcore/include/eraft/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,3 @@ class Network {
virtual EStatus InsertPeerNodeConnection(int64_t peer_id,
std::string addr) = 0;
};

/**
* @brief
*
*/
class Event {
public:
/**
* @brief Destroy the Event object
*
*/
virtual ~Event() {}

/**
* @brief
*
* @param raft
* @param state
*/
virtual void RaftStateChangeEvent(RaftServer* raft, int state) = 0;

/**
* @brief
*
* @param raft
* @param node
* @param ety
*/
virtual void RaftGroupMembershipChangeEvent(RaftServer* raft,
RaftNode* node,
eraftkv::Entry* ety) = 0;
};
1 change: 1 addition & 0 deletions raftcore/include/eraft/raft_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "eraft/log_storage.h"
#include "eraft/network.h"
#include "eraft/raft_node.h"

/**
* @brief
*
Expand Down
122 changes: 117 additions & 5 deletions raftcore/include/eraft/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,65 +44,154 @@
#include <vector>

namespace fs = std::filesystem;

/**
* @brief
*
*/
class DirectoryTool {
public:
static bool IsDir(const std::string dirpath);
static bool MkDir(const std::string dirpath);
static int StaticDirSize(const std::string dirpath);
/**
* @brief
*
* @param dirpath
* @return true
* @return false
*/
static bool IsDir(const std::string dirpath);
/**
* @brief
*
* @param dirpath
* @return true
* @return false
*/
static bool MkDir(const std::string dirpath);
/**
* @brief
*
* @param dirpath
* @return int
*/
static int StaticDirSize(const std::string dirpath);
/**
* @brief
*
* @param dirpath
* @return std::vector<std::string>
*/
static std::vector<std::string> ListDirFiles(const std::string dirpath);
static void DeleteDir(const std::string dirpath);
/**
* @brief
*
* @param dirpath
*/
static void DeleteDir(const std::string dirpath);
DirectoryTool();
~DirectoryTool();
};


class EncodeDecodeTool {
public:
/**
* @brief
*
* @param dst
* @param value
*/
static void EncodeFixed64(char* dst, uint64_t value) {
uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
std::memcpy(buffer, &value, sizeof(uint64_t));
}

/**
* @brief
*
* @param dst
* @param value
*/
static void PutFixed64(std::string* dst, uint64_t value) {
char buf[sizeof(value)];
EncodeFixed64(buf, value);
dst->append(buf, sizeof(buf));
}

/**
* @brief
*
* @param buffer
* @return uint64_t
*/
static uint64_t DecodeFixed64(const uint8_t* buffer) {
uint64_t result;
std::memcpy(&result, buffer, sizeof(uint64_t));
return result;
}

/**
* @brief
*
* @param dst
* @param value
*/
static void EncodeFixed16(char* dst, uint16_t value) {
uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
std::memcpy(buffer, &value, sizeof(uint16_t));
}

/**
* @brief
*
* @param dst
* @param value
*/
static void PutFixed16(std::string* dst, uint16_t value) {
char buf[sizeof(value)];
EncodeFixed16(buf, value);
dst->append(buf, sizeof(buf));
}

/**
* @brief
*
* @param buffer
* @return uint16_t
*/
static uint16_t DecodeFixed16(const uint8_t* buffer) {
uint16_t result;
std::memcpy(&result, buffer, sizeof(uint16_t));
return result;
}

/**
* @brief
*
* @param dst
* @param value
*/
static void EncodeFixed32(char* dst, uint32_t value) {
uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst);
std::memcpy(buffer, &value, sizeof(uint32_t));
}

/**
* @brief
*
* @param dst
* @param value
*/
static void PutFixed32(std::string* dst, uint32_t value) {
char buf[sizeof(value)];
EncodeFixed32(buf, value);
dst->append(buf, sizeof(buf));
}

/**
* @brief
*
* @param buffer
* @return uint32_t
*/
static uint32_t DecodeFixed32(const uint8_t* buffer) {
uint32_t result;
std::memcpy(&result, buffer, sizeof(uint32_t));
Expand Down Expand Up @@ -167,11 +256,26 @@ class StringUtil {
return tmp_s;
}

/**
* @brief
*
* @param str
* @param suffix
* @return true
* @return false
*/
static bool endsWith(const std::string& str, const std::string& suffix) {
return str.size() >= suffix.size() &&
0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
}

/**
* @brief
*
* @param str
* @param delim
* @return std::vector<std::string>
*/
static std::vector<std::string> Split(const std::string& str, char delim) {
std::stringstream ss(str);
std::string item;
Expand All @@ -187,5 +291,13 @@ class StringUtil {

class HashUtil {
public:
/**
* @brief
*
* @param crc
* @param s
* @param l
* @return uint64_t
*/
static uint64_t CRC64(uint64_t crc, const char* s, uint64_t l);
};
Loading

0 comments on commit 5b05c7b

Please sign in to comment.