From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 0B5836EC5F; Sat, 17 Apr 2021 01:23:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0B5836EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618611783; bh=8Le1FSO3Jvww3NeFP4TEDn7aDxd51NKriOqeCRgl/Ss=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=KrH7oj+r8K8MNI5xR2V05hvIqPlNtry5QjtDX6jQSwb6enjk5h9URsjgyygnO5bR9 UXHoGHJTZmMdK84yBL4Tk9juRgKYFW6nSz0x1X9C9SYpwC8gjYIW/u/ixe9h8pLuQA 5iTj/zWlrPDXDTbMSRlHB4MuwE/GbXaov2zkAEZA= Received: from smtp38.i.mail.ru (smtp38.i.mail.ru [94.100.177.98]) (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 4F91B6EC5F for ; Sat, 17 Apr 2021 01:23:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F91B6EC5F Received: by smtp38.i.mail.ru with esmtpa (envelope-from ) id 1lXWrd-0006Uf-Jw; Sat, 17 Apr 2021 01:23:02 +0300 To: Serge Petrenko , gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org References: Message-ID: <7ff56892-5253-174b-a97b-7800100a58db@tarantool.org> Date: Sat, 17 Apr 2021 00:23:00 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480BE79914FF86F9151AC38CC435EA4A654182A05F53808504022F6FABC10D971147E4FB740B76BC66CC5BDFE2532F15AAEF607E1F17923AF7A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE730B41EED8119E12FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372094AD700861FA748638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2BC42FBAFD590C3DAE432020B0A458D6AAD368CDB2FD0D9CCD2E47CDBA5A96583C09775C1D3CA48CFE478A468B35FE767117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7BEE62E5629C982429FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE772C7F6EAAB0B2D3AD32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0D405410565B6B015CD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C369456C5265B6C55C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4ADC9C490B0B7E26B461F353E365580418C X-C1DE0DAB: 0D63561A33F958A587D3F37D2D3B0AE97A1E38222CBAC4FB02EB5CF4640D5144D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3416EA6E382A5BB1761674E4F08AD5FDBB6E244689C3E57B6F3B5D5530BF45328905F4B69CDB0C899A1D7E09C32AA3244C55344BF85850F04B2B60AB304FDF548DE8FBBEFAE1C4874CFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojr8JA+pXcDukVfGaa0ToPog== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110803774D883795568E5C9BF88160EB77A615C7E8934B3BD2207784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 09/12] raft: introduce raft_start/stop_candidate X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for working on this! See 3 comments below. > src/lib/raft/raft.c | 83 ++++++++++++++++++++++++++++--------------- > src/lib/raft/raft.h | 13 +++++++ > test/unit/raft.c | 33 +++++++++++++++-- > test/unit/raft.result | 10 +++++- > 4 files changed, 108 insertions(+), 31 deletions(-) > > diff --git a/src/lib/raft/raft.c b/src/lib/raft/raft.c > index e9ce8cade..b21693642 100644 > --- a/src/lib/raft/raft.c > +++ b/src/lib/raft/raft.c > @@ -848,38 +848,65 @@ raft_cfg_is_enabled(struct raft *raft, bool is_enabled) <...> > + > +void > +raft_stop_candidate(struct raft *raft, bool demote) 1. For flags we usually use 'is', 'do', 'has' and similar prefixes. > +{ > + if (!raft->is_candidate) > + return; > + raft->is_candidate = false; > + if (raft->state != RAFT_STATE_LEADER) { > + /* Do not wait for anything while being a voter. */ > + raft_ev_timer_stop(raft_loop(), &raft->timer); > + } > + if (raft->state != RAFT_STATE_FOLLOWER) { > + if (raft->state == RAFT_STATE_LEADER) { > + if (!demote) { > + /* > + * Remain leader until someone > + * triggers new elections. > + */ > + return; > + } > + raft->leader = 0; > } > + raft->state = RAFT_STATE_FOLLOWER; > + /* State is visible and changed - broadcast. */ > + raft_schedule_broadcast(raft); > } > } > > diff --git a/src/lib/raft/raft.h b/src/lib/raft/raft.h > index a5f7e08d9..69dec63c6 100644 > --- a/src/lib/raft/raft.h > +++ b/src/lib/raft/raft.h > @@ -327,6 +327,19 @@ raft_cfg_is_enabled(struct raft *raft, bool is_enabled); > void > raft_cfg_is_candidate(struct raft *raft, bool is_candidate); > > +/** > + * Make the instance a candidate. > + */ > +void > +raft_start_candidate(struct raft *raft); > + > +/** > + * Make the instance stop taking part in new elections. > + * @param demote whether to stop being a leader immediately or not. > + */ > +void > +raft_stop_candidate(struct raft *raft, bool demote); 2. Double whitespace after 'struct'. > + > /** Configure Raft leader election timeout. */ > void > raft_cfg_election_timeout(struct raft *raft, double timeout); > diff --git a/test/unit/raft.c b/test/unit/raft.c > index 0306cefcd..575886932 100644 > --- a/test/unit/raft.c > +++ b/test/unit/raft.c > @@ -1296,15 +1296,43 @@ raft_test_term_filter(void) > ok(!raft_is_node_outdated(&node.raft, 3), "node doesn't become " > "outdated"); > > - 3. This probably should be in the previous commit. > raft_node_destroy(&node); > raft_finish_test(); > }