Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] raft: fix an assertion failure on transition to voter
@ 2020-10-22 10:44 Serge Petrenko
  2020-10-22 11:05 ` Serge Petrenko
  0 siblings, 1 reply; 2+ messages in thread
From: Serge Petrenko @ 2020-10-22 10:44 UTC (permalink / raw)
  To: kyukhin, v.shpilevoy; +Cc: tarantool-patches

When an instance is configured as candidate, it has a leader death timer
ticking constantly to schedule an election as soon as leader disappears.
When the instance receives the leader's heartbeat, it resets the timer
to its initial value.

When being a voter, the instance ignores heartbeats, since it has
nothing to wait for. So its timer must be stopped. Otherwise it'll try
to schedule a new election and fail.

Stop the timer on transition from candidate to voter.
---
https://github.com/tarantool/tarantool/tree/sp/raft-crash-on-voter

 src/box/raft.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/box/raft.c b/src/box/raft.c
index b70f47006..4a8e54cac 100644
--- a/src/box/raft.c
+++ b/src/box/raft.c
@@ -952,12 +952,18 @@ raft_cfg_is_candidate(bool is_candidate)
 			 * until the new state is fully persisted.
 			 */
 		}
-	} else if (raft.state != RAFT_STATE_FOLLOWER) {
-		if (raft.state == RAFT_STATE_LEADER)
-			raft.leader = 0;
-		raft.state = RAFT_STATE_FOLLOWER;
-		/* State is visible and changed - broadcast. */
-		raft_schedule_broadcast();
+	} else {
+		if (raft.state != RAFT_STATE_LEADER) {
+			/* Do not wait for anything while being a voter. */
+			ev_timer_stop(loop(), &raft.timer);
+		}
+		if (raft.state != RAFT_STATE_FOLLOWER) {
+			if (raft.state == RAFT_STATE_LEADER)
+				raft.leader = 0;
+			raft.state = RAFT_STATE_FOLLOWER;
+			/* State is visible and changed - broadcast. */
+			raft_schedule_broadcast();
+		}
 	}
 	box_update_ro_summary();
 }
-- 
2.24.3 (Apple Git-128)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-22 11:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 10:44 [Tarantool-patches] [PATCH] raft: fix an assertion failure on transition to voter Serge Petrenko
2020-10-22 11:05 ` Serge Petrenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox