Step down to follower (or keep learner/observer role if the node is one). Learners and observers that receive an `AppendEntries` with a higher term update their term but do not transition to `Follower` — they stay in their non-election role so the tick loop continues to skip timeouts.
(&mut self, term: u64)
| 67 | /// term update their term but do not transition to `Follower` — they stay |
| 68 | /// in their non-election role so the tick loop continues to skip timeouts. |
| 69 | pub(super) fn become_follower(&mut self, term: u64) { |
| 70 | let was_leader = self.role == NodeRole::Leader; |
| 71 | match self.role { |
| 72 | NodeRole::Learner | NodeRole::Observer => { |
| 73 | // Preserve the non-election role. |
| 74 | } |
| 75 | NodeRole::Follower | NodeRole::Candidate | NodeRole::Leader => { |
| 76 | self.role = NodeRole::Follower; |
| 77 | } |
| 78 | } |
| 79 | self.hard_state.current_term = term; |
| 80 | self.hard_state.voted_for = 0; |
| 81 | self.leader_state = None; |
| 82 | self.votes_received.clear(); |
| 83 | self.persist_hard_state(); |
| 84 | self.reset_election_timeout(); |
| 85 | |
| 86 | if was_leader { |
| 87 | info!( |
| 88 | node = self.config.node_id, |
| 89 | group = self.config.group_id, |
| 90 | term, |
| 91 | "stepped down from leader" |
| 92 | ); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | pub(super) fn become_leader(&mut self) { |
| 97 | self.role = NodeRole::Leader; |
no test coverage detected