Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org, gorcunov@gmail.com
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v4 13/16] box: allow calling promote on a candidate
Date: Wed, 14 Jul 2021 21:25:41 +0300	[thread overview]
Message-ID: <5e258b337c1314a10440677b583290d94fc4f499.1626287002.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1626287002.git.sergepetrenko@tarantool.org>

Part of #6034
---
 src/box/box.cc                                | 15 +---
 .../gh-6034-election-candidate-promote.result | 84 +++++++++++++++++++
 ...h-6034-election-candidate-promote.test.lua | 42 ++++++++++
 test/replication/suite.cfg                    |  1 +
 4 files changed, 128 insertions(+), 14 deletions(-)
 create mode 100644 test/replication/gh-6034-election-candidate-promote.result
 create mode 100644 test/replication/gh-6034-election-candidate-promote.test.lua

diff --git a/src/box/box.cc b/src/box/box.cc
index 6a534952f..9130fc322 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1717,21 +1717,8 @@ box_promote(void)
 			 "manual elections");
 		return -1;
 	case ELECTION_MODE_MANUAL:
-		if (box_raft()->state == RAFT_STATE_LEADER)
-			return 0;
-		run_elections = true;
-		break;
 	case ELECTION_MODE_CANDIDATE:
-		/*
-		 * Leader elections are enabled, and this instance is allowed to
-		 * promote only if it's already an elected leader. No manual
-		 * elections.
-		 */
-		if (box_raft()->state != RAFT_STATE_LEADER) {
-			diag_set(ClientError, ER_UNSUPPORTED, "election_mode="
-				 "'candidate'", "manual elections");
-			return -1;
-		}
+		run_elections = box_raft()->state != RAFT_STATE_LEADER;
 		break;
 	default:
 		unreachable();
diff --git a/test/replication/gh-6034-election-candidate-promote.result b/test/replication/gh-6034-election-candidate-promote.result
new file mode 100644
index 000000000..76a54d5a6
--- /dev/null
+++ b/test/replication/gh-6034-election-candidate-promote.result
@@ -0,0 +1,84 @@
+-- test-run result file version 2
+test_run = require('test_run').new()
+ | ---
+ | ...
+
+SERVERS = {'election_replica1', 'election_replica2', 'election_replica3'}
+ | ---
+ | ...
+test_run:create_cluster(SERVERS, 'replication')
+ | ---
+ | ...
+test_run:wait_fullmesh(SERVERS)
+ | ---
+ | ...
+is_leader_cmd = 'return box.info.election.state == \'leader\''
+ | ---
+ | ...
+
+test_run:cmd("setopt delimiter ';'")
+ | ---
+ | - true
+ | ...
+function get_leader_nr()
+    local leader_nr = 0
+    test_run:wait_cond(function()
+        for nr = 1,3 do
+            local is_leader = test_run:eval('election_replica'..nr, is_leader_cmd)[1]
+            if is_leader then
+                leader_nr = nr
+                return true
+            end
+        end
+        return false
+    end)
+    return leader_nr
+end;
+ | ---
+ | ...
+test_run:cmd("setopt delimiter ''");
+ | ---
+ | - true
+ | ...
+
+leader_nr = get_leader_nr()
+ | ---
+ | ...
+
+assert(leader_nr ~= 0)
+ | ---
+ | - true
+ | ...
+
+term = test_run:eval('election_replica'..leader_nr,\
+                     'return box.info.election.term')[1]
+ | ---
+ | ...
+
+next_nr = leader_nr % 3 + 1
+ | ---
+ | ...
+-- Someone else may become a leader, thus promote may fail. But we're testing
+-- that it takes effect at all, so that's fine.
+_ = pcall(test_run:eval('election_replica'..next_nr, 'box.ctl.promote()'))
+ | ---
+ | ...
+new_term = test_run:eval('election_replica'..next_nr,\
+                         'return box.info.election.term')[1]
+ | ---
+ | ...
+assert(new_term > term)
+ | ---
+ | - true
+ | ...
+leader_nr = get_leader_nr()
+ | ---
+ | ...
+assert(leader_nr ~= 0)
+ | ---
+ | - true
+ | ...
+
+test_run:drop_cluster(SERVERS)
+ | ---
+ | ...
diff --git a/test/replication/gh-6034-election-candidate-promote.test.lua b/test/replication/gh-6034-election-candidate-promote.test.lua
new file mode 100644
index 000000000..24c57f4cb
--- /dev/null
+++ b/test/replication/gh-6034-election-candidate-promote.test.lua
@@ -0,0 +1,42 @@
+test_run = require('test_run').new()
+
+SERVERS = {'election_replica1', 'election_replica2', 'election_replica3'}
+test_run:create_cluster(SERVERS, 'replication')
+test_run:wait_fullmesh(SERVERS)
+is_leader_cmd = 'return box.info.election.state == \'leader\''
+
+test_run:cmd("setopt delimiter ';'")
+function get_leader_nr()
+    local leader_nr = 0
+    test_run:wait_cond(function()
+        for nr = 1,3 do
+            local is_leader = test_run:eval('election_replica'..nr, is_leader_cmd)[1]
+            if is_leader then
+                leader_nr = nr
+                return true
+            end
+        end
+        return false
+    end)
+    return leader_nr
+end;
+test_run:cmd("setopt delimiter ''");
+
+leader_nr = get_leader_nr()
+
+assert(leader_nr ~= 0)
+
+term = test_run:eval('election_replica'..leader_nr,\
+                     'return box.info.election.term')[1]
+
+next_nr = leader_nr % 3 + 1
+-- Someone else may become a leader, thus promote may fail. But we're testing
+-- that it takes effect at all, so that's fine.
+_ = pcall(test_run:eval('election_replica'..next_nr, 'box.ctl.promote()'))
+new_term = test_run:eval('election_replica'..next_nr,\
+                         'return box.info.election.term')[1]
+assert(new_term > term)
+leader_nr = get_leader_nr()
+assert(leader_nr ~= 0)
+
+test_run:drop_cluster(SERVERS)
diff --git a/test/replication/suite.cfg b/test/replication/suite.cfg
index 8b2204e2a..6f42db081 100644
--- a/test/replication/suite.cfg
+++ b/test/replication/suite.cfg
@@ -53,6 +53,7 @@
     "gh-6057-qsync-confirm-async-no-wal.test.lua": {},
     "gh-6094-rs-uuid-mismatch.test.lua": {},
     "gh-6127-election-join-new.test.lua": {},
