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 275C06E201; Fri, 18 Jun 2021 00:10:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 275C06E201 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623964246; bh=SO3ygtSEJfgY+hPm8e8qDBlysD3WJ10MGWt2dcNH9ro=; 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=OWSGaGgGOdFjXhwNGGKKH/OGwWiKZU65XWEsRmW2pujegcJZ5DaMeBQ0YXaA1zYAS +CWX5hZECDwdmawbujZOfCFNzLWieec8BmuyIFVYvIfshpxvN81IHezGLrIjdkVGVe 3bqTY5NT4qNaa+LVhb6DlKcrSSaVoysitz7uiWUw= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (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 557756E202 for ; Fri, 18 Jun 2021 00:08:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 557756E202 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1ltzFj-00046o-Kn; Fri, 18 Jun 2021 00:08:44 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Fri, 18 Jun 2021 00:07:38 +0300 Message-Id: <3c7254027e2fd344ba1fa4cbfd4f2f537ce72fd6.1623963649.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: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD91C2C07775F13263A48BAE59A842244EB7433BA0B4B73D52900894C459B0CD1B95C9CBFFE42D5B9D983B4E4AD322FFC797FF79ED123BE076CE56FC18614CB2959 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77DA205A7C6971420C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7747FD4AFDBA6C67AEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BD6CF32B5F8F9D40456E19858BE1F2498B6E2F7376624F032CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8EDCF5861DED71B2F389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F79006376A9E655210F73848D81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE752BFC73057FA81B4EC76A7562686271EEC990983EF5C03292E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C34B08FA16E56A400835872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD7067FEF890167A548C312CBAE3E303E3 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C2C9C2AE8C25C43DD2EDDC17D7D35AC9F7D20C3CD58B843CE9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFD99FB7B2A39B4961699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3447DF5779098ECEE92958A558CF295302E6B1A9B5A625B699F1D02EBA465D9ADF5AD9F705308D07CC1D7E09C32AA3244C110E3E8862AF0F2C3157C5CA616B92244DBEAD0ED6C55A80927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjymZAW17GbhHLFlKq0Co0w X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A18ACA3F9016771417D65058D89133B0A79ECB9C90B2EBC74424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 4/8] box: make promote always bump the term 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" When called without elections, promote and resulted in multiple PROMOTE entries for the same term. This is not right, because all the promotions for the same term except the first one would be ignored as already seen. Part-of #6034 --- src/box/box.cc | 10 +++-- .../gh-4114-local-space-replication.result | 7 ++-- .../gh-4114-local-space-replication.test.lua | 4 +- .../gh-6034-promote-bump-term.result | 37 +++++++++++++++++++ .../gh-6034-promote-bump-term.test.lua | 16 ++++++++ test/replication/suite.cfg | 1 + 6 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 test/replication/gh-6034-promote-bump-term.result create mode 100644 test/replication/gh-6034-promote-bump-term.test.lua diff --git a/src/box/box.cc b/src/box/box.cc index 6a0950f44..53a8f80e5 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1687,16 +1687,18 @@ box_promote(void) rc = -1; } else { promote: - /* We cannot possibly get here in a volatile state. */ - assert(box_raft()->volatile_term == box_raft()->term); + if (try_wait) + raft_new_term(box_raft()); + + uint64_t term = box_raft()->volatile_term; txn_limbo_write_promote(&txn_limbo, wait_lsn, - box_raft()->term); + term); struct synchro_request req = { .type = IPROTO_PROMOTE, .replica_id = former_leader_id, .origin_id = instance_id, .lsn = wait_lsn, - .term = box_raft()->term, + .term = term, }; txn_limbo_process(&txn_limbo, &req); assert(txn_limbo_is_empty(&txn_limbo)); diff --git a/test/replication/gh-4114-local-space-replication.result b/test/replication/gh-4114-local-space-replication.result index 9b63a4b99..676400cef 100644 --- a/test/replication/gh-4114-local-space-replication.result +++ b/test/replication/gh-4114-local-space-replication.result @@ -45,9 +45,8 @@ test_run:cmd('switch replica') | --- | - true | ... -box.info.vclock[0] +a = box.info.vclock[0] or 0 | --- - | - null | ... box.cfg{checkpoint_count=1} | --- @@ -77,9 +76,9 @@ box.space.test:insert{3} | - [3] | ... -box.info.vclock[0] +box.info.vclock[0] == a + 3 or box.info.vclock[0] - a | --- - | - 3 + | - true | ... test_run:cmd('switch default') diff --git a/test/replication/gh-4114-local-space-replication.test.lua b/test/replication/gh-4114-local-space-replication.test.lua index c18fb3b10..8f787db84 100644 --- a/test/replication/gh-4114-local-space-replication.test.lua +++ b/test/replication/gh-4114-local-space-replication.test.lua @@ -18,7 +18,7 @@ for i = 1,10 do box.space.test:insert{i} end box.info.vclock[0] == a + 10 or box.info.vclock[0] - a test_run:cmd('switch replica') -box.info.vclock[0] +a = box.info.vclock[0] or 0 box.cfg{checkpoint_count=1} box.space.test:select{} box.space.test:insert{1} @@ -27,7 +27,7 @@ box.space.test:insert{2} box.snapshot() box.space.test:insert{3} -box.info.vclock[0] +box.info.vclock[0] == a + 3 or box.info.vclock[0] - a test_run:cmd('switch default') diff --git a/test/replication/gh-6034-promote-bump-term.result b/test/replication/gh-6034-promote-bump-term.result new file mode 100644 index 000000000..20e352922 --- /dev/null +++ b/test/replication/gh-6034-promote-bump-term.result @@ -0,0 +1,37 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... + +-- gh-6034: test that every box.ctl.promote() bumps +-- the instance's term. Even when elections are disabled. Even for consequent +-- promotes on the same instance. +election_mode = box.cfg.election_mode + | --- + | ... +box.cfg{election_mode='off'} + | --- + | ... + +term = box.info.election.term + | --- + | ... +box.ctl.promote() + | --- + | ... +assert(box.info.election.term == term + 1) + | --- + | - true + | ... +box.ctl.promote() + | --- + | ... +assert(box.info.election.term == term + 2) + | --- + | - true + | ... + +-- Cleanup. +box.cfg{election_mode=election_mode} + | --- + | ... diff --git a/test/replication/gh-6034-promote-bump-term.test.lua b/test/replication/gh-6034-promote-bump-term.test.lua new file mode 100644 index 000000000..5847dbb8f --- /dev/null +++ b/test/replication/gh-6034-promote-bump-term.test.lua @@ -0,0 +1,16 @@ +test_run = require('test_run').new() + +-- gh-6034: test that every box.ctl.promote() bumps +-- the instance's term. Even when elections are disabled. Even for consequent +-- promotes on the same instance. +election_mode = box.cfg.election_mode +box.cfg{election_mode='off'} + +term = box.info.election.term +box.ctl.promote() +assert(box.info.election.term == term + 1) +box.ctl.promote() +assert(box.info.election.term == term + 2) + +-- Cleanup. +box.cfg{election_mode=election_mode} diff --git a/test/replication/suite.cfg b/test/replication/suite.cfg index b0f275526..4fc6643e4 100644 --- a/test/replication/suite.cfg +++ b/test/replication/suite.cfg @@ -48,6 +48,7 @@ "gh-5613-bootstrap-prefer-booted.test.lua": {}, "gh-6027-applier-error-show.test.lua": {}, "gh-6032-promote-wal-write.test.lua": {}, + "gh-6034-promote-bump-term.test.lua": {}, "gh-6057-qsync-confirm-async-no-wal.test.lua": {}, "gh-6094-rs-uuid-mismatch.test.lua": {}, "gh-6127-election-join-new.test.lua": {}, -- 2.30.1 (Apple Git-130)