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 203886FC8F; Tue, 23 Mar 2021 18:48:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 203886FC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616514496; bh=TpCYt0hMg764G5c+Hth2OmDBqvR2DsG6A6tUZ+7XozQ=; 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=g2XtFILBzP8KcRBhSBx29H4Wmfb2r3Ka4SrhHceJC9KQ6RZi7AOl2wnMDFBCi2aat /+pgn0E6MlEVS9c0+prR/yKx+HpZV4nEQmmKjQAm/ADHrs9NBnHhopkKPuJbd7SI2J 6lTZXcivuD1Ta6ze80DuLl+M0+mQuB7S6l+NGxvE= Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 6AAB471828 for ; Tue, 23 Mar 2021 18:47:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6AAB471828 Received: by mail-lf1-f51.google.com with SMTP id n138so27331471lfa.3 for ; Tue, 23 Mar 2021 08:47:39 -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=r8MGH1FlRKOUNWCw5CA20vNs3RFZqW2N24011KXsJpM=; b=riyJLFoS3LhcFXRiHbByGpdXaKlgl71Y2S+M6zeE2Nqjg3SpJihguMTnQDu1peET9W +cSusPD89TIWdFadB0uIZk6U6JOlxCTsxa410e3gcCB5djCh1v53BdzqhFmZOAf2pAAJ BhiV4Rl4hIsw7CebfZpZFwGqN4SAaukNwEovFjj06VqL4GM67we6GCwf1LgFaqqziKz0 dNZtZJywGh9TBGE0a73IvTrDK3BMff9AIGdDnS3mpX8b07Oe3uR9ZauzdSm+R32p7mu8 TgwrzOcFYT9W5NcMT6EfwScOVA2e9MUFwt+7rIp5Qxbqc8qEq6gM1uzRvURJ4iN0W9xh w9Pg== X-Gm-Message-State: AOAM532Syi2h5IAkd4HVlr6pj7ffhhZhzK/yuLIb5CK/GVAlrFgrYhnC 8zrAgdlfjJEXpqWPyoVP/AAnAG48jPw= X-Google-Smtp-Source: ABdhPJzUsONZds7bsXENk6aYOG0Lq8dsWIYYROOurlEm/2vCRsbtg+NUkIeZ4m5O0XAVrouhMdlu+Q== X-Received: by 2002:a19:2242:: with SMTP id i63mr2764111lfi.643.1616514458101; Tue, 23 Mar 2021 08:47:38 -0700 (PDT) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id n205sm1884593lfd.297.2021.03.23.08.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 08:47:36 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 8A9805601CB; Tue, 23 Mar 2021 18:47:11 +0300 (MSK) To: tml Date: Tue, 23 Mar 2021 18:47:09 +0300 Message-Id: <20210323154710.1696442-3-gorcunov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210323154710.1696442-1-gorcunov@gmail.com> References: <20210323154710.1696442-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v3 2/3] test: add a test for wal_cleanup_delay option 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" Part-of #5806 Signed-off-by: Cyrill Gorcunov --- test/replication/gh-5806-master.lua | 8 + test/replication/gh-5806-slave.lua | 8 + test/replication/gh-5806-xlog-cleanup.result | 356 ++++++++++++++++++ .../replication/gh-5806-xlog-cleanup.test.lua | 155 ++++++++ 4 files changed, 527 insertions(+) create mode 100644 test/replication/gh-5806-master.lua create mode 100644 test/replication/gh-5806-slave.lua create mode 100644 test/replication/gh-5806-xlog-cleanup.result create mode 100644 test/replication/gh-5806-xlog-cleanup.test.lua diff --git a/test/replication/gh-5806-master.lua b/test/replication/gh-5806-master.lua new file mode 100644 index 000000000..bc15dab67 --- /dev/null +++ b/test/replication/gh-5806-master.lua @@ -0,0 +1,8 @@ +#!/usr/bin/env tarantool + +require('console').listen(os.getenv('ADMIN')) + +box.cfg({ + listen = os.getenv("LISTEN"), + wal_cleanup_delay = tonumber(arg[1]) or 0, +}) diff --git a/test/replication/gh-5806-slave.lua b/test/replication/gh-5806-slave.lua new file mode 100644 index 000000000..3abb3e035 --- /dev/null +++ b/test/replication/gh-5806-slave.lua @@ -0,0 +1,8 @@ +#!/usr/bin/env tarantool + +require('console').listen(os.getenv('ADMIN')) + +box.cfg({ + listen = os.getenv("LISTEN"), + replication = os.getenv("MASTER"), +}) diff --git a/test/replication/gh-5806-xlog-cleanup.result b/test/replication/gh-5806-xlog-cleanup.result new file mode 100644 index 000000000..3ab72722d --- /dev/null +++ b/test/replication/gh-5806-xlog-cleanup.result @@ -0,0 +1,356 @@ +-- test-run result file version 2 +-- +-- gh-5806: defer xlog cleanup to keep xlogs until +-- replicas present in "_cluster" are connected. +-- Otherwise we are getting XlogGapError since +-- master might go far forward from replica and +-- replica won't be able to connect without full +-- rebootstrap. +-- + +fiber = require('fiber') + | --- + | ... +test_run = require('test_run').new() + | --- + | ... +engine = test_run:get_cfg('engine') + | --- + | ... + +-- +-- Case 1. +-- +-- First lets make sure we're getting XlogGapError in +-- case if wal_cleanup_delay is not used. +-- + +test_run:cmd('create server master with script="replication/gh-5806-master.lua"') + | --- + | - true + | ... +test_run:cmd('start server master with wait=True, wait_load=True') + | --- + | - true + | ... + +test_run:switch('master') + | --- + | - true + | ... +box.schema.user.grant('guest', 'replication') + | --- + | ... + +-- +-- Keep small number of snaps to force cleanup +-- procedure be more intensive. +box.cfg{checkpoint_count = 1} + | --- + | ... + +engine = test_run:get_cfg('engine') + | --- + | ... +s = box.schema.space.create('test', {engine = engine}) + | --- + | ... +_ = s:create_index('pk') + | --- + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('create server replica with rpl_master=master,\ + script="replication/gh-5806-slave.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica with wait=True, wait_load=True') + | --- + | - true + | ... + +-- +-- On replica we create an own space which allows us to +-- use more complex scenario and disables replica from +-- automatic rejoin (since replica can't do auto-rejoin if +-- there gonna be an own data loss). This allows us to +-- trigger XlogGapError in the log. +test_run:switch('replica') + | --- + | - true + | ... +box.cfg{checkpoint_count = 1} + | --- + | ... +s = box.schema.space.create('testreplica') + | --- + | ... +_ = s:create_index('pk') + | --- + | ... +box.space.testreplica:insert({1}) + | --- + | - [1] + | ... +box.snapshot() + | --- + | - ok + | ... + +-- +-- Stop the replica node and generate +-- xlogs on the master. +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... + +test_run:switch('master') + | --- + | - true + | ... +box.space.test:insert({1}) + | --- + | - [1] + | ... +box.snapshot() + | --- + | - ok + | ... + +-- +-- We need to restart the master node since otherwise +-- the replica will be preventing us from removing old +-- xlog because it will be tracked by gc consumer which +-- kept in memory while master node is running. +-- +-- Once restarted we write a new record into master's +-- space and run snapshot which removes old xlog required +-- by replica to subscribe leading to XlogGapError which +-- we need to test. +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('restart server master with wait_load=True') + | --- + | - true + | ... +test_run:switch('master') + | --- + | - true + | ... +box.space.test:insert({2}) + | --- + | - [2] + | ... +box.snapshot() + | --- + | - ok + | ... +assert(box.info.gc().is_paused == false) + | --- + | - true + | ... + +-- +-- Start replica and wait for error. +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('start server replica with wait=False, wait_load=False') + | --- + | - true + | ... + +-- +-- Wait error to appear. +test_run:wait_log('master', 'XlogGapError', 1024, 0.1) ~= nil + | --- + | - true + | ... + +-- +-- Cleanup. +test_run:cmd('stop server master') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('delete server master') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... + +-- +-- Case 2. +-- +-- Lets make sure we're not getting XlogGapError in +-- case if wal_cleanup_delay is used the code is almost +-- the same as for Case 1 except we don't disable cleanup +-- fiber but delay it up to a hour until replica is up +-- and running. +-- + +test_run:cmd('create server master with script="replication/gh-5806-master.lua"') + | --- + | - true + | ... +test_run:cmd('start server master with args="3600", wait=True, wait_load=True') + | --- + | - true + | ... + +test_run:switch('master') + | --- + | - true + | ... +box.schema.user.grant('guest', 'replication') + | --- + | ... + +box.cfg{checkpoint_count = 1} + | --- + | ... + +engine = test_run:get_cfg('engine') + | --- + | ... +s = box.schema.space.create('test', {engine = engine}) + | --- + | ... +_ = s:create_index('pk') + | --- + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('create server replica with rpl_master=master,\ + script="replication/gh-5806-slave.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica with wait=True, wait_load=True') + | --- + | - true + | ... + +test_run:switch('replica') + | --- + | - true + | ... +box.cfg{checkpoint_count = 1} + | --- + | ... +s = box.schema.space.create('testreplica') + | --- + | ... +_ = s:create_index('pk') + | --- + | ... +box.space.testreplica:insert({1}) + | --- + | - [1] + | ... +box.snapshot() + | --- + | - ok + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... + +test_run:switch('master') + | --- + | - true + | ... +box.space.test:insert({1}) + | --- + | - [1] + | ... +box.snapshot() + | --- + | - ok + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('restart server master with args="3600", wait=True, wait_load=True') + | --- + | - true + | ... +test_run:switch('master') + | --- + | - true + | ... +box.space.test:insert({2}) + | --- + | - [2] + | ... +box.snapshot() + | --- + | - ok + | ... +assert(box.info.gc().is_paused == true) + | --- + | - true + | ... + +test_run:switch('default') + | --- + | - true + | ... +test_run:cmd('start server replica with wait=True, wait_load=True') + | --- + | - true + | ... + +-- +-- Make sure no error happened. +assert(test_run:grep_log("master", "XlogGapError") == nil) + | --- + | - true + | ... + +test_run:cmd('stop server master') + | --- + | - true + | ... +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('delete server master') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... diff --git a/test/replication/gh-5806-xlog-cleanup.test.lua b/test/replication/gh-5806-xlog-cleanup.test.lua new file mode 100644 index 000000000..5ad88735e --- /dev/null +++ b/test/replication/gh-5806-xlog-cleanup.test.lua @@ -0,0 +1,155 @@ +-- +-- gh-5806: defer xlog cleanup to keep xlogs until +-- replicas present in "_cluster" are connected. +-- Otherwise we are getting XlogGapError since +-- master might go far forward from replica and +-- replica won't be able to connect without full +-- rebootstrap. +-- + +fiber = require('fiber') +test_run = require('test_run').new() +engine = test_run:get_cfg('engine') + +-- +-- Case 1. +-- +-- First lets make sure we're getting XlogGapError in +-- case if wal_cleanup_delay is not used. +-- + +test_run:cmd('create server master with script="replication/gh-5806-master.lua"') +test_run:cmd('start server master with wait=True, wait_load=True') + +test_run:switch('master') +box.schema.user.grant('guest', 'replication') + +-- +-- Keep small number of snaps to force cleanup +-- procedure be more intensive. +box.cfg{checkpoint_count = 1} + +engine = test_run:get_cfg('engine') +s = box.schema.space.create('test', {engine = engine}) +_ = s:create_index('pk') + +test_run:switch('default') +test_run:cmd('create server replica with rpl_master=master,\ + script="replication/gh-5806-slave.lua"') +test_run:cmd('start server replica with wait=True, wait_load=True') + +-- +-- On replica we create an own space which allows us to +-- use more complex scenario and disables replica from +-- automatic rejoin (since replica can't do auto-rejoin if +-- there gonna be an own data loss). This allows us to +-- trigger XlogGapError in the log. +test_run:switch('replica') +box.cfg{checkpoint_count = 1} +s = box.schema.space.create('testreplica') +_ = s:create_index('pk') +box.space.testreplica:insert({1}) +box.snapshot() + +-- +-- Stop the replica node and generate +-- xlogs on the master. +test_run:switch('default') +test_run:cmd('stop server replica') + +test_run:switch('master') +box.space.test:insert({1}) +box.snapshot() + +-- +-- We need to restart the master node since otherwise +-- the replica will be preventing us from removing old +-- xlog because it will be tracked by gc consumer which +-- kept in memory while master node is running. +-- +-- Once restarted we write a new record into master's +-- space and run snapshot which removes old xlog required +-- by replica to subscribe leading to XlogGapError which +-- we need to test. +test_run:switch('default') +test_run:cmd('restart server master with wait_load=True') +test_run:switch('master') +box.space.test:insert({2}) +box.snapshot() +assert(box.info.gc().is_paused == false) + +-- +-- Start replica and wait for error. +test_run:switch('default') +test_run:cmd('start server replica with wait=False, wait_load=False') + +-- +-- Wait error to appear. +test_run:wait_log('master', 'XlogGapError', 1024, 0.1) ~= nil + +-- +-- Cleanup. +test_run:cmd('stop server master') +test_run:cmd('stop server replica') +test_run:cmd('delete server master') +test_run:cmd('delete server replica') + +-- +-- Case 2. +-- +-- Lets make sure we're not getting XlogGapError in +-- case if wal_cleanup_delay is used the code is almost +-- the same as for Case 1 except we don't disable cleanup +-- fiber but delay it up to a hour until replica is up +-- and running. +-- + +test_run:cmd('create server master with script="replication/gh-5806-master.lua"') +test_run:cmd('start server master with args="3600", wait=True, wait_load=True') + +test_run:switch('master') +box.schema.user.grant('guest', 'replication') + +box.cfg{checkpoint_count = 1} + +engine = test_run:get_cfg('engine') +s = box.schema.space.create('test', {engine = engine}) +_ = s:create_index('pk') + +test_run:switch('default') +test_run:cmd('create server replica with rpl_master=master,\ + script="replication/gh-5806-slave.lua"') +test_run:cmd('start server replica with wait=True, wait_load=True') + +test_run:switch('replica') +box.cfg{checkpoint_count = 1} +s = box.schema.space.create('testreplica') +_ = s:create_index('pk') +box.space.testreplica:insert({1}) +box.snapshot() + +test_run:switch('default') +test_run:cmd('stop server replica') + +test_run:switch('master') +box.space.test:insert({1}) +box.snapshot() + +test_run:switch('default') +test_run:cmd('restart server master with args="3600", wait=True, wait_load=True') +test_run:switch('master') +box.space.test:insert({2}) +box.snapshot() +assert(box.info.gc().is_paused == true) + +test_run:switch('default') +test_run:cmd('start server replica with wait=True, wait_load=True') + +-- +-- Make sure no error happened. +assert(test_run:grep_log("master", "XlogGapError") == nil) + +test_run:cmd('stop server master') +test_run:cmd('stop server replica') +test_run:cmd('delete server master') +test_run:cmd('delete server replica') -- 2.30.2