From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 9E0CF42EF5C for ; Fri, 3 Jul 2020 00:15:17 +0300 (MSK) From: sergeyb@tarantool.org Date: Fri, 3 Jul 2020 00:13:39 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 4/4] replication: add tests for sync replication with snapshots List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, sergepetrenko@tarantool.org, gorcunov@gmail.com, lvasiliev@tarantool.org From: Sergey Bronnikov Part of #5055 --- test/replication/qsync_snapshots.result | 362 ++++++++++++++++++++++ test/replication/qsync_snapshots.test.lua | 132 ++++++++ 2 files changed, 494 insertions(+) create mode 100644 test/replication/qsync_snapshots.result create mode 100644 test/replication/qsync_snapshots.test.lua diff --git a/test/replication/qsync_snapshots.result b/test/replication/qsync_snapshots.result new file mode 100644 index 000000000..db98f87fd --- /dev/null +++ b/test/replication/qsync_snapshots.result @@ -0,0 +1,362 @@ +-- test-run result file version 2 +env = require('test_run') + | --- + | ... +test_run = env.new() + | --- + | ... +engine = test_run:get_cfg('engine') + | --- + | ... +fiber = require('fiber') + | --- + | ... + +orig_synchro_quorum = box.cfg.replication_synchro_quorum + | --- + | ... +orig_synchro_timeout = box.cfg.replication_synchro_timeout + | --- + | ... + +NUM_INSTANCES = 2 + | --- + | ... +BROKEN_QUORUM = NUM_INSTANCES + 1 + | --- + | ... + +box.schema.user.grant('guest', 'replication') + | --- + | ... + +-- Setup an async cluster with two instances. +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica with wait=True, wait_load=True') + | --- + | - true + | ... + +-- [RFC, Snapshot generation] all txns confirmed, then snapshot on master, +-- expected success. +-- Testcase setup. +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} + | --- + | ... +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... +-- Testcase body. +box.space.sync:insert{1} + | --- + | - [1] + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +box.snapshot() + | --- + | - ok + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +-- Testcase cleanup. +box.space.sync:drop() + | --- + | ... + +-- [RFC, Snapshot generation] all txns confirmed, then snapshot on replica, +-- expected success. +-- Testcase setup. +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} + | --- + | ... +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... +-- Testcase body. +box.space.sync:insert{1} + | --- + | - [1] + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('replica') + | --- + | - true + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +box.snapshot() + | --- + | - ok + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +-- Testcase cleanup. +test_run:switch('default') + | --- + | - true + | ... +box.space.sync:drop() + | --- + | ... + +-- [RFC, Snapshot generation] rolled back operations are not snapshotted +-- Testcase setup. +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} + | --- + | ... +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... +-- Testcase body. +box.space.sync:insert{1} + | --- + | - [1] + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=3, replication_synchro_timeout=0.1} + | --- + | ... +box.space.sync:insert{2} + | --- + | - error: Quorum collection for a synchronous transaction is timed out + | ... +box.snapshot() + | --- + | - ok + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('replica') + | --- + | - true + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +-- Testcase cleanup. +test_run:switch('default') + | --- + | - true + | ... +box.space.sync:drop() + | --- + | ... + +-- [RFC, Snapshot generation] snapshot started on master, then rollback +-- arrived, expected snapshot abort +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} + | --- + | ... +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... +-- Testcase body. +box.space.sync:insert{1} + | --- + | - [1] + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd("setopt delimiter ';'") + | --- + | - true + | ... +_ = fiber.create(function() + box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=2} + box.space.sync:insert{2} +end); + | --- + | ... +test_run:cmd("setopt delimiter ''"); + | --- + | - true + | ... +box.snapshot() -- abort + | --- + | - error: A rollback for a synchronous transaction is received + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('replica') + | --- + | - true + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +-- Testcase cleanup. +test_run:switch('default') + | --- + | - true + | ... +box.space.sync:drop() + | --- + | ... + +-- [RFC, Snapshot generation] snapshot started on replica, then rollback +-- arrived, expected snapshot abort +test_run:switch('default') + | --- + | - true + | ... +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} + | --- + | ... +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) + | --- + | ... +_ = box.space.sync:create_index('pk') + | --- + | ... +-- Testcase body. +box.space.sync:insert{1} + | --- + | - [1] + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('replica') + | --- + | - true + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd("setopt delimiter ';'") + | --- + | - true + | ... +_ = fiber.create(function() + box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=2} + box.space.sync:insert{2} +end); + | --- + | ... +test_run:cmd("setopt delimiter ''"); + | --- + | - true + | ... +test_run:switch('replica') + | --- + | - true + | ... +box.snapshot() -- abort + | --- + | - error: A rollback for a synchronous transaction is received + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +test_run:switch('default') + | --- + | - true + | ... +box.space.sync:select{} -- 1 + | --- + | - - [1] + | ... +-- Testcase cleanup. +test_run:switch('default') + | --- + | - true + | ... +box.space.sync:drop() + | --- + | ... + +-- Teardown. +test_run:cmd('switch default') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... +test_run:cleanup_cluster() + | --- + | ... +box.schema.user.revoke('guest', 'replication') + | --- + | ... +box.cfg{ \ + replication_synchro_quorum = orig_synchro_quorum, \ + replication_synchro_timeout = orig_synchro_timeout, \ +} + | --- + | ... diff --git a/test/replication/qsync_snapshots.test.lua b/test/replication/qsync_snapshots.test.lua new file mode 100644 index 000000000..b5990bce7 --- /dev/null +++ b/test/replication/qsync_snapshots.test.lua @@ -0,0 +1,132 @@ +env = require('test_run') +test_run = env.new() +engine = test_run:get_cfg('engine') +fiber = require('fiber') + +orig_synchro_quorum = box.cfg.replication_synchro_quorum +orig_synchro_timeout = box.cfg.replication_synchro_timeout + +NUM_INSTANCES = 2 +BROKEN_QUORUM = NUM_INSTANCES + 1 + +box.schema.user.grant('guest', 'replication') + +-- Setup an async cluster with two instances. +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') +test_run:cmd('start server replica with wait=True, wait_load=True') + +-- [RFC, Snapshot generation] all txns confirmed, then snapshot on master, +-- expected success. +-- Testcase setup. +test_run:switch('default') +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) +_ = box.space.sync:create_index('pk') +-- Testcase body. +box.space.sync:insert{1} +box.space.sync:select{} -- 1 +box.snapshot() +box.space.sync:select{} -- 1 +-- Testcase cleanup. +box.space.sync:drop() + +-- [RFC, Snapshot generation] all txns confirmed, then snapshot on replica, +-- expected success. +-- Testcase setup. +test_run:switch('default') +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) +_ = box.space.sync:create_index('pk') +-- Testcase body. +box.space.sync:insert{1} +box.space.sync:select{} -- 1 +test_run:switch('replica') +box.space.sync:select{} -- 1 +box.snapshot() +box.space.sync:select{} -- 1 +-- Testcase cleanup. +test_run:switch('default') +box.space.sync:drop() + +-- [RFC, Snapshot generation] rolled back operations are not snapshotted. +-- Testcase setup. +test_run:switch('default') +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) +_ = box.space.sync:create_index('pk') +-- Testcase body. +box.space.sync:insert{1} +box.space.sync:select{} -- 1 +test_run:switch('default') +box.cfg{replication_synchro_quorum=3, replication_synchro_timeout=0.1} +box.space.sync:insert{2} +box.snapshot() +box.space.sync:select{} -- 1 +test_run:switch('replica') +box.space.sync:select{} -- 1 +-- Testcase cleanup. +test_run:switch('default') +box.space.sync:drop() + +-- [RFC, Snapshot generation] snapshot started on master, then rollback +-- arrived, expected snapshot abort. +test_run:switch('default') +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) +_ = box.space.sync:create_index('pk') +-- Testcase body. +box.space.sync:insert{1} +box.space.sync:select{} -- 1 +test_run:switch('default') +test_run:cmd("setopt delimiter ';'") +_ = fiber.create(function() + box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=2} + box.space.sync:insert{2} +end); +test_run:cmd("setopt delimiter ''"); +box.snapshot() -- abort +box.space.sync:select{} -- 1 +test_run:switch('replica') +box.space.sync:select{} -- 1 +-- Testcase cleanup. +test_run:switch('default') +box.space.sync:drop() + +-- [RFC, Snapshot generation] snapshot started on replica, then rollback +-- arrived, expected snapshot abort. +test_run:switch('default') +box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1} +_ = box.schema.space.create('sync', {is_sync=true, engine=engine}) +_ = box.space.sync:create_index('pk') +-- Testcase body. +box.space.sync:insert{1} +box.space.sync:select{} -- 1 +test_run:switch('replica') +box.space.sync:select{} -- 1 +test_run:switch('default') +test_run:cmd("setopt delimiter ';'") +_ = fiber.create(function() + box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=2} + box.space.sync:insert{2} +end); +test_run:cmd("setopt delimiter ''"); +test_run:switch('replica') +box.snapshot() -- abort +box.space.sync:select{} -- 1 +test_run:switch('default') +box.space.sync:select{} -- 1 +-- Testcase cleanup. +test_run:switch('default') +box.space.sync:drop() + +-- Teardown. +test_run:cmd('switch default') +test_run:cmd('stop server replica') +test_run:cmd('delete server replica') +test_run:cleanup_cluster() +box.schema.user.revoke('guest', 'replication') +box.cfg{ \ + replication_synchro_quorum = orig_synchro_quorum, \ + replication_synchro_timeout = orig_synchro_timeout, \ +} -- 2.26.2