Skip to content

Commit

Permalink
Improve logging to main process. (#105) (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd authored Nov 7, 2024
1 parent 06b329b commit a277e8a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class NuRaftMesgConan(ConanFile):
name = "nuraft_mesg"
version = "3.6.1"
version = "3.6.2"

homepage = "https://github.com/eBay/nuraft_mesg"
description = "A gRPC service for NuRAFT"
Expand Down
10 changes: 8 additions & 2 deletions src/lib/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ class nuraft_mesg_logger : public ::nuraft::logger {
const std::string& log_line) override {
switch (level) {
case 1: {
if (LEVELCHECK(nuraft_mesg, spdlog::level::level_enum::critical))
if (LEVELCHECK(nuraft_mesg, spdlog::level::level_enum::critical)) {
sisl::logging::GetLogger()->critical("[{}:{}:{}] {} [group={}]", file_name(source_file), line_number,
func_name, log_line, _group_id);
_custom_logger->critical("[{}:{}:{}] {} [group={}]", file_name(source_file), line_number, func_name,
log_line, _group_id);
}
} break;
case 2: {
if (LEVELCHECK(nuraft_mesg, spdlog::level::level_enum::err))
if (LEVELCHECK(nuraft_mesg, spdlog::level::level_enum::err)) {
sisl::logging::GetLogger()->error("[{}:{}:{}] {} [group={}]", file_name(source_file), line_number,
func_name, log_line, _group_id);
_custom_logger->error("[{}:{}:{}] {} [group={}]", file_name(source_file), line_number, func_name,
log_line, _group_id);
}
} break;
case 3: {
if (LEVELCHECK(nuraft_mesg, spdlog::level::level_enum::warn))
Expand Down
22 changes: 14 additions & 8 deletions src/lib/manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,40 +128,46 @@ void ManagerImpl::register_mgr_type(group_type_t const& group_type, group_params
nuraft::cb_func::ReturnCode ManagerImpl::generic_raft_event_handler(group_id_t 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: {
LOGI("[srv_id={}] evicted from: [group={}]", start_params_.server_uuid_, group_id);
LOGI("[srv_id={}] evicted from: [group={}, leader_id:{}, my_id:{}]", start_params_.server_uuid_, 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;
LOGI("[srv_id={}] joined: [group={}], [leader_id:{},my_id:{}]", start_params_.server_uuid_, group_id, leader_id,
LOGI("[srv_id={}] joined: [group={}, leader_id:{}, my_id:{}]", start_params_.server_uuid_, 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: {
LOGD("[srv_id={}] saw cluster change: [group={}]", start_params_.server_uuid_, group_id);
LOGD("[srv_id={}] saw cluster change: [group={}, leader_id:{}, my_id:{}]", start_params_.server_uuid_, group_id, leader_id, my_id);
_config_change.notify_all();
} break;
case nuraft::cb_func::BecomeLeader: {
LOGI("[srv_id={}] became leader: [group={}]!", start_params_.server_uuid_, group_id);
LOGI("[srv_id={}] became leader: [group={}, leader_id:{}, my_id:{}]!", start_params_.server_uuid_, 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: {
LOGI("[srv_id={}] following: [group={}]!", start_params_.server_uuid_, group_id);
LOGI("[srv_id={}] following: [group={}, leader_id:{}, my_id:{}]!", start_params_.server_uuid_, 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: {
LOGI("Received Snapshot to sync for: {}, [leader_id:{}, my_id:{}]", group_id, leader_id, my_id);
} break;
case nuraft::cb_func::FollowerLost: {
LOGI("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/proto/proto_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool proto_service::raftStep(const sisl::AsyncRpcDataPtr< Messaging, RaftGroupMs
// Verify this is for the service it was intended for
auto const& base = request.msg().base();
if (sid != _service_address) {
LOGW("Recieved mesg for {} intended for {}, we are {}",
LOGW("Recieved mesg for [{}:{}] intended for {}, we are {}", group_id,
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 a277e8a

Please sign in to comment.