+    "gh-6034-election-candidate-promote.test.lua": {},
     "gh-6035-applier-filter.test.lua": {},
     "*": {
         "memtx": {"engine": "memtx"},
-- 
2.30.1 (Apple Git-130)


  parent reply	other threads:[~2021-07-14 18:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 18:25 [Tarantool-patches] [PATCH v4 00/16] forbid implicit limbo ownership transition Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 01/16] replication: always send raft state to subscribers Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 02/16] txn_limbo: fix promote term filtering Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 03/16] txn_limbo: persist the latest effective promote in snapshot Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 04/16] replication: encode version in JOIN request Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 05/16] replication: add META stage to JOIN Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 06/16] replication: send latest effective promote in initial join Serge Petrenko via Tarantool-patches
2021-07-21 23:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:44     ` Sergey Petrenko via Tarantool-patches
2021-07-26 23:43       ` Vladislav Shpilevoy via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 07/16] replication: send current Raft term in join response Serge Petrenko via Tarantool-patches
2021-07-21 23:24   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:44     ` Sergey Petrenko via Tarantool-patches
2021-07-26 23:43       ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 20:46         ` Sergey Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 08/16] raft: refactor raft_new_term() Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 09/16] box: split promote() into reasonable parts Serge Petrenko via Tarantool-patches
2021-07-21 23:26   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:45     ` Sergey Petrenko via Tarantool-patches
2021-07-26 23:44       ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 20:46         ` Sergey Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 10/16] box: make promote always bump the term Serge Petrenko via Tarantool-patches
2021-07-26 23:45   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 20:46     ` Sergey Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 11/16] box: make promote on the current leader a no-op Serge Petrenko via Tarantool-patches
2021-07-21 23:26   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:45     ` Sergey Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 12/16] box: fix an assertion failure after a spurious wakeup in promote Serge Petrenko via Tarantool-patches
2021-07-21 23:29   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23  7:45     ` Sergey Petrenko via Tarantool-patches
2021-07-14 18:25 ` Serge Petrenko via Tarantool-patches [this message]
2021-07-15 14:06   ` [Tarantool-patches] [PATCH v4 13/16] box: allow calling promote on a candidate Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 14/16] box: extract promote() settings to a separate method Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 15/16] replication: forbid implicit limbo owner transition Serge Petrenko via Tarantool-patches
2021-07-14 18:25 ` [Tarantool-patches] [PATCH v4 16/16] box: introduce `box.ctl.demote` Serge Petrenko via Tarantool-patches
2021-07-15 17:13   ` Serge Petrenko via Tarantool-patches
2021-07-15 20:11   ` [Tarantool-patches] [PATCH v4 17/16] replication: fix flaky election_qsync.test Serge Petrenko via Tarantool-patches
2021-07-26 23:43 ` [Tarantool-patches] [PATCH v4 00/16] forbid implicit limbo ownership transition Vladislav Shpilevoy via Tarantool-patches
2021-07-29 20:47   ` Sergey Petrenko 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=5e258b337c1314a10440677b583290d94fc4f499.1626287002.git.sergepetrenko@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v4 13/16] box: allow calling promote on a candidate' \
    /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