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 85B0F6F879; Tue, 25 Jan 2022 13:17:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 85B0F6F879 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1643105876; bh=MW6H9GDF4aQTJsfvgomLS70yInKgwRrHpFzY15r383I=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bVXey92T6xp8UGjfjRTZowHIV1Tc6cuvavMDSNf/GQIz4j5kNOZ5ZF0E8OxksLDMn iavo3kWUi0G/VsFAMSX8zl/StEtIwDx++qr7uq/vIE46E9ocdDYsExSyBZLoKeWxVd gRPZA/rfdH7R7jRuEmviyjfgzTCcQyYUqk/PFryE= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 6B1756F879 for ; Tue, 25 Jan 2022 13:17:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6B1756F879 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1nCItd-000300-JX; Tue, 25 Jan 2022 13:17:54 +0300 Message-ID: <3caf820d-9e60-0eb4-188d-33abbcb25721@tarantool.org> Date: Tue, 25 Jan 2022 13:17:52 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-GB To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org References: <72798befd5d6e32f4386aaeeb3209cc93c0e44b4.1642639079.git.v.shpilevoy@tarantool.org> <33c8217d-c839-1b1e-7595-db44c640eeac@tarantool.org> <71e416b7-3532-897d-a49b-0dcb925a88f6@tarantool.org> In-Reply-To: <71e416b7-3532-897d-a49b-0dcb925a88f6@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9AA78FDF62ECAE61F7D831E2382AA7A6C0481E357CE3D3DF1182A05F538085040032AAD8D9E5F17E2C103200072A1504992B8105B7868CDBF4C4898D6C5AFD56F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A609AE8E79ADB41CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375448D590B04CE87D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8448C42CDB2BE52953309DC3B82291EFC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55D5BE2F85BDEC5FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520B28585415E75ADA9BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB1593CA6EC85F86D846F39228950D27DD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE30CABCCA60F52D7EB302FCEF25BFAB345C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006373BC478629CBEC79DEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5882728020B78E31CEA8D831B237EF85E274809830B387DB4D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75913C2247C57F08EB410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F804B400765FFFF9B97E4D21F4A2080C42F5FC3D5A81434BFF1B53731FA47318C60DDD106CE60F191D7E09C32AA3244CD3E9ECFE405D86BC2BE2122B5EC67A1230452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojF0Kx79yI7sWLBJ5Oh8cclw== X-Mailru-Sender: 583F1D7ACE8F49BDA1AB7BAC9906293E160A9EA8DA6AE0AF6F77F92A60A8F5E67294268B687DDCF2424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BCB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 4/5] raft: introduce split vote detection 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" 21.01.2022 02:02, Vladislav Shpilevoy пишет: >>> +static void >>> +raft_check_split_vote(struct raft *raft) >>> +{ >>> +    /* When leader is known, there is no election. Thus no vote to split. */ >>> +    if (raft->leader != 0) >>> +        return; >>> +    /* Not a candidate = can't trigger term bump anyway. */ >>> +    if (!raft->is_candidate) >>> +        return; >>> +    /* >>> +     * WAL write in progress means the state is changing. All is rechecked >>> +     * when it is done. >>> +     */ >>> +    if (raft->is_write_in_progress) >>> +        return; >>> +    if (!raft_has_split_vote(raft)) >>> +        return; >>> +    assert(raft_ev_is_active(&raft->timer)); >>> +    /* >>> +     * Could be already detected before. The timeout would be updated by now >>> +     * then. >>> +     */ >>> +    if (raft->timer.repeat < raft->election_timeout) >>> +        return; >> I don't think you should decrease timer.repeat. >> This 'vote speedup' is for a single term only. >> >> Besides the check below about delay >= remaining is enough >> to test if split vote detection was already triggered. > I update timer.repeat as a flag that the split vote was already seen > during this term. If I drop this check, each next vote after the first > detection of split vote will lead to potential timeout decrease depending > on random. I wanted to decrease it only once - when split vote is seen > first time. Even managed to add a test for it. > > The alternative was to store a flag 'has_split_vote' somewhere in struct > raft, but I didn't want to add it. Ok, I see now. Thanks for the explanation! > >>> + >>> +    assert(raft->state == RAFT_STATE_FOLLOWER || >>> +           raft->state == RAFT_STATE_CANDIDATE); >>> +    struct ev_loop *loop = raft_loop(); >>> +    struct ev_timer *timer = &raft->timer; >>> +    double delay = raft_new_random_election_shift(raft); >>> +    /* >>> +     * Could be too late to speed up anything - probably the term is almost >>> +     * over anyway. >>> +     */ >>> +    double remaining = raft_ev_timer_remaining(loop, timer); >>> +    if (delay >= remaining) >>> +        delay = remaining; >>> +    say_info("RAFT: split vote is discovered - %s, new term in %lf sec", >>> +         raft_scores_str(raft), delay); >>> +    raft_ev_timer_stop(loop, timer); >>> +    raft_ev_timer_set(timer, delay, delay); >> >> ... >>> diff --git a/test/unit/raft_test_utils.h b/test/unit/raft_test_utils.h >>> index c68dc3b22..2138a829e 100644 >>> --- a/test/unit/raft_test_utils.h >>> +++ b/test/unit/raft_test_utils.h >>> @@ -32,6 +32,7 @@ >>>   #include "fakesys/fakeev.h" >>>   #include "fiber.h" >>>   #include "raft/raft.h" >>> +#include "raft/raft_ev.h" >> Why do you need it here? > The tests now use raft_ev_is_active() which is defined in this header. I > decided to add it here instead of unit/raft.c because the idea of > raft_test_utils.h is, among other things, to do all the boilerplate work > such as necessary inclusions. Ok. > > New version of the commit after the comment from v1 about new raft > members: > > ==================== > raft: introduce split vote detection Thanks for the fixes! LGTM. -- Serge Petrenko