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 4D563741EE; Fri, 6 Aug 2021 10:36:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4D563741EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628235375; bh=AEsBYHp1CKc4uToodEd1+6UcuoRPPqtsLZZUkdTYc9M=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=wZ4GLP3Qw+VuxgWT29QDqM3urhYwPqfpCq9nId3oeN9qY9LAAc8HM3FB5XfY/9tCA VkyzknC08FHZoDxe4N8/DSlSCUcLSuRZaiu+zpmWX/Pu/r9n0b+AM2rl7tXOv3QMoy 1MOqWN/X28fWQd3Cyh1nhMhDoCMjt0MIVdN9GNJA= Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 544FD741EE for ; Fri, 6 Aug 2021 04:56:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 544FD741EE Received: by mail-lj1-f178.google.com with SMTP id o10so9765427ljp.0 for ; Thu, 05 Aug 2021 18:56:33 -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=VIh1ZI+fQPoZtQIBa0eiby+7Yo31knudWqkvhnzzldI=; b=PqgCsGZEAokOSahWL9bybavrJlwU4awFDJIv0qMB47h+iDEl0R+bHnz/hao6sHm09a FBBzEwkDgec33knDgzUMLJ6zdDfDvcPpQ9hDrJ2/Ti1aqq6nLFBSbIQYOC2/SMapJ66K KdoY190MzRiKxcrm5iuHn2XNA/ZeamR6WqhaHHOk1PydFtZ416N412z5le3BKwLH3XQR melX9HwcFD345OU5Q0fI7mEIwcWxp/VPqFooiLQpJrTw70rLe02Sv7zgSRQVFXK/81sO ZmhMwF5+V4jrNZWmAO84TE9OkdASwtAQSH1rYllhlW6XjvUsOXuml6dyJ0zl+DEbooH8 YU9Q== X-Gm-Message-State: AOAM5328RKywUjSiiSPg/sabZVp7mm/ncxDS5hlk8MEEZ6CsUsk7vfD5 FrSixsbR5BP5V3WNBoweOPU= X-Google-Smtp-Source: ABdhPJyILzTYerAZ8y4moYq4GopfQOAk+wKWvWR8Sg1Yq39kbIJy8OqwaC9/x564duqVD0bEIXkTeQ== X-Received: by 2002:a2e:92c8:: with SMTP id k8mr5050126ljh.136.1628214992885; Thu, 05 Aug 2021 18:56:32 -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 g30sm683988lfv.196.2021.08.05.18.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 18:56:32 -0700 (PDT) To: sergepetrenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org, Yan Shtunder Date: Fri, 6 Aug 2021 04:56:07 +0300 Message-Id: <20210806015607.14898-1-ya.shtunder@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 06 Aug 2021 10:36:14 +0300 Subject: [Tarantool-patches] (no subject) 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" Issue: https://github.com/tarantool/tarantool/issues/6028 Patch: https://github.com/tarantool/tarantool/tree/yshtunder/gh-6028-applier-vclock Subject: [PATCH] replication: fill replicaset.applier.vclock after local recovery 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 --- src/box/applier.cc | 5 ++ src/box/box.cc | 7 ++ src/lib/core/errinj.h | 1 + test/box/errinj.result | 1 + ...0-misc-heartbeats-on-master-changes.result | 2 +- test/replication/gh-6028-replica.lua | 13 ++++ .../gh-6028-vclock-is-empty.result | 65 +++++++++++++++++++ .../gh-6028-vclock-is-empty.test.lua | 26 ++++++++ 8 files changed, 119 insertions(+), 1 deletion(-) 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-3160-misc-heartbeats-on-master-changes.result b/test/replication/gh-3160-misc-heartbeats-on-master-changes.result index 86e5ddfa0..f5ffbe17d 100644 --- a/test/replication/gh-3160-misc-heartbeats-on-master-changes.result +++ b/test/replication/gh-3160-misc-heartbeats-on-master-changes.result @@ -57,7 +57,7 @@ test_run:cmd("setopt delimiter ''"); ... test_timeout() --- -- true +- false ... test_run:cmd("switch default") --- 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..944c0905e --- /dev/null +++ b/test/replication/gh-6028-vclock-is-empty.result @@ -0,0 +1,65 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... + + +box.schema.user.grant('guest', 'super') + | --- + | ... +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:switch('default') + | --- + | - true + | ... +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..e981958b2 --- /dev/null +++ b/test/replication/gh-6028-vclock-is-empty.test.lua @@ -0,0 +1,26 @@ +test_run = require('test_run').new() + + +box.schema.user.grant('guest', 'super') +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:switch('default') +test_run:cmd('stop server replica') +test_run:cmd('cleanup server replica') +test_run:cmd('delete server replica') -- 2.25.1