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 8367D6EC55; Fri, 30 Jul 2021 14:38:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8367D6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627645095; bh=VEWPtsTz2HmDb9UqsKj49xk8EOnIRCOXHwfk30Bo4Hs=; 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=f28ffMtMTwwGFSmtQ2Vtpvmvioytnf71GNNx0EmbIEFemjM0S+QuOziYe5+VJlJMR 9In1gySdXlgR4jRtP9TFxvoslpoAs3QMbHfUzL2q40bOQ0k2MS8Lu1qNvKWZhdW5YX idDYJrnCMoz9JtVKXyD2iJK2vmwJI3Dc76fj1tkI= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 27DF96EC56 for ; Fri, 30 Jul 2021 14:36:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 27DF96EC56 Received: by mail-lf1-f46.google.com with SMTP id h2so17331707lfu.4 for ; Fri, 30 Jul 2021 04:36:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+fHNQC7AsTeqjf61feDb5/J19k7gUTnhyLPO2lbYgc=; b=oP2qVvZsYHfsg82kyNl5yRD6G7j97a+ff81U/YCXX+kbEkIBWBGXT1iivlaJbP9q5W wt+QzQUwWvQ/sVCZpLGPXftIjTr4LbsQcyxZij2bu5888sUjaOUHWyvru9GovIZcUZSK /OeWqBdqOLW/Y/XPo6hjQNquJnLoBSEG4IVlWKWA35Qw30BWRrDTeYiM/VV9ICEHZjuA ObzVB+/Wz9PbMBeLpt7EXkBGNAvBuXkreWeDJDEAuq8CwkLQFQ11uAdnfrKISrBPjcab wplD1tKcT7MdKYlqYtQavKkJb7Jc5rGj4wuFxLt1tmrXUJfgtddIodhPqV6d+pZcdCp5 tVfw== X-Gm-Message-State: AOAM530XbrrYrWYB3SlPhUbjEwBb5HBD0bZG7s0bvbiCd4XvYscTV9PZ eHa2qpNaafmxMLijNheW9ASltzPd+MHrhQ== X-Google-Smtp-Source: ABdhPJyKAqe26NFNT6DCGRkQmvMITM/gfp2SpjEEZGhXxzEva+44UJtwiuENGVmut2Z5M3dmcxP5QA== X-Received: by 2002:a05:6512:3b0:: with SMTP id v16mr1601429lfp.224.1627645001067; Fri, 30 Jul 2021 04:36:41 -0700 (PDT) Received: from grain.localdomain ([5.18.255.97]) by smtp.gmail.com with ESMTPSA id i11sm127705lfe.215.2021.07.30.04.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 04:36:40 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 3EA1D5A0023; Fri, 30 Jul 2021 14:35:41 +0300 (MSK) To: tml Date: Fri, 30 Jul 2021 14:35:39 +0300 Message-Id: <20210730113539.563318-6-gorcunov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210730113539.563318-1-gorcunov@gmail.com> References: <20210730113539.563318-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v9 5/5] test: add replication/gh-6036-rollback-confirm 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Follow-up #6036 Signed-off-by: Cyrill Gorcunov --- test/replication/gh-6036-master.lua | 1 + test/replication/gh-6036-node.lua | 33 ++++ test/replication/gh-6036-replica.lua | 1 + .../gh-6036-rollback-confirm.result | 180 ++++++++++++++++++ .../gh-6036-rollback-confirm.test.lua | 92 +++++++++ 5 files changed, 307 insertions(+) create mode 120000 test/replication/gh-6036-master.lua create mode 100644 test/replication/gh-6036-node.lua create mode 120000 test/replication/gh-6036-replica.lua create mode 100644 test/replication/gh-6036-rollback-confirm.result create mode 100644 test/replication/gh-6036-rollback-confirm.test.lua diff --git a/test/replication/gh-6036-master.lua b/test/replication/gh-6036-master.lua new file mode 120000 index 000000000..65baed5de --- /dev/null +++ b/test/replication/gh-6036-master.lua @@ -0,0 +1 @@ +gh-6036-node.lua \ No newline at end of file diff --git a/test/replication/gh-6036-node.lua b/test/replication/gh-6036-node.lua new file mode 100644 index 000000000..ac701b7a2 --- /dev/null +++ b/test/replication/gh-6036-node.lua @@ -0,0 +1,33 @@ +local INSTANCE_ID = string.match(arg[0], "gh%-6036%-(.+)%.lua") + +local function unix_socket(name) + return "unix/:./" .. name .. '.sock'; +end + +require('console').listen(os.getenv('ADMIN')) + +if INSTANCE_ID == "master" then + box.cfg({ + listen = unix_socket("master"), + replication_connect_quorum = 0, + election_mode = 'candidate', + replication_synchro_quorum = 3, + replication_synchro_timeout = 1000, + }) +elseif INSTANCE_ID == "replica" then + box.cfg({ + listen = unix_socket("replica"), + replication = { + unix_socket("master"), + unix_socket("replica") + }, + read_only = true, + election_mode = 'voter', + replication_synchro_quorum = 2, + replication_synchro_timeout = 1000, + }) +end + +box.once("bootstrap", function() + box.schema.user.grant('guest', 'super') +end) diff --git a/test/replication/gh-6036-replica.lua b/test/replication/gh-6036-replica.lua new file mode 120000 index 000000000..65baed5de --- /dev/null +++ b/test/replication/gh-6036-replica.lua @@ -0,0 +1 @@ +gh-6036-node.lua \ No newline at end of file diff --git a/test/replication/gh-6036-rollback-confirm.result b/test/replication/gh-6036-rollback-confirm.result new file mode 100644 index 000000000..27419ce21 --- /dev/null +++ b/test/replication/gh-6036-rollback-confirm.result @@ -0,0 +1,180 @@ +-- test-run result file version 2 +-- +-- gh-6036: Test for record collision detection. We have a cluster +-- of two nodes: master and replica. The master initiates syncho write +-- but fails to gather a quorum. Before it rolls back the record the +-- network breakage occurs and replica lives with dirty data while +-- master node goes offline. The replica becomes a new raft leader +-- and commits the dirty data, same time master node rolls back this +-- record and tries to connect to the new raft leader back. Such +-- connection should be refused because old master node is not longer +-- consistent. +-- +test_run = require('test_run').new() + | --- + | ... + +test_run:cmd('create server master with script="replication/gh-6036-master.lua"') + | --- + | - true + | ... +test_run:cmd('create server replica with script="replication/gh-6036-replica.lua"') + | --- + | - true + | ... + +test_run:cmd('start server master') + | --- + | - true + | ... +test_run:cmd('start server replica') + | --- + | - true + | ... + +-- +-- Connect master to the replica and write a record. Since the quorum +-- value is bigger than number of nodes in a cluster it will be rolled +-- back later. +test_run:switch('master') + | --- + | - true + | ... +box.cfg({ \ + replication = { \ + "unix/:./master.sock", \ + "unix/:./replica.sock", \ + }, \ +}) + | --- + | ... +_ = box.schema.create_space('sync', {is_sync = true}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... + +-- +-- Wait the record to appear on the master. +f = require('fiber').create(function() box.space.sync:replace{1} end) + | --- + | ... +test_run:wait_cond(function() return box.space.sync:get({1}) ~= nil end, 100) + | --- + | - true + | ... +box.space.sync:select{} + | --- + | - - [1] + | ... + +-- +-- Wait the record from master get written and then +-- drop the replication. +test_run:switch('replica') + | --- + | - true + | ... +test_run:wait_cond(function() return box.space.sync:get({1}) ~= nil end, 100) + | --- + | - true + | ... +box.space.sync:select{} + | --- + | - - [1] + | ... +box.cfg{replication = {}} + | --- + | ... + +-- +-- Then we jump back to the master and drop the replication, +-- thus unconfirmed record get rolled back. +test_run:switch('master') + | --- + | - true + | ... +box.cfg({ \ + replication = {}, \ + replication_synchro_timeout = 0.001, \ + election_mode = 'manual', \ +}) + | --- + | ... +while f:status() ~= 'dead' do require('fiber').sleep(0.1) end + | --- + | ... +test_run:wait_cond(function() return box.space.sync:get({1}) == nil end, 100) + | --- + | - true + | ... + +-- +-- Force the replica to become a RAFT leader and +-- commit this new record. +test_run:switch('replica') + | --- + | - true + | ... +box.cfg({ \ + replication_synchro_quorum = 1, \ + election_mode = 'manual' \ +}) + | --- + | ... +box.ctl.promote() + | --- + | ... +box.space.sync:select{} + | --- + | - - [1] + | ... + +-- +-- Connect master back to the replica, it should +-- be refused. +test_run:switch('master') + | --- + | - true + | ... +box.cfg({ \ + replication = { \ + "unix/:./replica.sock", \ + }, \ +}) + | --- + | ... +box.space.sync:select{} + | --- + | - [] + | ... +test_run:wait_cond(function() return \ + test_run:grep_log('master', \ + 'rejecting PROMOTE') ~= nil end, 100) \ +test_run:wait_cond(function() return \ + test_run:grep_log('master', \ + 'ER_UNSUPPORTED') ~= nil end, 100) + | --- + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('stop server master') + | --- + | - true + | ... +test_run:cmd('delete server master') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... diff --git a/test/replication/gh-6036-rollback-confirm.test.lua b/test/replication/gh-6036-rollback-confirm.test.lua new file mode 100644 index 000000000..f84f3dd45 --- /dev/null +++ b/test/replication/gh-6036-rollback-confirm.test.lua @@ -0,0 +1,92 @@ +-- +-- gh-6036: Test for record collision detection. We have a cluster +-- of two nodes: master and replica. The master initiates syncho write +-- but fails to gather a quorum. Before it rolls back the record the +-- network breakage occurs and replica lives with dirty data while +-- master node goes offline. The replica becomes a new raft leader +-- and commits the dirty data, same time master node rolls back this +-- record and tries to connect to the new raft leader back. Such +-- connection should be refused because old master node is not longer +-- consistent. +-- +test_run = require('test_run').new() + +test_run:cmd('create server master with script="replication/gh-6036-master.lua"') +test_run:cmd('create server replica with script="replication/gh-6036-replica.lua"') + +test_run:cmd('start server master') +test_run:cmd('start server replica') + +-- +-- Connect master to the replica and write a record. Since the quorum +-- value is bigger than number of nodes in a cluster it will be rolled +-- back later. +test_run:switch('master') +box.cfg({ \ + replication = { \ + "unix/:./master.sock", \ + "unix/:./replica.sock", \ + }, \ +}) +_ = box.schema.create_space('sync', {is_sync = true}) +_ = box.space.sync:create_index('pk') + +-- +-- Wait the record to appear on the master. +f = require('fiber').create(function() box.space.sync:replace{1} end) +test_run:wait_cond(function() return box.space.sync:get({1}) ~= nil end, 100) +box.space.sync:select{} + +-- +-- Wait the record from master get written and then +-- drop the replication. +test_run:switch('replica') +test_run:wait_cond(function() return box.space.sync:get({1}) ~= nil end, 100) +box.space.sync:select{} +box.cfg{replication = {}} + +-- +-- Then we jump back to the master and drop the replication, +-- thus unconfirmed record get rolled back. +test_run:switch('master') +box.cfg({ \ + replication = {}, \ + replication_synchro_timeout = 0.001, \ + election_mode = 'manual', \ +}) +while f:status() ~= 'dead' do require('fiber').sleep(0.1) end +test_run:wait_cond(function() return box.space.sync:get({1}) == nil end, 100) + +-- +-- Force the replica to become a RAFT leader and +-- commit this new record. +test_run:switch('replica') +box.cfg({ \ + replication_synchro_quorum = 1, \ + election_mode = 'manual' \ +}) +box.ctl.promote() +box.space.sync:select{} + +-- +-- Connect master back to the replica, it should +-- be refused. +test_run:switch('master') +box.cfg({ \ + replication = { \ + "unix/:./replica.sock", \ + }, \ +}) +box.space.sync:select{} +test_run:wait_cond(function() return \ + test_run:grep_log('master', \ + 'rejecting PROMOTE') ~= nil end, 100) \ +test_run:wait_cond(function() return \ + test_run:grep_log('master', \ + 'ER_UNSUPPORTED') ~= nil end, 100) + +test_run:switch('default') +test_run:cmd('stop server master') +test_run:cmd('delete server master') +test_run:cmd('stop server replica') +test_run:cmd('delete server replica') -- 2.31.1