MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / handle_request_vote_response

Method handle_request_vote_response

nodedb-raft/src/node/rpc/request_vote.rs:74–92  ·  view source on GitHub ↗

Handle RequestVote response (candidate only).

(&mut self, peer: u64, resp: &RequestVoteResponse)

Source from the content-addressed store, hash-verified

72
73 /// Handle RequestVote response (candidate only).
74 pub fn handle_request_vote_response(&mut self, peer: u64, resp: &RequestVoteResponse) {
75 if resp.term > self.hard_state.current_term {
76 self.become_follower(resp.term);
77 return;
78 }
79
80 if self.role != NodeRole::Candidate {
81 return;
82 }
83
84 if resp.vote_granted {
85 self.votes_received.insert(peer);
86 let vote_count = self.votes_received.len() + 1; // +1 for self-vote
87
88 if vote_count >= self.config.quorum() {
89 self.become_leader();
90 }
91 }
92 }
93}
94
95#[cfg(test)]

Calls 5

become_followerMethod · 0.80
quorumMethod · 0.80
become_leaderMethod · 0.80
insertMethod · 0.45
lenMethod · 0.45