[Tarantool-patches] [PATCH v4 08/16] raft: refactor raft_new_term()
Serge Petrenko
sergepetrenko at tarantool.org
Wed Jul 14 21:25:36 MSK 2021
Make raft_new_term() always bump the current term, even when Raft is
disabled.
Part-of #6034
---
src/box/box.cc | 2 +-
src/lib/raft/raft.c | 3 +--
test/unit/raft.c | 15 ++++++++++++++-
test/unit/raft.result | 3 ++-
4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/box/box.cc b/src/box/box.cc
index 8c695686e..86370514a 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -3513,7 +3513,7 @@ box_cfg_xc(void)
if (!is_bootstrap_leader) {
replicaset_sync();
- } else {
+ } else if (raft_is_enabled(box_raft())) {
/*
* When the cluster is just bootstrapped and this instance is a
* leader, it makes no sense to wait for a leader appearance.
diff --git a/src/lib/raft/raft.c b/src/lib/raft/raft.c
index ef11ef89f..22f38b330 100644
--- a/src/lib/raft/raft.c
+++ b/src/lib/raft/raft.c
@@ -988,8 +988,7 @@ raft_cfg_vclock(struct raft *raft, const struct vclock *vclock)
void
raft_new_term(struct raft *raft)
{
- if (raft->is_enabled)
- raft_sm_schedule_new_term(raft, raft->volatile_term + 1);
+ raft_sm_schedule_new_term(raft, raft->volatile_term + 1);
}
static void
diff --git a/test/unit/raft.c b/test/unit/raft.c
index b9bc49b78..9637abf43 100644
--- a/test/unit/raft.c
+++ b/test/unit/raft.c
@@ -1184,7 +1184,7 @@ raft_test_death_timeout(void)
static void
raft_test_enable_disable(void)
{
- raft_start_test(10);
+ raft_start_test(11);
struct raft_node node;
raft_node_create(&node);
@@ -1276,7 +1276,20 @@ raft_test_enable_disable(void)
"{0: 2}" /* Vclock. */
), "nothing changed");
+ /* Disabled node still bumps the term when needed. */
+ raft_node_new_term(&node);
+
+ ok(raft_node_check_full_state(&node,
+ RAFT_STATE_FOLLOWER /* State. */,
+ 0 /* Leader. */,
+ 4 /* Term. */,
+ 0 /* Vote. */,
+ 4 /* Volatile term. */,
+ 0 /* Volatile vote. */,
+ "{0: 3}" /* Vclock. */
+ ), "term bump when disabled");
raft_node_destroy(&node);
+
raft_finish_test();
}
diff --git a/test/unit/raft.result b/test/unit/raft.result
index f89cd1658..41463db69 100644
--- a/test/unit/raft.result
+++ b/test/unit/raft.result
@@ -205,7 +205,7 @@ ok 10 - subtests
ok 11 - subtests
*** raft_test_death_timeout: done ***
*** raft_test_enable_disable ***
- 1..10
+ 1..11
ok 1 - accepted a leader notification
ok 2 - leader is seen
ok 3 - death timeout passed
@@ -216,6 +216,7 @@ ok 11 - subtests
ok 8 - became leader
ok 9 - resigned from leader state
ok 10 - nothing changed
+ ok 11 - term bump when disabled
ok 12 - subtests
*** raft_test_enable_disable: done ***
*** raft_test_too_long_wal_write ***
--
2.30.1 (Apple Git-130)
More information about the Tarantool-patches
mailing list