Skip to content

Commit

Permalink
RATIS-2154. The old leader may send appendEntries after term changed. (
Browse files Browse the repository at this point in the history
  • Loading branch information
133tosakarin authored Sep 12, 2024
1 parent 1918432 commit e6fe8fc
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,10 @@ private synchronized boolean changeToFollower(
boolean allowListener,
Object reason) {
final RaftPeerRole old = role.getCurrentRole();
final boolean metadataUpdated = state.updateCurrentTerm(newTerm);
if (old == RaftPeerRole.LISTENER && !allowListener) {
throw new IllegalStateException("Unexpected role " + old);
}

boolean metadataUpdated;
if ((old != RaftPeerRole.FOLLOWER || force) && old != RaftPeerRole.LISTENER) {
setRole(RaftPeerRole.FOLLOWER, reason);
if (old == RaftPeerRole.LEADER) {
Expand All @@ -597,8 +596,11 @@ private synchronized boolean changeToFollower(
} else if (old == RaftPeerRole.FOLLOWER) {
role.shutdownFollowerState();
}
metadataUpdated = state.updateCurrentTerm(newTerm);
role.startFollowerState(this, reason);
setFirstElection(reason);
} else {
metadataUpdated = state.updateCurrentTerm(newTerm);
}
return metadataUpdated;
}
Expand Down

0 comments on commit e6fe8fc

Please sign in to comment.