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 048866EC58; Wed, 4 Aug 2021 22:10:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 048866EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628104200; 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=levcksNCVsL2douQwu6vJm9k3WpXCzjd0TTQSSPst+auxrytzLBjg4rk/jfRaGHYE YcU7GwRz0+BLu8WaUS46ZYeIHMeutZuJbPCfoft+XW1KjFRwW8d3+D0hXIBCz/vhnN WtvRnInUMGxveZ2rh6tlP3tZwirIycCqf/2xy9EI= Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 A40196EC58 for ; Wed, 4 Aug 2021 22:08:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A40196EC58 Received: by mail-lf1-f47.google.com with SMTP id n17so3526628lft.13 for ; Wed, 04 Aug 2021 12:08:44 -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=ndN9cdFbaGhXkR4+nN49pky9M8/0TFA+FxRdYgKNcRHx0xppXpHufUipK1hC3l01+p S3T60YxK0iAeuKY+hgEj0llQgIrgfe7L9bCazV0mR9h2KB0T6ime24caWDJDpb+g/bDo tXgSgs3392FamjTLQMbBA5FTqvSDygR7u5PIOfekDswZKN04HLzMGv3QAvIC6JGpx7O0 2XIhLRVLV5dXPNu6RUQktDnpwnjk1iMOpP/6/yafCz82U6b4FqUqDQGwyRnZI98tHHDe YQZOJ51zRko4FvZP7Ut996QKO0divoqouCPMXpQfTQTKVBBqoOU+xSrbc7CQPpAaO3j7 fJRQ== X-Gm-Message-State: AOAM5325sVJ/Z2LIkFWVV+EWCmu/803PQw8Vr+0bUuocw6jMWmPHEbF0 O0unSxPnq5PVYZT2IYUJG1tLJxBi5Pk= X-Google-Smtp-Source: ABdhPJwHTrkbDtRQ7lGiLvWpQCPUDGKs0esjp6DVhc5s5AsEI5YPrP5wPi48aXJnzIh0SEFRsAiQKQ== X-Received: by 2002:ac2:560e:: with SMTP id v14mr541015lfd.158.1628104123591; Wed, 04 Aug 2021 12:08:43 -0700 (PDT) Received: from grain.localdomain ([5.18.255.97]) by smtp.gmail.com with ESMTPSA id z8sm299949lfb.30.2021.08.04.12.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 12:08:42 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id DD7B05A0022; Wed, 4 Aug 2021 22:07:53 +0300 (MSK) To: tml Date: Wed, 4 Aug 2021 22:07:52 +0300 Message-Id: <20210804190752.488147-5-gorcunov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804190752.488147-1-gorcunov@gmail.com> References: <20210804190752.488147-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v10 4/4] 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