From 3e0374f8af2e1e15cd91630928f637b8513deee3 Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Mon, 4 Nov 2024 18:02:16 -0700 Subject: [PATCH 1/2] Improve logging to main process. (#105) --- conanfile.py | 2 +- src/lib/logger.hpp | 1 + src/lib/messaging.cpp | 20 +++++++++++++------- src/lib/service.cpp | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index 738a9c4..fa545ef 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ class NuRaftGrpcConan(ConanFile): name = "nuraft_grpc" - version = "6.1.2" + version = "6.1.3" homepage = "https://github.com/eBay/nuraft_mesg" description = "A gRPC service for NuRAFT" topics = ("ebay", "nublox", "raft") diff --git a/src/lib/logger.hpp b/src/lib/logger.hpp index 56e05d7..3e3b6b1 100644 --- a/src/lib/logger.hpp +++ b/src/lib/logger.hpp @@ -42,6 +42,7 @@ class nuraft_mesg_logger : public ::nuraft::logger { [[fallthrough]]; case 2: { LOGERRORMOD_USING_LOGGER(nuraft, _custom_logger, "ERROR {}", mesg); + LOGERRORMOD(nuraft, "ERROR {}", mesg); } break; ; case 3: { diff --git a/src/lib/messaging.cpp b/src/lib/messaging.cpp index 923793d..1e76317 100644 --- a/src/lib/messaging.cpp +++ b/src/lib/messaging.cpp @@ -137,14 +137,14 @@ void service::register_mgr_type(std::string const& group_type, register_params& nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_id, nuraft::cb_func::Type type, nuraft::cb_func::Param* param) { + auto const my_id = param->myId; + auto const leader_id = param->leaderId; switch (type) { case nuraft::cb_func::RemovedFromCluster: { - LOGINFO("Removed from cluster {}", group_id); + LOGINFO("Removed from cluster {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); exit_group(group_id); } break; case nuraft::cb_func::JoinedCluster: { - auto const my_id = param->myId; - auto const leader_id = param->leaderId; LOGINFO("Joined cluster: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); @@ -152,11 +152,11 @@ nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_i } } break; case nuraft::cb_func::NewConfig: { - LOGDEBUGMOD(nuraft_mesg, "Cluster change for: {}", group_id); + LOGDEBUGMOD(nuraft_mesg, "Cluster change for: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); _config_change.notify_all(); } break; case nuraft::cb_func::BecomeLeader: { - LOGDEBUGMOD(nuraft_mesg, "I'm the leader of: {}!", group_id); + LOGINFOMOD(nuraft_mesg, "Elected leader of: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); _is_leader[group_id] = true; @@ -164,12 +164,18 @@ nuraft::cb_func::ReturnCode service::callback_handler(std::string const& group_i _config_change.notify_all(); } break; case nuraft::cb_func::BecomeFollower: { - LOGDEBUGMOD(nuraft_mesg, "I'm a follower of: {} with the leader {}!", group_id, param->leaderId); + LOGINFOMOD(nuraft_mesg, "Became a follower of: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); { std::lock_guard< std::mutex > lg(_manager_lock); _is_leader[group_id] = false; } - } + } break; + case nuraft::cb_func::SaveSnapshot: { + LOGINFOMOD(nuraft_mesg, "Received Snapshot to sync for: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id); + } break; + case nuraft::cb_func::FollowerLost: { + LOGINFOMOD(nuraft_mesg, "Lost follower: {}, [leader_id:{}, my_id:{}]", param->peerId, group_id, leader_id, my_id); + } break; default: break; }; diff --git a/src/lib/service.cpp b/src/lib/service.cpp index 2d7e4a0..3d0fa58 100644 --- a/src/lib/service.cpp +++ b/src/lib/service.cpp @@ -205,7 +205,7 @@ bool msg_service::raftStep(const sisl::AsyncRpcDataPtr< Messaging, RaftGroupMsg, // Verify this is for the service it was intended for auto const& base = request.msg().base(); if (intended_addr != _service_address) { - LOGWARNMOD(nuraft_mesg, "Recieved mesg for {} intended for {}, we are {}", + LOGWARNMOD(nuraft_mesg, "Received mesg for [{}:{}] intended for {}, we are {}", group_name, nuraft::msg_type_to_string(nuraft::msg_type(base.type())), intended_addr, _service_address); rpc_data->set_status(::grpc::Status( ::grpc::INVALID_ARGUMENT, From 03cacff56e7103f008b1e7b6aa6e73bd52d5e805 Mon Sep 17 00:00:00 2001 From: Brian Szmyd Date: Wed, 4 Dec 2024 11:30:05 -0700 Subject: [PATCH 2/2] Add batch_size_hint field to RCResponse message. (#110) Fixes #109 --- conanfile.py | 4 ++-- src/lib/grpc_client.cpp | 1 + src/lib/grpc_server.cpp | 1 + src/proto/raft_types.proto | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index fa545ef..1ec95eb 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ class NuRaftGrpcConan(ConanFile): name = "nuraft_grpc" - version = "6.1.3" + version = "6.2.0" homepage = "https://github.com/eBay/nuraft_mesg" description = "A gRPC service for NuRAFT" topics = ("ebay", "nublox", "raft") @@ -53,7 +53,7 @@ def requirements(self): self.requires("sisl/8.6.8") self.requires("lz4/1.9.4", override=True) - self.requires("grpc/1.50.1", override=True) + self.requires("grpc/1.50.1", override=True) def build(self): cmake = CMake(self) diff --git a/src/lib/grpc_client.cpp b/src/lib/grpc_client.cpp index 2ccd334..ddbd3a7 100644 --- a/src/lib/grpc_client.cpp +++ b/src/lib/grpc_client.cpp @@ -50,6 +50,7 @@ inline shared< nuraft::resp_msg > toResponse(RaftMessage const& raft_msg) { auto const& resp = raft_msg.rc_response(); auto message = std::make_shared< grpc_resp >(base.term(), (nuraft::msg_type)base.type(), base.src(), base.dest(), resp.next_index(), resp.accepted()); + message->set_next_batch_size_hint_in_bytes(resp.batch_size_hint()); message->set_result_code((nuraft::cmd_result_code)(0 - resp.result_code())); if (nuraft::cmd_result_code::NOT_LEADER == message->get_result_code()) { LOGINFOMOD(nuraft_mesg, "Leader has changed!"); diff --git a/src/lib/grpc_server.cpp b/src/lib/grpc_server.cpp index 465f950..42167a6 100644 --- a/src/lib/grpc_server.cpp +++ b/src/lib/grpc_server.cpp @@ -26,6 +26,7 @@ static RCResponse* fromRCResponse(nuraft::resp_msg& rcmsg) { auto req = new RCResponse; req->set_next_index(rcmsg.get_next_idx()); req->set_accepted(rcmsg.get_accepted()); + req->set_batch_size_hint(rcmsg.get_next_batch_size_hint_in_bytes()); req->set_result_code((ResultCode)(0 - rcmsg.get_result_code())); auto ctx = rcmsg.get_ctx(); if (ctx) { req->set_context(ctx->data(), ctx->container_size()); } diff --git a/src/proto/raft_types.proto b/src/proto/raft_types.proto index b6c6231..7779bb9 100644 --- a/src/proto/raft_types.proto +++ b/src/proto/raft_types.proto @@ -73,6 +73,7 @@ message RCResponse { bytes context = 3; string dest_addr = 4; ResultCode result_code = 5; + uint64 batch_size_hint = 6; } message RaftMessage {