diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-26 23:18:11 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-26 23:18:11 +0200 |
| commit | e76b434619e1ec034e161e0c644e5fad5ab14c79 (patch) | |
| tree | 174db947f131bdfc514518ebb01f66f378b73c5a /src/main/java/protocols/implementations/VSRaftProtocol.java | |
| parent | ffdbcd5382394e0107b88aed0ae762538bcd6167 (diff) | |
Fix Raft follower timeout re-arming tests (0bac83d3-1322-4940-a9ee-58eb1e0d6245)
Diffstat (limited to 'src/main/java/protocols/implementations/VSRaftProtocol.java')
| -rw-r--r-- | src/main/java/protocols/implementations/VSRaftProtocol.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/protocols/implementations/VSRaftProtocol.java b/src/main/java/protocols/implementations/VSRaftProtocol.java index 4a310ee..eaf63a7 100644 --- a/src/main/java/protocols/implementations/VSRaftProtocol.java +++ b/src/main/java/protocols/implementations/VSRaftProtocol.java @@ -166,6 +166,7 @@ public class VSRaftProtocol extends VSAbstractProtocol { * @param newLeaderId the known leader in that term, or -1 if unknown */ private void becomeFollower(int term, int newLeaderId) { + clearServerSchedules(); isLeader = false; isCandidate = false; currentTerm = term; @@ -181,9 +182,24 @@ public class VSRaftProtocol extends VSAbstractProtocol { private void resetElectionTimeout() { long jitterPercentage = Math.abs(process.getRandomPercentage()); long jitter = (getLong("electionJitter") * jitterPercentage) / 100L; + boolean previousContextIsServer = currentContextIsServer(); + currentContextIsServer(false); removeSchedules(); scheduleAt(process.getTime() + getLong("electionTimeout") + jitter); + currentContextIsServer(previousContextIsServer); + } + + /** + * Clears any active server-side schedules while preserving the caller + * context. + */ + private void clearServerSchedules() { + boolean previousContextIsServer = currentContextIsServer(); + + currentContextIsServer(true); + removeSchedules(); + currentContextIsServer(previousContextIsServer); } /** |
