From ba8dc1cbf40bff70fa8284103dc8155c3d2dd297 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Fri, 13 Dec 2024 13:25:27 +0800 Subject: [PATCH] Refactor error message of register with leader node (#2368) ### What problem does this PR solve? _Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR._ ### Type of change - [x] Refactoring Signed-off-by: Jin Hai --- src/main/cluster_manager_leader.cpp | 5 +++++ src/main/cluster_manager_reader.cpp | 2 +- src/network/peer_server_thrift_service.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/cluster_manager_leader.cpp b/src/main/cluster_manager_leader.cpp index 748e29962e..abe48729c3 100644 --- a/src/main/cluster_manager_leader.cpp +++ b/src/main/cluster_manager_leader.cpp @@ -114,6 +114,11 @@ Status ClusterManager::AddNodeInfo(const SharedPtr &other_node) { return Status::DuplicateNode(other_node_name); } + if (other_node->node_ip() == this_node_->node_ip() and other_node->node_port() == this_node_->node_port()) { + return Status::InvalidServerAddress( + fmt::format("Follower or learner peer server address {}: {} are same as leader", this_node_->node_ip(), this_node_->node_port())); + } + // Add by register auto iter = other_node_map_.find(other_node_name); if (iter != other_node_map_.end()) { diff --git a/src/main/cluster_manager_reader.cpp b/src/main/cluster_manager_reader.cpp index 5e3555c9c2..fd405b5f60 100644 --- a/src/main/cluster_manager_reader.cpp +++ b/src/main/cluster_manager_reader.cpp @@ -125,7 +125,7 @@ Status ClusterManager::RegisterToLeaderNoLock() { Status status = Status::OK(); if (register_peer_task->error_code_ != 0) { status.code_ = static_cast(register_peer_task->error_code_); - status.msg_ = MakeUnique(register_peer_task->error_message_); + status.msg_ = MakeUnique(fmt::format("From leader: {}", register_peer_task->error_message_)); return status; } auto now = std::chrono::system_clock::now(); diff --git a/src/network/peer_server_thrift_service.cpp b/src/network/peer_server_thrift_service.cpp index 7efa35180b..3469d41887 100644 --- a/src/network/peer_server_thrift_service.cpp +++ b/src/network/peer_server_thrift_service.cpp @@ -69,6 +69,7 @@ void PeerServerThriftService::Register(infinity_peer_server::RegisterResponse &r response.leader_term = leader_node->leader_term(); response.heart_beat_interval = leader_node->heartbeat_interval(); } else { + LOG_ERROR(fmt::format("Node: {} fail to register with leader, error: {}", request.node_name, status.message())); response.error_code = static_cast(status.code()); response.error_message = status.message(); }