[Tarantool-patches] [PATCH v4 09/12] raft: introduce raft_start/stop_candidate
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Apr 17 01:23:00 MSK 2021
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();
> }
More information about the Tarantool-patches
mailing list