Skip to content

Commit

Permalink
fix get peer info of removed membe
Browse files Browse the repository at this point in the history
in nuobject test, a removed member will try to get the info of itself to
identify whether it is in a pg. but ATM , it is not in the configuration
of this raft group. this PR aims to handle this case.

what`s more, this PR add the commited_log_index to peer info, so that a
peer can get its last commited log index.
  • Loading branch information
JacksonYao287 committed Nov 19, 2024
1 parent ec3ca39 commit 18a83e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 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.3"
version = "3.6.4"

homepage = "https://github.com/eBay/nuraft_mesg"
description = "A gRPC service for NuRAFT"
Expand Down
3 changes: 3 additions & 0 deletions include/nuraft_mesg/mesg_state_mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct peer_info {
uint64_t last_log_idx_;
// The elapsed time since the last successful response from this peer, set to 0 on leader
uint64_t last_succ_resp_us_;
// The last committed log index that the peer has. this is only got by the node itself,
// a node can not get the last_commit_log_idx_ of other nodes.
uint64_t last_commit_log_idx_;
};

class repl_service_ctx {
Expand Down
19 changes: 13 additions & 6 deletions src/lib/repl_service_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,23 @@ std::vector< peer_info > repl_service_ctx::get_raft_status() const {
LOGW("do not find peer id {} in the conifg of leader", pinfo.id_);
continue;
}
peers.emplace_back(peer_info{std::string(peer_id), pinfo.last_log_idx_, pinfo.last_succ_resp_us_});
// from the view of leader, it can not get the last_commit_log_idx_ of other nodes, so set it to 0
peers.emplace_back(std::string(peer_id), pinfo.last_log_idx_, pinfo.last_succ_resp_us_, 0);
}
}

auto my_id = _server->get_id();
auto my_peer_id = _server->get_srv_config(my_id)->get_endpoint();
auto my_config = _server->get_srv_config(_server->get_id());

// add the peer info of itself(leader or follower) , which is useful for upper layer
// from the view a node itself, last_succ_resp_us_ make no sense, so set it to 0
peers.emplace_back(my_peer_id, _server->get_last_log_idx(), 0);
// if I am the removed memeber, I can not find myself in the configuration. this will happen when a removed member
// tries to get the raft status
if (my_config) {
auto my_peer_id = my_config->get_endpoint();

// add the peer info of itself(leader or follower) , which is useful for upper layer
// 1 from the view of a node itself, last_succ_resp_us_ make no sense, so set it to 0
// 2 from the view of a node itself, it can get the last_commit_log_idx_ of itself
peers.emplace_back(my_peer_id, _server->get_last_log_idx(), 0, _server->get_committed_log_idx());
}

return peers;
}
Expand Down

0 comments on commit 18a83e6

Please sign in to comment.