From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Konstantin Belyavskiy Subject: [PATCH] replication: fix bug with zero replication_connect_quorum Date: Mon, 9 Apr 2018 11:04:04 +0300 Message-Id: <20180409080404.9844-1-k.belyavskiy@tarantool.org> To: vdavydov@tarantool.org, georgy@tarantool.org Cc: tarantool-patches@freelists.org List-ID: If 'box.cfg.read_only' is false, 'replication' defines at least one replica (other than itself), but they are not available at the time of box.cfg execution and replication_connect_quorum is set to zero, master displays 'orphan' status instead of 'running' since logic which cnange this state is executed only after successfull connection. ticket: https://github.com/tarantool/tarantool/issues/3278 branch: https://github.com/tarantool/tarantool/compare/gh-3278-fix-bug-with-zero-replication-connect-quorum Closes #3278 --- src/box/replication.cc | 8 ++++-- test/replication/quorum.result | 52 +++++++++++++++++++++++++++++++++++++ test/replication/quorum.test.lua | 25 ++++++++++++++++++ test/replication/replica_params.lua | 23 ++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 test/replication/replica_params.lua diff --git a/src/box/replication.cc b/src/box/replication.cc index b1c84d36c..760f83751 100644 --- a/src/box/replication.cc +++ b/src/box/replication.cc @@ -600,8 +600,12 @@ error: void replicaset_follow(void) { - if (replicaset.applier.total == 0) { - /* Replication is not configured. */ + if (replicaset.applier.total == 0 || replicaset_quorum() == 0) { + /* + * Replication is not configured or quorum is set to + * zero so in the latter case we have no need to wait + * for others. + */ box_clear_orphan(); return; } diff --git a/test/replication/quorum.result b/test/replication/quorum.result index 34408d421..78d98bfa2 100644 --- a/test/replication/quorum.result +++ b/test/replication/quorum.result @@ -239,3 +239,55 @@ test_run:cmd('switch default') test_run:drop_cluster(SERVERS) --- ... +-- +-- gh-3278: test different replication and replication_connect_quorum configs. +-- +-- For next test try to find port with no tarantool running on it. +remote = require('net.box') +--- +... +attempt = 0 +--- +... +port = 32768 + math.random(32768) +--- +... +test_run:cmd("setopt delimiter ';'") +--- +- true +... +while attempt < 10 do + s = remote.connect('localhost:'..port) + if s.state ~= 'error' then + port = 32768 + math.random(32768) + attempt = attempt + 1 + else + break + end +end; +--- +... +test_run:cmd("setopt delimiter ''"); +--- +- true +... +test_run:cmd("create server replica with rpl_master=default, script='replication/replica_params.lua'") +--- +- true +... +test_run:cmd("start server replica with args='0 0 "..port.."'") +--- +- true +... +test_run:cmd("restart server replica with args='0 1 "..port.."'") +--- +- true +... +test_run:cmd('switch replica') +--- +- true +... +box.info.status -- running (old: orphan) +--- +- running +... diff --git a/test/replication/quorum.test.lua b/test/replication/quorum.test.lua index 856006843..d92ed23a6 100644 --- a/test/replication/quorum.test.lua +++ b/test/replication/quorum.test.lua @@ -97,3 +97,28 @@ box.info.replication[4].upstream.status -- Cleanup. test_run:cmd('switch default') test_run:drop_cluster(SERVERS) + +-- +-- gh-3278: test different replication and replication_connect_quorum configs. +-- + +-- For next test try to find port with no tarantool running on it. +remote = require('net.box') +attempt = 0 +port = 32768 + math.random(32768) +test_run:cmd("setopt delimiter ';'") +while attempt < 10 do + s = remote.connect('localhost:'..port) + if s.state ~= 'error' then + port = 32768 + math.random(32768) + attempt = attempt + 1 + else + break + end +end; +test_run:cmd("setopt delimiter ''"); +test_run:cmd("create server replica with rpl_master=default, script='replication/replica_params.lua'") +test_run:cmd("start server replica with args='0 0 "..port.."'") +test_run:cmd("restart server replica with args='0 1 "..port.."'") +test_run:cmd('switch replica') +box.info.status -- running (old: orphan) diff --git a/test/replication/replica_params.lua b/test/replication/replica_params.lua new file mode 100644 index 000000000..4f8ee5d0a --- /dev/null +++ b/test/replication/replica_params.lua @@ -0,0 +1,23 @@ +#!/usr/bin/env tarantool + +local quorum = tonumber(arg[1]) +local n_replics = tonumber(arg[2]) +local addr = '127.0.0.1:'..arg[3] +listen = os.getenv("LISTEN") +-- Test different replicaset configurations: +-- First, when the only address in the replicaset is itself. +repl = {} +-- To test situation with second master unavailable, add +-- second address (should be empty). +if n_replics == 1 then repl = { addr } end +if n_replics == 2 then repl = { listen, addr } end + +box.cfg({ + listen = listen, + replication = repl, + memtx_memory = 100 * 1024 * 1024, + replication_connect_quorum = quorum, + replication_connect_timeout = 0.1, +}) + +require('console').listen(os.getenv('ADMIN')) -- 2.14.3 (Apple Git-98)