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 EA83F7118D; Mon, 25 Oct 2021 13:44:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EA83F7118D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635158696; bh=2Afl+JD+sncbeUwzx0VWeTZu5+B9IyWYCquyItoEj5Q=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hDwY/HORxxM0HrTWctpTHSybISWTMpDsRYNe4Y6wv/NTHDmmUXL+C3TTShFnU2/sW 329BaK725RL6HfUlCdqKnBfrZa9Y7Dseq4oaaW+d/e2FGVU/Ky7UaNVh4h2B9PfAtD rgwvk529f1qNLA6wKO+068N64fTyQfClWlXlV2rA= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 7E8557118D for ; Mon, 25 Oct 2021 13:44:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7E8557118D Received: by mail-lf1-f46.google.com with SMTP id j21so10393509lfe.0 for ; Mon, 25 Oct 2021 03:44:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=krw65MoE/xUc1aGFxCtmvC+hbk9ZU91ognkfyLY4b+Y=; b=aLfuGVBvZJDQqk3GsEhrKIXl2MMTPKXK1Y/IAgZzvlYuIgcIJ+qTMPzx4r7ICXipWK v6N2RT7eZ2EfYTFuocQMOCf4vY2znQUKAkxJf+Kj5pEeL9K6GA2gpz0jXETB5aTwv5qW /JTJXOViT6NEZVm6H4Mzdh/OtiEoS/pTzUC9r7UWFFs5izipZQTYCUf5Ex2lWoor/aJW 10CgktNN+dGU0WaldR05CEpMGjcfhfE+112GsnCjkoYKLNUXqcn3dmHC1/JuP0lQ08cq IBn8U4ooFH/vsMkZJ1K0f9W17ztxbZwrMpcdZIEMUBZKT5fIsMwY3C7UmmvaZZr/DVdM J5aA== X-Gm-Message-State: AOAM5337LceO32nZqF4FyO4yN8CVlVkEpiiiunrH/Gq+UKillZNWae1+ N40Bv3qoWLNCjWajvoI4zCjZ7uGhDpE= X-Google-Smtp-Source: ABdhPJy8qcnCjA5G0gIyy22EVBbND/Wt7GOLPYxJnQQlwHeiG+tDV98TzSzvsUzMxGsPUeyLcYLmXA== X-Received: by 2002:a05:6512:324d:: with SMTP id c13mr4092690lfr.349.1635158692844; Mon, 25 Oct 2021 03:44:52 -0700 (PDT) Received: from localhost.localdomain (broadband-46-242-13-228.ip.moscow.rt.ru. [46.242.13.228]) by smtp.gmail.com with ESMTPSA id l20sm1611705lfg.15.2021.10.25.03.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 03:44:52 -0700 (PDT) To: tarantool-patches@dev.tarantool.org Cc: Yan Shtunder Date: Mon, 25 Oct 2021 13:44:49 +0300 Message-Id: <20211025104449.26693-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 v3] replication: the truncate method called from within a transaction 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" The truncate method could be called from within a transaction. The flag of GROUP_LOCAL was set in truncate method after statement row had been being checked on the GROUP_LOCAL. Accordingly, after a local transaction NOP row was not appended. Closes #6123 --- Issue: https://github.com/tarantool/tarantool/issues/6123 Patch: https://github.com/tarantool/tarantool/tree/yshtunder/gh-6123-truncate-is-local-transaction src/box/alter.cc | 5 ++ test/replication-luatest/gh_6123_test.lua | 62 +++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/replication-luatest/gh_6123_test.lua diff --git a/src/box/alter.cc b/src/box/alter.cc index 31ac82fc5..52b9ea4d2 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2914,6 +2914,11 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event) if (space_is_temporary(old_space) || space_group_id(old_space) == GROUP_LOCAL) { stmt->row->group_id = GROUP_LOCAL; + /* + * The trigger is invoked after txn->n_local_rows + * is counted, so don't forget to update it here. + */ + ++txn->n_local_rows; } try { diff --git a/test/replication-luatest/gh_6123_test.lua b/test/replication-luatest/gh_6123_test.lua new file mode 100644 index 000000000..d0ffa0c8b --- /dev/null +++ b/test/replication-luatest/gh_6123_test.lua @@ -0,0 +1,62 @@ +local fio = require('fio') +local log = require('log') +local t = require('luatest') +local cluster = require('test.luatest_helpers.cluster') +local helpers = require('test.luatest_helpers.helpers') + +local g = t.group('gh-6123') + +g.before_test('test_truncate_is_local_transaction', function() + g.cluster = cluster:new({}) + + local box_cfg = { + replication = { + helpers.instance_uri('master') + }, + replication_timeout = 0.1, + read_only = false + } + + g.master = g.cluster:build_server({alias = 'master'}, engine, box_cfg) + + local box_cfg = { + replication = { + helpers.instance_uri('master'), + helpers.instance_uri('replica') + }, + replication_timeout = 0.1, + replication_connect_timeout = 0.5, + read_only = true + } + + g.replica = g.cluster:build_server({alias = 'replica'}, engine, box_cfg) + + g.cluster:join_server(g.master) + g.cluster:join_server(g.replica) + g.cluster:start() + log.info('Everything is started') +end) + +g.after_test('test_truncate_is_local_transaction', function() + g.cluster:stop() + fio.rmtree(g.master.workdir) + fio.rmtree(g.replica.workdir) +end) + +g.test_truncate_is_local_transaction = function() + g.master:eval("s = box.schema.space.create('temp', {temporary = true})") + g.master:eval("s:create_index('pk')") + + g.master:eval("s:insert{1, 2}") + g.master:eval("s:insert{4}") + t.assert_equals(g.master:eval("return s:select()"), {{1, 2}, {4}}) + + g.master:eval("box.begin() box.space._schema:replace{'smth'} s:truncate() box.commit()") + t.assert_equals(g.master:eval("return s:select()"), {}) + t.assert_equals(g.master:eval("return box.space._schema:select{'smth'}"), {{'smth'}}) + + -- Checking that replica has received the last transaction, + -- and that replication isn't broken. + t.assert_equals(g.replica:eval("return box.space._schema:select{'smth'}"), {{'smth'}}) + t.assert_equals(g.replica:eval("return box.info.replication[1].upstream.status"), 'follow') +end -- 2.25.1