Skip to content

Commit

Permalink
Refactor error message of register with leader node (#2368)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
  • Loading branch information
JinHai-CN authored Dec 13, 2024
1 parent 7a363f8 commit ba8dc1c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/cluster_manager_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ Status ClusterManager::AddNodeInfo(const SharedPtr<NodeInfo> &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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/cluster_manager_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Status ClusterManager::RegisterToLeaderNoLock() {
Status status = Status::OK();
if (register_peer_task->error_code_ != 0) {
status.code_ = static_cast<ErrorCode>(register_peer_task->error_code_);
status.msg_ = MakeUnique<String>(register_peer_task->error_message_);
status.msg_ = MakeUnique<String>(fmt::format("From leader: {}", register_peer_task->error_message_));
return status;
}
auto now = std::chrono::system_clock::now();
Expand Down
1 change: 1 addition & 0 deletions src/network/peer_server_thrift_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>(status.code());
response.error_message = status.message();
}
Expand Down

0 comments on commit ba8dc1c

Please sign in to comment.