Skip to content

Commit

Permalink
Improve logging to main process. (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd authored Nov 5, 2024
1 parent e47c11a commit 3e0374f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/lib/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
20 changes: 13 additions & 7 deletions src/lib/messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,45 @@ 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);
_is_leader[group_id] = (leader_id == my_id);
}
} 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;
}
_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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3e0374f

Please sign in to comment.