diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..e7c2f337 --- /dev/null +++ b/.clang-format @@ -0,0 +1,22 @@ +--- +Language: Cpp +UseTab: Never +IndentWidth: 4 +AccessModifierOffset: -4 +TabWidth: 4 +ColumnLimit: 90 +BreakConstructorInitializersBeforeComma: true +BreakBeforeTernaryOperators: true +BreakBeforeBinaryOperators: NonAssignment +PointerAlignment: Left +AllowShortIfStatementsOnASingleLine: true +AllowShortFunctionsOnASingleLine: true +SpaceBeforeRangeBasedForLoopColon: false +BinPackArguments: false +BinPackParameters: false +AlwaysBreakBeforeMultilineStrings: false +AlignEscapedNewlines: Left +#IndentPPDirectives: BeforeHash +AllowShortLambdasOnASingleLine: Inline +AlignAfterOpenBracket: true +AlignOperands: true diff --git a/include/libnuraft/raft_params.hxx b/include/libnuraft/raft_params.hxx index 59b5e654..2fd80328 100644 --- a/include/libnuraft/raft_params.hxx +++ b/include/libnuraft/raft_params.hxx @@ -505,6 +505,7 @@ public: /** * Wait ms for response after forwarding request to leader. * must be larger than client_req_timeout_. + * If 0, there will be no timeout for auto forwarding. */ int32 auto_forwarding_req_timeout_; }; diff --git a/include/libnuraft/rpc_cli.hxx b/include/libnuraft/rpc_cli.hxx index 524fe9bf..458e9931 100644 --- a/include/libnuraft/rpc_cli.hxx +++ b/include/libnuraft/rpc_cli.hxx @@ -40,7 +40,9 @@ class rpc_client { __interface_body__(rpc_client); public: - virtual void send(ptr& req, rpc_handler& when_done, uint64_t send_timeout_ms = 0) = 0; + virtual void send(ptr& req, + rpc_handler& when_done, + uint64_t send_timeout_ms = 0) = 0; virtual uint64_t get_id() const = 0; diff --git a/src/asio_service.cxx b/src/asio_service.cxx index fc9a26fd..6c4cbb7f 100644 --- a/src/asio_service.cxx +++ b/src/asio_service.cxx @@ -915,7 +915,10 @@ class asio_rpc_client send(req, when_done, send_timeout_ms); } - virtual void send(ptr& req, rpc_handler& when_done, uint64_t send_timeout_ms = 0) __override__ { + virtual void send(ptr& req, + rpc_handler& when_done, + uint64_t send_timeout_ms = 0) __override__ + { if (abandoned_) { p_er( "client %p to %s:%s is already stale (SSL %s)", this, host_.c_str(), port_.c_str(), @@ -1106,8 +1109,8 @@ class asio_rpc_client ( std::chrono::duration_cast ( std::chrono::milliseconds( send_timeout_ms ) ) ); operation_timer_.async_wait( std::bind( &asio_rpc_client::cancel_socket, - this, - std::placeholders::_1 ) ); + this, + std::placeholders::_1 ) ); } @@ -1162,8 +1165,9 @@ class asio_rpc_client } void cancel_socket(const ERROR_CODE& err) { - if (err) // Timer was cancelled itself, it's OK. + if (err) { // Timer was cancelled itself, it's OK. return; + } if (socket().is_open()) { p_wn("cancelling operations due to socket (%s:%s) timeout", diff --git a/tests/unit/asio_service_test.cxx b/tests/unit/asio_service_test.cxx index cc9d620d..1a561463 100644 --- a/tests/unit/asio_service_test.cxx +++ b/tests/unit/asio_service_test.cxx @@ -1214,7 +1214,8 @@ int auto_forwarding_timeout_test() { raft_server::init_options opt; /// Make leader quite slow - opt.raft_callback_ = [](cb_func::Type type, cb_func::Param* param) -> cb_func::ReturnCode { + opt.raft_callback_ = [](cb_func::Type type, cb_func::Param* param) + -> cb_func::ReturnCode { if (type == cb_func::Type::AppendLogs) { TestSuite::sleep_ms(150); } @@ -1245,7 +1246,7 @@ int auto_forwarding_timeout_test() { // Forwarded as expected auto ret1 = s3.raftServer->append_entries({msg}); CHK_TRUE(ret1->get_accepted()); - CHK_EQ(ret1->get_result_code(), nuraft::cmd_result_code::OK) + CHK_EQ(nuraft::cmd_result_code::OK, ret1->get_result_code()); for (auto& entry: pkgs) { RaftAsioPkg* pp = entry; @@ -1269,7 +1270,7 @@ int auto_forwarding_timeout_test() { // Work again auto ret3 = s3.raftServer->append_entries({msg}); CHK_TRUE(ret3->get_accepted()); - CHK_EQ(ret3->get_result_code(), nuraft::cmd_result_code::OK) + CHK_EQ(nuraft::cmd_result_code::OK, ret3->get_result_code()); s1.raftServer->shutdown(); s2.raftServer->shutdown(); diff --git a/tests/unit/fake_network.cxx b/tests/unit/fake_network.cxx index fb46e72a..9fc93c4c 100644 --- a/tests/unit/fake_network.cxx +++ b/tests/unit/fake_network.cxx @@ -298,7 +298,10 @@ FakeClient::FakeClient(FakeNetwork* mother, FakeClient::~FakeClient() {} -void FakeClient::send(ptr& req, rpc_handler& when_done, uint64_t /*send_timeout_ms*/) { +void FakeClient::send(ptr& req, + rpc_handler& when_done, + uint64_t /*send_timeout_ms*/) +{ SimpleLogger* ll = motherNet->getBase()->getLogger(); _log_info(ll, "got request %s -> %s, %s", motherNet->getEndpoint().c_str(), diff --git a/tests/unit/raft_package_asio.hxx b/tests/unit/raft_package_asio.hxx index 75457c28..db652646 100644 --- a/tests/unit/raft_package_asio.hxx +++ b/tests/unit/raft_package_asio.hxx @@ -81,7 +81,7 @@ public: void initServer(bool enable_ssl = false, bool use_global_asio = false, - const raft_server::init_options & opt = raft_server::init_options()) { + const raft_server::init_options& opt = raft_server::init_options()) { std::string log_file_name = "./srv" + std::to_string(myId) + ".log"; myLogWrapper = cs_new(log_file_name); myLog = myLogWrapper;