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 868F36EC5F; Sun, 18 Apr 2021 11:59:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 868F36EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618736374; bh=4XWOrsU7RSURdj7JecpJt18p7+bXaN3WeCmjvb+VVVI=; 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=BH4NRRRM836HIZYABnFdaSUgHl2lONeeAHmfSppt3NVyZqqhPwEvUrnBN4JFv2KHP NUescSlV89/I6cqSfXsDu0evCtZw6T1aLVaOb0m7P/BgZHkOc2tXWaOtBdGZTgYD1x 4Zr4EQ2bxnVa5QEMBokv7Fb15hpC+BlPUCgMh+po= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 F3FBC6EC5F for ; Sun, 18 Apr 2021 11:59:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F3FBC6EC5F Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1lY3HA-0002rF-Bx; Sun, 18 Apr 2021 11:59:32 +0300 To: Vladislav Shpilevoy , gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org References: <7ff56892-5253-174b-a97b-7800100a58db@tarantool.org> Message-ID: <94422851-f0dd-8995-fbe8-78bbd90680e7@tarantool.org> Date: Sun, 18 Apr 2021 11:59:31 +0300 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: <7ff56892-5253-174b-a97b-7800100a58db@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E748013307ED7ECCBF4892260E197EB99ED8F182A05F5380850400066AC4E03850EA35CAFD926F6948531EAFF86D839F255AEDD374BF17586024D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DA1A6500DE61AB7AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637802D3462438662818638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2F7C369039B3619A9A058C079C6C832E99414A38D98B987DBD2E47CDBA5A96583C09775C1D3CA48CFED8438A78DFE0A9E117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE71DD432BB81541BCF9FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE772C7F6EAAB0B2D3AD32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0F0EB20F09E7EDBCCCD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C34B08FA16E56A400835872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5C90E705BE6F8CB7CC803461CEF7FA28F7E2E798456C1257BD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F6110710A6CC527FEE3F8C3B9118CEC8D0E9AEFFE244AADCEAB2C275DAA85D33935D68D30F31E7F21D7E09C32AA3244C7B1DE6B094957B162353E07C2D274FFBF26BFA4C8A6946B8FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj1t4H7vLuVFXtg+THztPw8w== X-Mailru-Sender: 583F1D7ACE8F49BDD2846D59FC20E9F83A84F7F6465804B22BB2B7CC29B64D4317B06088871D0942424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 17.04.2021 01:23, Vladislav Shpilevoy пишет: > Thanks for working on this! > > See 3 comments below. Thanks for  the review! > >> 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. Ok, let it be do_demote then. > >> +{ >> + 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'. Fixed. > >> + >> /** 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. This became obsolete after I squashed your commit, but thanks for noticing! > >> raft_node_destroy(&node); >> raft_finish_test(); >> } ================================= diff --git a/src/lib/raft/raft.c b/src/lib/raft/raft.c index 874e9157e..3f900db9a 100644 --- a/src/lib/raft/raft.c +++ b/src/lib/raft/raft.c @@ -865,7 +865,7 @@ raft_start_candidate(struct raft *raft)         assert(raft->state != RAFT_STATE_CANDIDATE);         /*          * May still be the leader after raft_stop_candidate -        * with demote = false. +        * with do_demote = false.          */         if (raft->state == RAFT_STATE_LEADER)                 return; @@ -884,7 +884,7 @@ raft_start_candidate(struct raft *raft)  }  void -raft_stop_candidate(struct raft *raft, bool demote) +raft_stop_candidate(struct raft *raft, bool do_demote)  {         if (!raft->is_candidate)                 return; @@ -895,7 +895,7 @@ raft_stop_candidate(struct raft *raft, bool demote)         }         if (raft->state != RAFT_STATE_FOLLOWER) {                 if (raft->state == RAFT_STATE_LEADER) { -                       if (!demote) { +                       if (!do_demote) {                                 /*                                  * Remain leader until someone                                  * triggers new elections. diff --git a/src/lib/raft/raft.h b/src/lib/raft/raft.h index f7bc205d2..a8da564b0 100644 --- a/src/lib/raft/raft.h +++ b/src/lib/raft/raft.h @@ -289,10 +289,10 @@ 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. + * @param do_demote whether to stop being a leader immediately or not.   */  void -raft_stop_candidate(struct  raft *raft, bool demote); +raft_stop_candidate(struct raft *raft, bool do_demote);  /** Configure Raft leader election timeout. */  void -- Serge Petrenko