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 A6B846EC55; Wed, 25 Aug 2021 08:54:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A6B846EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629870896; bh=M+gYZdU1LeUtJdEDaMC+tVtyR0D0jxaJ3ufWdtr/sEo=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZVnTXOJAoxhC35kGiJU4IjM/Qe5aL8eGZdTP2h8hw37vCVZX4zMFJtUKHy8fY+9ev vpfO/6tufpfAXVhPn0AvEpFYQ6h1uis8JIIAXhK6rFh3GAIqHFyvAKmCHv30o27g1f Kl5drgfu2NpMomUncHyoZKtV+PWwZGiRrgm18EZA= Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 81E136EC55 for ; Wed, 25 Aug 2021 08:54:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 81E136EC55 Received: by mail-lj1-f182.google.com with SMTP id y6so41640323lje.2 for ; Tue, 24 Aug 2021 22:54: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=s3+jdu3fhw/aSiugyxjjkqAUMRqXkN2GhvDb5mIKqDw=; b=ptwS6AiErR8Yi+om/EAnu5PIw+UX15AAdjRTBOKoL6QxPZ5a6k+1QS4n0pGD5DeWRl HHVFS1VtGcppLfUxtAsmmaxI+FZBrnqq6MfjO2BuI0H1VmNpvodxn7idJFMC4bc9j+wE as7nJZroK4e6GpCnQ5INYySJPaNGBHzHDf8qzvVJsa4BaEFk52WWBwVILr5ouVCCfdLJ yxd//08ojGdDrRm1fa2UEzdAjivt4Q3COmgSJlRlMd1N7l/cqqNyD17GMy4N7RvHMjtH Ky+U82f0xVcWYD6wqKhWX1cvQc8D4LS0R1GT7cM6J2JQNCHZWfNUGXZCGklHBXDBJDaD y58w== X-Gm-Message-State: AOAM532ZTfWr5fwAzP7mfxC4OL7NqY9nD0pkQpps/e1HHW38B8tr3Hfg QcHGUiayhY6HHYglSpo0bio= X-Google-Smtp-Source: ABdhPJwuexVxvZVDFVpYbyK4KRoQANlRLHhN5dlemKIuzV+pivoIK+43s84ddWzWZAmiO8++i8t2Xg== X-Received: by 2002:a2e:824e:: with SMTP id j14mr1881134ljh.65.1629870894781; Tue, 24 Aug 2021 22:54: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 d4sm1955198lfg.127.2021.08.24.22.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 22:54:54 -0700 (PDT) To: sergepetrenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org, Yan Shtunder Date: Wed, 25 Aug 2021 08:54:51 +0300 Message-Id: <20210825055451.115351-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/txn.c | 16 +++-- ...-6123-truncate-is-local-transaction.result | 69 +++++++++++++++++++ ...123-truncate-is-local-transaction.test.lua | 27 ++++++++ 3 files changed, 107 insertions(+), 5 deletions(-) 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/txn.c b/src/box/txn.c index b80e722a4..d37bec7ae 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -397,6 +397,7 @@ txn_is_distributed(struct txn *txn) int txn_commit_stmt(struct txn *txn, struct request *request) { + int rc = 0; assert(txn->in_sub_stmt > 0); /* * Run on_replace triggers. For now, disallow mutation @@ -415,9 +416,6 @@ txn_commit_stmt(struct txn *txn, struct request *request) assert(stmt->row != NULL); if (stmt->row->replica_id == 0) { ++txn->n_new_rows; - if (stmt->row->group_id == GROUP_LOCAL) - ++txn->n_local_rows; - } else { ++txn->n_applier_rows; } @@ -447,10 +445,18 @@ txn_commit_stmt(struct txn *txn, struct request *request) */ stmt->does_require_old_tuple = true; - if(trigger_run(&stmt->space->on_replace, txn) != 0) - goto fail; + rc = trigger_run(&stmt->space->on_replace, txn); } } + + if (stmt->row != NULL && stmt->row->replica_id == 0 && + stmt->row->group_id == GROUP_LOCAL) { + ++txn->n_local_rows; + } + + if (rc != 0) + goto fail; + --txn->in_sub_stmt; return 0; fail: 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..0a4b990c1 --- /dev/null +++ b/test/replication/gh-6123-truncate-is-local-transaction.result @@ -0,0 +1,69 @@ +-- 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'] + | ... + + +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..b68514d0b --- /dev/null +++ b/test/replication/gh-6123-truncate-is-local-transaction.test.lua @@ -0,0 +1,27 @@ +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'} + + +test_run:cmd('stop server replica') +test_run:cmd('cleanup server replica') +test_run:cmd('delete server replica') -- 2.25.1