diff --git a/.github/workflows/import_braft.yml b/.github/workflows/import_braft.yml new file mode 100644 index 000000000..c0c01f3fe --- /dev/null +++ b/.github/workflows/import_braft.yml @@ -0,0 +1,58 @@ +name: Import BRaft Actions (Temporary) + +on: + push: + pull_request: + branches: [ "import-braft" ] + +jobs: + check_format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build + run: bash ci/build.sh + + - name: Check Format + working-directory: ${{ github.workspace }}/build + run: make check-format + + build_on_macos: + runs-on: macos-latest + needs: check_format + + steps: + - uses: actions/checkout@v4 + + - name: Build + env: + CPLUS_INCLUDE_PATH: /usr/local/opt/openssl/include + run: | + sh build.sh + + - name: Run Go E2E Tests + working-directory: ${{ github.workspace }}/build + run: | + cd ../tests + go mod tidy + go test ./pikiwidb_suite_test.go ./consistency_test.go -v + + build_on_ubuntu: + runs-on: ubuntu-latest + needs: check_format + + steps: + - uses: actions/checkout@v4 + + - name: Build + run: | + bash build.sh + + - name: Run Go E2E Tests + working-directory: ${{ github.workspace }}/build + run: | + cd ../tests + go mod tidy + go test ./pikiwidb_suite_test.go ./consistency_test.go -v diff --git a/cmake/braft.cmake b/cmake/braft.cmake index 87aff68a1..43ea4a350 100644 --- a/cmake/braft.cmake +++ b/cmake/braft.cmake @@ -16,8 +16,8 @@ ExternalProject_Add( extern_braft ${EXTERNAL_PROJECT_LOG_ARGS} DEPENDS brpc - URL "https://github.com/baidu/braft/archive/v1.1.2.tar.gz" - URL_HASH SHA256=bb3705f61874f8488e616ae38464efdec1a20610ddd6cd82468adc814488f14e + URL "https://github.com/pikiwidb/braft/archive/refs/heads/stable.zip" + URL_HASH SHA256=e73831f9768ac57d07f01ed81a11c8368e259c25315a960c29a6422f31f42fd1 PREFIX ${BRAFT_SOURCES_DIR} UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} diff --git a/src/cmd_admin.cc b/src/cmd_admin.cc index adc463a94..b43575f60 100644 --- a/src/cmd_admin.cc +++ b/src/cmd_admin.cc @@ -6,9 +6,8 @@ */ #include "cmd_admin.h" -#include "store.h" -#include "braft/raft.h" -#include "praft.h" + +#include "praft/praft.h" namespace pikiwidb { @@ -80,7 +79,7 @@ void SelectCmd::DoCmd(PClient* client) { client->SetRes(CmdRes::kOK); } -InfoCmd::InfoCmd(const std::string& name, int16_t arity) +InfoCmd::InfoCmd(const std::string& name, int16_t arity) : BaseCmd(name, arity, kCmdFlagsAdmin | kCmdFlagsReadonly, kAclCategoryAdmin) {} bool InfoCmd::DoInitial(PClient* client) { return true; } @@ -127,7 +126,7 @@ void InfoCmd::DoCmd(PClient* client) { message += "raft_state:up\r\n"; } else { message += "raft_state:down\r\n"; - } + } message += "raft_role:" + std::string(braft::state2str(node_status.state)) + "\r\n"; // message += "raft_is_voting:" + node_status.is_voting + "\r\n"; message += "raft_leader_id:" + node_status.leader_id.to_string() + "\r\n"; @@ -141,9 +140,10 @@ void InfoCmd::DoCmd(PClient* client) { if (!status.ok()) { return client->SetRes(CmdRes::kErrOther, status.error_str()); } - + for (int i = 0; i < peers.size(); i++) { - message += "raft_node" + std::to_string(i) + ":addr=" + butil::ip2str(peers[i].addr.ip).c_str() + ",port=" + std::to_string(peers[i].addr.port) + "\r\n"; + message += "raft_node" + std::to_string(i) + ":addr=" + butil::ip2str(peers[i].addr.ip).c_str() + + ",port=" + std::to_string(peers[i].addr.port) + "\r\n"; } } @@ -153,4 +153,4 @@ void InfoCmd::DoCmd(PClient* client) { } } -} // namespace pikiwidb \ No newline at end of file +} // namespace pikiwidb diff --git a/src/cmd_admin.h b/src/cmd_admin.h index 476660e01..8ef4d6e58 100644 --- a/src/cmd_admin.h +++ b/src/cmd_admin.h @@ -85,14 +85,14 @@ class SelectCmd : public BaseCmd { }; class InfoCmd : public BaseCmd { - public: - InfoCmd(const std::string& name, int16_t arity); + public: + InfoCmd(const std::string& name, int16_t arity); - protected: - bool DoInitial(PClient* client) override; + protected: + bool DoInitial(PClient* client) override; - private: - void DoCmd(PClient* client) override; + private: + void DoCmd(PClient* client) override; }; } // namespace pikiwidb diff --git a/src/cmd_raft.h b/src/cmd_raft.h index a5e8f924d..534c90576 100644 --- a/src/cmd_raft.h +++ b/src/cmd_raft.h @@ -25,7 +25,7 @@ namespace pikiwidb { * : * : * - * RAFT.NODE REMOVE [id] + * RAFT.NODE REMOVE [id] * Remove an existing node from the cluster. * Reply: * -NOCLUSTER || diff --git a/src/cmd_table_manager.cc b/src/cmd_table_manager.cc index 2ae39a0a2..edc375596 100644 --- a/src/cmd_table_manager.cc +++ b/src/cmd_table_manager.cc @@ -5,16 +5,15 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#include +#include "cmd_table_manager.h" #include "cmd_admin.h" #include "cmd_hash.h" #include "cmd_keys.h" #include "cmd_kv.h" #include "cmd_list.h" -#include "cmd_set.h" #include "cmd_raft.h" -#include "cmd_table_manager.h" +#include "cmd_set.h" #include "cmd_zset.h" namespace pikiwidb { @@ -46,7 +45,7 @@ void CmdTableManager::InitCmdTable() { // info ADD_COMMAND(Info, -1); - + // raft ADD_COMMAND(RaftCluster, -1); ADD_COMMAND(RaftNode, -2); diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc index be89bf02a..0b6558182 100644 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -15,8 +15,8 @@ #include #include "praft/praft.h" -#include "pstd/pstd_util.h" #include "pstd/log.h" +#include "pstd/pstd_util.h" #include "client.h" #include "config.h" diff --git a/src/storage/src/log_index.h b/src/storage/src/log_index.h index 44d486338..a2bfc9d40 100644 --- a/src/storage/src/log_index.h +++ b/src/storage/src/log_index.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include