From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E6F0544643B for ; Wed, 14 Oct 2020 02:28:35 +0300 (MSK) From: Vladislav Shpilevoy Date: Wed, 14 Oct 2020 01:28:29 +0200 Message-Id: <325b6fd1b87444f6cefdacf80e28cd9f692adb29.1602631481.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 3/6] raft: new candidate should wait for leader death List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org When a raft node was configured to be a candidate via election_mode, it didn't do anything if there was an active leader. But it should have started monitoring its health in order to initiate a new election round when it dies. The patch fixes this bug. It does not contain a test, because will be covered by a test for #5339. Needed for #5339 --- src/box/raft.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/box/raft.c b/src/box/raft.c index f51e87fde..ff28e7f08 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -926,12 +926,18 @@ raft_cfg_is_candidate(bool is_candidate) if (raft.is_candidate) { assert(raft.state == RAFT_STATE_FOLLOWER); - /* - * If there is an on-going WAL write, it means there was some - * node who sent newer data to this node. - */ - if (raft.leader == 0 && raft_is_fully_on_disk()) + if (raft.leader != 0) { + raft_sm_wait_leader_dead(); + } else if (raft_is_fully_on_disk()) { raft_sm_wait_leader_found(); + } else { + /* + * If there is an on-going WAL write, it means there was + * some node who sent newer data to this node. So it is + * probably a better candidate. Anyway can't do anything + * until the new state is fully persisted. + */ + } } else if (raft.state != RAFT_STATE_FOLLOWER) { if (raft.state == RAFT_STATE_LEADER) raft.leader = 0; -- 2.21.1 (Apple Git-122.3)