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 92B0D6EC40; Mon, 9 Aug 2021 13:09:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 92B0D6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628503797; bh=yW3mcoy4X/8xwfEft3SdwIwvHvESvYqvBo8q4BX6tfY=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=K/EMnsIW3kYHIOSwwSO3hnvcpPYFZ02gQpOYKl/6wr3HVsRs/lsR1V6MAaUze0ZJB TjnHhhT+u0pXWi7GNQbYlY36hTxoAssEpmpdivK448x9cXm8KBPUf81+jTWy6p3Kei VL4TNHJ4Jwnj1OZ6P10764agfWn42YyNtDge2aJs= Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 400286EC40 for ; Mon, 9 Aug 2021 13:09:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 400286EC40 Received: by mail-lf1-f53.google.com with SMTP id p38so5194058lfa.0 for ; Mon, 09 Aug 2021 03:09:55 -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:mime-version :content-transfer-encoding; bh=we9NyfCiRV+keMxxUcR/xd88Uk/E003uyrTIhuTJCak=; b=QqOhFVmHmf1hVqPpRyL+GTtm9X16f2/v2cY7XHXR7TuNZ2X+53YGrulY52gV3/npYz sfLuEbfRUtukJJNyQ//iIbZ2v8ftl5ncF/5laPtjs1B2bnYi9XOFtsrI/GUguueCncaB xYVDh96nlkWIRdH16ModVf/fNzUW3u3O5natayU2l2MtUNs1IUsQYSlvTZYLLxMHmaNj atskVod/VwLZgJJGk5+6JMtlgxAB2mkYFMbuV2yOoilCgAcJnSbhYxymrne3CKss+ZYl WgYZEKGALjgEQIpeDgnMgL+H1zzE3BoyH9sHHZoxjr7Y3kfBgNMDdp8k0BnwgMLjKrYl GzRw== X-Gm-Message-State: AOAM530X+V65j5+d2vzjWR7EnDr78biZVoQP2pAYvMCXXWmdLT05ouas qfYSz41HD2l2fEwsXOP8R4s= X-Google-Smtp-Source: ABdhPJw/mcROBieSqBymgHA6VfWfeqpfGyIP6sJiDT3pMg3HcwlrmNYo5FYwKVO0nrHOyHbk+5HO5g== X-Received: by 2002:a05:6512:3d8d:: with SMTP id k13mr17813454lfv.394.1628503794790; Mon, 09 Aug 2021 03:09:54 -0700 (PDT) Received: from localhost.localdomain (broadband-46-242-13-79.ip.moscow.rt.ru. [46.242.13.79]) by smtp.gmail.com with ESMTPSA id q3sm1681558lfc.284.2021.08.09.03.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 03:09:54 -0700 (PDT) To: sergepetrenko@tarantool.org, sergos@tarantool.org Cc: tarantool-patches@dev.tarantool.org, Yan Shtunder Date: Mon, 9 Aug 2021 13:09:31 +0300 Message-Id: <20210809100931.14367-1-ya.shtunder@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] replication: fill replicaset.applier.vclock after local recovery 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: Yan Shtunder via Tarantool-patches Reply-To: Yan Shtunder Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" replicaset.applier.vclock is initialized in replication_init(), which happens before local recovery. If some changes are come frome some instance via applier that applier.vclock will equal 0. This means that if some wild master send this node already applied data, the node will apply the same data twice. Closes #6028 --- Issue: https://github.com/tarantool/tarantool/issues/6028 Patch: https://github.com/tarantool/tarantool/tree/yshtunder/gh-6028-applier-vclock src/box/applier.cc | 5 ++ src/box/box.cc | 7 +++ src/lib/core/errinj.h | 1 + test/box/errinj.result | 1 + test/replication/gh-6028-replica.lua | 13 ++++ .../gh-6028-vclock-is-empty.result | 60 +++++++++++++++++++ .../gh-6028-vclock-is-empty.test.lua | 24 ++++++++ 7 files changed, 111 insertions(+) create mode 100644 test/replication/gh-6028-replica.lua create mode 100644 test/replication/gh-6028-vclock-is-empty.result create mode 100644 test/replication/gh-6028-vclock-is-empty.test.lua diff --git a/src/box/applier.cc b/src/box/applier.cc index 07fe7f5c7..9855b8d37 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -1230,6 +1230,11 @@ applier_subscribe(struct applier *applier) struct vclock vclock; vclock_create(&vclock); vclock_copy(&vclock, &replicaset.vclock); + + ERROR_INJECT(ERRINJ_REPLICASET_VCLOCK, { + vclock_create(&vclock); + }); + /* * Stop accepting local rows coming from a remote * instance as soon as local WAL starts accepting writes. diff --git a/src/box/box.cc b/src/box/box.cc index ab7d983c9..f5cd63c9e 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -3451,6 +3451,13 @@ box_cfg_xc(void) bootstrap(&instance_uuid, &replicaset_uuid, &is_bootstrap_leader); } + + /* + * replicaset.applier.vclock is filled with real + * value where local restore has already completed + */ + vclock_copy(&replicaset.applier.vclock, &replicaset.vclock); + fiber_gc(); /* diff --git a/src/lib/core/errinj.h b/src/lib/core/errinj.h index 359174b16..fcd856fbb 100644 --- a/src/lib/core/errinj.h +++ b/src/lib/core/errinj.h @@ -152,6 +152,7 @@ struct errinj { _(ERRINJ_STDIN_ISATTY, ERRINJ_INT, {.iparam = -1}) \ _(ERRINJ_SNAP_COMMIT_FAIL, ERRINJ_BOOL, {.bparam = false}) \ _(ERRINJ_IPROTO_SINGLE_THREAD_STAT, ERRINJ_INT, {.iparam = -1}) \ + _(ERRINJ_REPLICASET_VCLOCK, ERRINJ_BOOL, {.bparam = false}) \ ENUM0(errinj_id, ERRINJ_LIST); extern struct errinj errinjs[]; diff --git a/test/box/errinj.result b/test/box/errinj.result index 43daf5f0f..62e37bbdd 100644 --- a/test/box/errinj.result +++ b/test/box/errinj.result @@ -70,6 +70,7 @@ evals - ERRINJ_RELAY_REPORT_INTERVAL: 0 - ERRINJ_RELAY_SEND_DELAY: false - ERRINJ_RELAY_TIMEOUT: 0 + - ERRINJ_REPLICASET_VCLOCK: false - ERRINJ_REPLICA_JOIN_DELAY: false - ERRINJ_SIO_READ_MAX: -1 - ERRINJ_SNAP_COMMIT_DELAY: false diff --git a/test/replication/gh-6028-replica.lua b/test/replication/gh-6028-replica.lua new file mode 100644 index 000000000..5669cc4e9 --- /dev/null +++ b/test/replication/gh-6028-replica.lua @@ -0,0 +1,13 @@ +#!/usr/bin/env tarantool + +require('console').listen(os.getenv('ADMIN')) + +box.error.injection.set("ERRINJ_REPLICASET_VCLOCK", true) + +box.cfg({ + listen = os.getenv("LISTEN"), + replication = {os.getenv("MASTER"), os.getenv("LISTEN")}, + memtx_memory = 107374182, +}) + +box.error.injection.set("ERRINJ_REPLICASET_VCLOCK", false) diff --git a/test/replication/gh-6028-vclock-is-empty.result b/test/replication/gh-6028-vclock-is-empty.result new file mode 100644 index 000000000..0b103bb6e --- /dev/null +++ b/test/replication/gh-6028-vclock-is-empty.result @@ -0,0 +1,60 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... + +box.schema.user.grant('guest', 'replication') + | --- + | ... +s = box.schema.create_space('test') + | --- + | ... +_ = s:create_index('pk') + | --- + | ... + + +-- Case 1 +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/gh-6028-replica.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica') + | --- + | - true + | ... + +test_run:cmd('stop server replica') + | --- + | - true + | ... +s:insert{1} + | --- + | - [1] + | ... + + +-- Case 2 +test_run:cmd('start server replica') + | --- + | - true + | ... +s:insert{2} + | --- + | - [2] + | ... + + +test_run:cmd('stop server replica') + | --- + | - true + | ... +test_run:cmd('cleanup server replica') + | --- + | - true + | ... +test_run:cmd('delete server replica') + | --- + | - true + | ... diff --git a/test/replication/gh-6028-vclock-is-empty.test.lua b/test/replication/gh-6028-vclock-is-empty.test.lua new file mode 100644 index 000000000..ba14eca55 --- /dev/null +++ b/test/replication/gh-6028-vclock-is-empty.test.lua @@ -0,0 +1,24 @@ +test_run = require('test_run').new() + +box.schema.user.grant('guest', 'replication') +s = box.schema.create_space('test') +_ = s:create_index('pk') + + +-- Case 1 +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/gh-6028-replica.lua"') +test_run:cmd('start server replica') + +test_run:cmd('stop server replica') +s:insert{1} + + +-- Case 2 +test_run:cmd('start server replica') +s:insert{2} + + +test_run:cmd('stop server replica') +test_run:cmd('cleanup server replica') +test_run:cmd('delete server replica') -- 2.25.1