From 8731295eb41412264a0e040d32b9a2ceeed90c3d Mon Sep 17 00:00:00 2001 From: amichon-kalray <83058367+amichon-kalray@users.noreply.github.com> Date: Wed, 19 Jun 2024 01:02:41 +0200 Subject: [PATCH 1/4] Add timeout to async_connect operation (#516) * Add timeout to async_connect operation If the network goes down during a async_connect, we may end up being stuck forever in this function since there is no timeout to cancel it. Signed-off-by: Alex Michon * Indent and line breaking --------- Signed-off-by: Alex Michon Co-authored-by: Jung-Sang Ahn --- src/asio_service.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/asio_service.cxx b/src/asio_service.cxx index a1fd31fe..ff84ce86 100644 --- a/src/asio_service.cxx +++ b/src/asio_service.cxx @@ -1407,6 +1407,15 @@ class asio_rpc_client send_timeout_ms, std::placeholders::_1, std::placeholders::_2 ) ); + if (send_timeout_ms != 0) { + operation_timer_.expires_after + ( 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 ) ); + } } else { ptr rsp; ptr except @@ -1477,6 +1486,7 @@ class asio_rpc_client std::error_code err, asio::ip::tcp::resolver::iterator itor) { + operation_timer_.cancel(); if (!err) { p_in( "%p connected to %s:%s (as a client)", this, host_.c_str(), port_.c_str() ); From 52d9236b2dfc21321c75c6d8b028ec7eda6012a3 Mon Sep 17 00:00:00 2001 From: amichon-kalray <83058367+amichon-kalray@users.noreply.github.com> Date: Sat, 22 Jun 2024 00:21:18 +0200 Subject: [PATCH 2/4] Add result code to response messages (#515) * Add result code to response messages In some cases, the response is marked as accepted even if there was an error. Therefore, including the accepted tag in the response message is not enough: a follower may believe that an auto forwarded request was successful when it wasn't. Signed-off-by: Alex Michon * [Update PR] Add `int32_t` to `cmd_result_code` --------- Signed-off-by: Alex Michon Co-authored-by: Jung-Sang Ahn --- include/libnuraft/async.hxx | 2 +- src/asio_service.cxx | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/libnuraft/async.hxx b/include/libnuraft/async.hxx index 872db482..1ead4de8 100644 --- a/include/libnuraft/async.hxx +++ b/include/libnuraft/async.hxx @@ -36,7 +36,7 @@ limitations under the License. namespace nuraft { -enum cmd_result_code { +enum cmd_result_code : int32_t { OK = 0, CANCELLED = -1, TIMEOUT = -2, diff --git a/src/asio_service.cxx b/src/asio_service.cxx index ff84ce86..f8f2d4f3 100644 --- a/src/asio_service.cxx +++ b/src/asio_service.cxx @@ -124,6 +124,9 @@ limitations under the License. // If set, each log entry will contain a CRC on the payload. #define CRC_ON_PAYLOAD (0x10) +// If set, RPC message (response) includes result code +#define INCLUDE_RESULT_CODE (0x20) + // ======================= namespace nuraft { @@ -735,6 +738,7 @@ class rpc_session try { ptr resp_ctx = resp->get_ctx(); int32 resp_ctx_size = (resp_ctx) ? resp_ctx->size() : 0; + int32 result_code_size = sizeof(int32_t); uint32_t flags = 0x0; size_t resp_meta_size = 0; @@ -759,6 +763,13 @@ class rpc_session size_t carried_data_size = resp_meta_size + resp_hint_size + resp_ctx_size; + if (req->get_type() == msg_type::client_request || + req->get_type() == msg_type::add_server_request || + req->get_type() == msg_type::remove_server_request) { + flags |= INCLUDE_RESULT_CODE; + carried_data_size += result_code_size; + } + int buf_size = RPC_RESP_HEADER_SIZE + carried_data_size; ptr resp_buf = buffer::alloc(buf_size); buffer_serializer bs(resp_buf); @@ -798,6 +809,11 @@ class rpc_session bs.put_buffer(*resp_ctx); } + /* Put result code at the end to avoid breaking backward compatibility */ + if (flags & INCLUDE_RESULT_CODE) { + bs.put_i32(resp->get_result_code()); + } + aa::write( ssl_enabled_, ssl_socket_, socket_, asio::buffer(resp_buf->data_begin(), resp_buf->size()), [this, self, resp_buf] @@ -1688,8 +1704,9 @@ class asio_rpc_client size_t bytes_transferred) { if ( !(flags & INCLUDE_META) && - !(flags & INCLUDE_HINT) ) { - // Neither meta nor hint exists, + !(flags & INCLUDE_HINT) && + !(flags & INCLUDE_RESULT_CODE)) { + // Neither meta nor hint nor result code exists, // just use the buffer as it is for ctx. ctx_buf->pos(0); rsp->set_ctx(ctx_buf); @@ -1739,9 +1756,21 @@ class asio_rpc_client assert(remaining_len >= 0); if (remaining_len) { // It has context, read it. - ptr actual_ctx = buffer::alloc(remaining_len); + size_t ctx_len = remaining_len; + if (flags & INCLUDE_RESULT_CODE) { + ctx_len -= sizeof(int32_t); + } + ptr actual_ctx = buffer::alloc(ctx_len); bs.get_buffer(actual_ctx); rsp->set_ctx(actual_ctx); + remaining_len -= ctx_len; + } + + // 4) Result code + if (flags & INCLUDE_RESULT_CODE) { + assert((size_t)remaining_len >= sizeof(int32_t)); + cmd_result_code res = static_cast(bs.get_i32()); + rsp->set_result_code(res); } operation_timer_.cancel(); From 340f632a27d6be248b71f56c876d53c6f89dbb27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:50:14 -0700 Subject: [PATCH 3/4] Bump codecov/codecov-action from 4.4.1 to 4.5.0 (#518) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.4.1 to 4.5.0. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/125fc84a9a348dbcf27191600683ec096ec9021c...e28ff129e5465c2c0dcc6f003fc735cb6ae0c673) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f85b66c4..1fdab4d3 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -52,7 +52,7 @@ jobs: run: ./github_action_build.sh - name: Code Coverage Metrics - uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # pin@v3 + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # pin@v3 with: verbose: true files: ./build/raft_cov.info.cleaned From 35083c6bad96df5236d9871f5c33b0530c7817a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:50:22 -0700 Subject: [PATCH 4/4] Bump actions/checkout from 4.1.6 to 4.1.7 (#519) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.6 to 4.1.7. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/a5ac7e51b41094c92402da3b24376905380afc29...692973e3d937129bcbf40652eb9f2f61becf3332) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 1fdab4d3..c5f7db0e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -31,7 +31,7 @@ jobs: timeout-minutes: 30 steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # pin@v2 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v2 - name: Fix kernel mmap rnd bits # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with