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 0CAF06EC55; Thu, 10 Jun 2021 16:33:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0CAF06EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623332014; bh=AuR6J2QUtEUt48opSoKyKogbUenfmpoLbMTMRWxrnhk=; 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=LOnEtwm/YSSfkS2h+xfO+kol4X10IqXiQgRaWJIXxOzQIxNGq4h+SOExq87rhMJ0/ pRw3xxaU98G4GR5LC0mdPYEcTcSxDfDW7zpMxhwFTYGodRJo7xcmrVrgqxtH9whejg QQnJt/0roqT2OsZZpzaGk6GJuOifLmx73sE0yLnw= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 A76EB6EC55 for ; Thu, 10 Jun 2021 16:33:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A76EB6EC55 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1lrKnt-0007EB-LU; Thu, 10 Jun 2021 16:33:02 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Thu, 10 Jun 2021 16:32:51 +0300 Message-Id: X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C5407454A95E60932C8E3171F0D0805CD56182A05F538085040C669F21B1AA29DEAF1A2B4BF541B104801894D1483730C30B5EB4FB41C78B7CA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B68FC8E74235BE2BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D7F1BE85E7B0CA818638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89C76217B59728F066738220A0B9E8CBB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE902A1BE408319B296E0066C2D8992A164AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3C88F76A0D5822D73BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE732FCE54C4D9A645443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FCFC014AD2D9E6C96F3C5ED81AB010F9DF1C7FCEA2B08377AAB1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBAB5495298CADBD05DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C1E32F4AD4B2486BD684C9BFB5A6F666E0837706A19CE09333BDF839ADE32359B6D72A5DA79B0B631D7E09C32AA3244CB8501827AADF2B2C7BE056EB7FF7229F408A6A02710B7304927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiiA81jxGMgNhgvgye/CVOu X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A7C268FF7D9159348AF54FE6BBBB3F91372AC3FD2AE4CE171424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/7] replication: always send raft state to subscribers 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" Tarantool used to send out raft state on subscribe only when raft was enabled. This was a safeguard against partially-upgraded clusters, where some nodes had no clue about Raft messages and couldn't handle them properly. Actually, Raft state should be sent out always. For example, promote bumps Raft term, even when raft is disabled, and it's important that everyone in cluster has the same term, for the sake of promote at least. So, send out Raft state to every subscriber with version >= 2.6.0 (that's when Raft was introduced). Closes #5438 --- src/box/box.cc | 11 +-- test/replication/gh-5438-raft-state.result | 73 ++++++++++++++++++++ test/replication/gh-5438-raft-state.test.lua | 30 ++++++++ test/replication/suite.cfg | 1 + 4 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 test/replication/gh-5438-raft-state.result create mode 100644 test/replication/gh-5438-raft-state.test.lua diff --git a/src/box/box.cc b/src/box/box.cc index 6dc991dc8..b9f3fab32 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -82,6 +82,7 @@ #include "msgpack.h" #include "raft.h" #include "trivia/util.h" +#include "version.h" static char status[64] = "unknown"; @@ -2811,13 +2812,13 @@ box_process_subscribe(struct ev_io *io, struct xrow_header *header) tt_uuid_str(&replica_uuid), sio_socketname(io->fd)); say_info("remote vclock %s local vclock %s", vclock_to_string(&replica_clock), vclock_to_string(&vclock)); - if (raft_is_enabled(box_raft())) { + if (replica_version_id >= version_id(2, 6, 0) && !anon) { /* * Send out the current raft state of the instance. Don't do - * that if Raft is disabled. It can be that a part of the - * cluster still contains old versions, which can't handle Raft - * messages. So when it is disabled, its network footprint - * should be 0. + * that if the remote instance is old. It can be that a part of + * the cluster still contains old versions, which can't handle + * Raft messages. Raft's network footprint should be 0 as seen + * by such instances. */ struct raft_request req; box_raft_checkpoint_remote(&req); diff --git a/test/replication/gh-5438-raft-state.result b/test/replication/gh-5438-raft-state.result new file mode 100644 index 000000000..7982796a8 --- /dev/null +++ b/test/replication/gh-5438-raft-state.result @@ -0,0 +1,73 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... + +-- +-- gh-5428 send out Raft state to subscribers, even when Raft is disabled. +-- +box.schema.user.grant('guest', 'replication') + | --- + | ... +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica') + | --- + | - true + | ... +test_run:wait_lsn('replica', 'default') + | --- + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... + +-- Bump Raft term while the replica's offline. +term = box.info.election.term + | --- + | ... +old_election_mode = box.cfg.election_mode + | --- + | ... +box.cfg{election_mode = 'candidate'} + | --- + | ... +test_run:wait_cond(function() return box.info.election.term > term end) + | --- + | - true + | ... + +-- Make sure the replica receives new term on resubscribe. +box.cfg{election_mode = 'off'} + | --- + | ... +test_run:cmd('start server replica') + | --- + | - true + | ... +test_run:wait_cond(function()\ + return test_run:eval('replica', 'return box.info.election.term')[1] ==\ + box.info.election.term\ +end) + | --- + | - true + | ... +-- Cleanup. +box.cfg{election_mode = old_election_mode} + | --- + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... +box.schema.user.revoke('guest', 'replication') + | --- + | ... diff --git a/test/replication/gh-5438-raft-state.test.lua b/test/replication/gh-5438-raft-state.test.lua new file mode 100644 index 000000000..179f4b1c9 --- /dev/null +++ b/test/replication/gh-5438-raft-state.test.lua @@ -0,0 +1,30 @@ +test_run = require('test_run').new() + +-- +-- gh-5428 send out Raft state to subscribers, even when Raft is disabled. +-- +box.schema.user.grant('guest', 'replication') +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') +test_run:cmd('start server replica') +test_run:wait_lsn('replica', 'default') +test_run:cmd('stop server replica') + +-- Bump Raft term while the replica's offline. +term = box.info.election.term +old_election_mode = box.cfg.election_mode +box.cfg{election_mode = 'candidate'} +test_run:wait_cond(function() return box.info.election.term > term end) + +-- Make sure the replica receives new term on resubscribe. +box.cfg{election_mode = 'off'} +test_run:cmd('start server replica') +test_run:wait_cond(function()\ + return test_run:eval('replica', 'return box.info.election.term')[1] ==\ + box.info.election.term\ +end) +-- Cleanup. +box.cfg{election_mode = old_election_mode} +test_run:cmd('stop server replica') +test_run:cmd('delete server replica') +box.schema.user.revoke('guest', 'replication') diff --git a/test/replication/suite.cfg b/test/replication/suite.cfg index 27eab20c2..46de2e6c4 100644 --- a/test/replication/suite.cfg +++ b/test/replication/suite.cfg @@ -19,6 +19,7 @@ "gh-5213-qsync-applier-order-3.test.lua": {}, "gh-5426-election-on-off.test.lua": {}, "gh-5433-election-restart-recovery.test.lua": {}, + "gh-5438-raft-state.test.lua": {}, "gh-5445-leader-inconsistency.test.lua": {}, "gh-5506-election-on-off.test.lua": {}, "once.test.lua": {}, -- 2.30.1 (Apple Git-130)