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 CC6EE6EC55; Fri, 27 Aug 2021 15:19:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CC6EE6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630066761; bh=yryPGUxkvJ9y/5OD81l4m60KUZ7ARxRwVGbS+rAQsBo=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=LFWfEY75LsN1jRn83BosTC93X8UbuZTEqZlHqEuua+N42TQaHQFnKzsRDi/5jTFf6 WJPL2X38/QAEQCKVr6Fnv+2tnJsgehy5xf4YzAjJ2dfJkD37PiiXZA6gszBZ71mBhf 7lNJ/sdM6RVateOcaUATGhu3Ns+9OVaL8IeL2Vx4= Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 7DF0D6EC55 for ; Fri, 27 Aug 2021 15:19:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7DF0D6EC55 Received: by mail-lj1-f171.google.com with SMTP id j12so11008538ljg.10 for ; Fri, 27 Aug 2021 05:19:20 -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=U5V4ld/EsavqzISZh66fhLWHBGq9aayx7DJLj1x3E0A=; b=e4MA5CQ/YJ66CC8qSiCrsnxTvvMzY/r7tFmPqGFaFEDCzdqHjAVb+bjrjVfS/ltBnO e12vpU+tA8ytwsa/D/ngMgOZSTUNYzkM6ttMZxadNNe1OwytPJhbIMahQaO7xVDBribP J15fD8OxYj2mmIU9GuQjjKvUbXGbnQOuCiTc0H2HxLwtpY/vZaCfbQCk5LqlueA/+9ng 1eabZzh6klQCibwj7dUiqOMhND+P8Zq9ymhqtYjsOfYmvST9DTh5aCpmInuD/r28vIpa 8N9uUvxDw9EDv0dWxDq3khavdUICHHmuKrjDIQxS5J1pYrUWW90E7y5LYv4iWywTpQzx x8Yw== X-Gm-Message-State: AOAM533RH3o8z+SWAR3XlWXWXkecOcnr98pqZnLxxYF8r+/8iQilqnK7 xvlXDQCPy2i5BpPtyvHU7zbWw11INRY= X-Google-Smtp-Source: ABdhPJzB1o7oa3/WtcoMppDE99lTlRkuryjj33xtLUAFdVJmFDq6VPtdvslBDNvx06XnRtHcC8atnQ== X-Received: by 2002:a2e:a889:: with SMTP id m9mr7406713ljq.195.1630066759898; Fri, 27 Aug 2021 05:19:19 -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 f25sm651526ljj.69.2021.08.27.05.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Aug 2021 05:19:19 -0700 (PDT) To: sergepetrenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org, Yan Shtunder Date: Fri, 27 Aug 2021 15:19:15 +0300 Message-Id: <20210827121915.260936-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: 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 | 11 +++ ...-6123-truncate-is-local-transaction.result | 90 +++++++++++++++++++ ...123-truncate-is-local-transaction.test.lua | 36 ++++++++ 3 files changed, 137 insertions(+) create mode 100644 test/replication/gh-6123-truncate-is-local-transaction.result create mode 100644 test/replication/gh-6123-truncate-is-local-transaction.test.lua diff --git a/src/box/alter.cc b/src/box/alter.cc index 89bb5946c..35bd603d0 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2901,6 +2901,17 @@ 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; + /* + * In order to append a dummy NOP statement + * to preserve the tx replication boundaries, + * it is necessary that the condition + * txn->n_local_rows > 0 must be true. + * Therefore it is necessary to increase the + * value of n_local_rows, because the checking + * on the flag of GROUP_LOCAL will occurs + * before it is set. + */ + ++txn->n_local_rows; } try { diff --git a/test/replication/gh-6123-truncate-is-local-transaction.result b/test/replication/gh-6123-truncate-is-local-transaction.result new file mode 100644 index 000000000..db57d37d8 --- /dev/null +++ b/test/replication/gh-6123-truncate-is-local-transaction.result @@ -0,0 +1,90 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... + + +-- Step 1 +box.schema.user.grant("guest", "replication") + | --- + | ... +s = box.schema.space.create("temp", {temporary=true}) + | --- + | ... +_ = s:create_index('pk') + | --- + | ... +s:insert{1,2} + | --- + | - [1, 2] + | ... +s:insert{4} + | --- + | - [4] + | ... +s:select() + | --- + | - - [1, 2] + | - [4] + | ... + + +-- Step 2 +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') + | --- + | - true + | ... +test_run:cmd('start server replica') + | --- + | - true + | ... + + +-- Step 3 +box.begin() box.space._schema:replace{"smth"} s:truncate() box.commit() + | --- + | ... +s:select() + | --- + | - [] + | ... +box.space._schema:select{'smth'} + | --- + | - - ['smth'] + | ... + + +-- Step 4 +-- Checking that replica has received the last transaction, +-- and that replication isn't broken. +test_run:switch('replica') + | --- + | - true + | ... +box.space._schema:select{'smth'} + | --- + | - - ['smth'] + | ... +box.info.replication[1].upstream.status + | --- + | - follow + | ... + + +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-6123-truncate-is-local-transaction.test.lua b/test/replication/gh-6123-truncate-is-local-transaction.test.lua new file mode 100644 index 000000000..336c0c44d --- /dev/null +++ b/test/replication/gh-6123-truncate-is-local-transaction.test.lua @@ -0,0 +1,36 @@ +test_run = require('test_run').new() + + +-- Step 1 +box.schema.user.grant("guest", "replication") +s = box.schema.space.create("temp", {temporary=true}) +_ = s:create_index('pk') +s:insert{1,2} +s:insert{4} +s:select() + + +-- Step 2 +test_run:cmd('create server replica with rpl_master=default,\ + script="replication/replica.lua"') +test_run:cmd('start server replica') + + +-- Step 3 +box.begin() box.space._schema:replace{"smth"} s:truncate() box.commit() +s:select() +box.space._schema:select{'smth'} + + +-- Step 4 +-- Checking that replica has received the last transaction, +-- and that replication isn't broken. +test_run:switch('replica') +box.space._schema:select{'smth'} +box.info.replication[1].upstream.status + + +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