Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 4/5] raft: introduce split vote detection
Date: Tue, 25 Jan 2022 13:17:52 +0300	[thread overview]
Message-ID: <3caf820d-9e60-0eb4-188d-33abbcb25721@tarantool.org> (raw)
In-Reply-To: <71e416b7-3532-897d-a49b-0dcb925a88f6@tarantool.org>



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


  reply	other threads:[~2022-01-25 10:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  0:43 [Tarantool-patches] [PATCH v2 0/5] Split vote and bugs Vladislav Shpilevoy via Tarantool-patches
2022-01-20  0:43 ` [Tarantool-patches] [PATCH v2 1/5] raft: fix crash on election_timeout reconfig Vladislav Shpilevoy via Tarantool-patches
2022-01-20  0:43 ` [Tarantool-patches] [PATCH v2 2/5] raft: fix ev_timer.at incorrect usage Vladislav Shpilevoy via Tarantool-patches
2022-01-20  0:43 ` [Tarantool-patches] [PATCH v2 3/5] raft: track all votes, even not own Vladislav Shpilevoy via Tarantool-patches
2022-01-20  0:43 ` [Tarantool-patches] [PATCH v2 4/5] raft: introduce split vote detection Vladislav Shpilevoy via Tarantool-patches
2022-01-20 13:22   ` Serge Petrenko via Tarantool-patches
2022-01-20 23:02     ` Vladislav Shpilevoy via Tarantool-patches
2022-01-25 10:17       ` Serge Petrenko via Tarantool-patches [this message]
2022-01-20  0:43 ` [Tarantool-patches] [PATCH v2 5/5] election: activate raft split vote handling Vladislav Shpilevoy via Tarantool-patches
2022-01-25 10:18 ` [Tarantool-patches] [PATCH v2 0/5] Split vote and bugs Serge Petrenko via Tarantool-patches
2022-01-25 22:51 ` Vladislav Shpilevoy via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3caf820d-9e60-0eb4-188d-33abbcb25721@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 4/5] raft: introduce split vote detection' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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