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 AC7B76EC5C; Wed, 14 Jul 2021 21:32:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AC7B76EC5C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626287546; bh=DLVaKg0MeHjGeI5WkjNUUlyeEyw02fO84p3R1u7J8xA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=glqSKBohs+zZERX80hsfoh/vpo7IeyojCePtFT5eH71WScfThTapdwWReklgxbea8 2lHtzZrpgiK16TELgjS3poHvRHWRMZAYa2hKYpKeVNMpD9rjWhWSxKd6KSDZm0mH2N PowL+RzyXbCtFNlwrv41Ahg8c30beeijPzBpnuEQ= Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [217.69.128.38]) (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 5417F6F3D0 for ; Wed, 14 Jul 2021 21:26:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5417F6F3D0 Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1m3jaF-0007Q7-KK; Wed, 14 Jul 2021 21:26:12 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Wed, 14 Jul 2021 21:25:41 +0300 Message-Id: <5e258b337c1314a10440677b583290d94fc4f499.1626287002.git.sergepetrenko@tarantool.org> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D54F26E6113A59F95A22EFF9DCA932A94B182A05F5380850404A78CDFD532CE55E8622EB6A22898BF0837FCCD63B30047FA11924105D8999B1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7648F5E4671A60CF6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374ECA27954A00B6C3EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2FD713620EA0B1B7290937071FE64396BCC7F00164DA146DAFE8445B8C89999728AA50765F7900637F6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B81DF583BEE9BDE68EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CE68746B1F2AB10C6275D2AE5E8002DA3F4296C4DF177D0169C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF309DFB797F6729CB699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53592357E8057735155ACEF072E25A15EC1219B91FA1BE31C1467CDF719AEAC7A0C20454E5924DD1D7E09C32AA3244C37E568F593D34AE94B8939AAF85391C055E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojDdSFIg49M1SnG2hi2lLjWQ== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A446DCF67A6ACA5D040D8D96EB08830C837CD34B31F94090839A424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 13/16] box: allow calling promote on a candidate 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 Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)