Tarantool development patches archive
 help / color / mirror / Atom feed
From: Yan Shtunder via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: sergepetrenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org,
	Yan Shtunder <ya.shtunder@gmail.com>
Subject: [Tarantool-patches] [PATCH] replication: the truncate method called from within a transaction
Date: Fri, 27 Aug 2021 15:19:15 +0300	[thread overview]
Message-ID: <20210827121915.260936-1-ya.shtunder@gmail.com> (raw)

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


             reply	other threads:[~2021-08-27 12:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 12:19 Yan Shtunder via Tarantool-patches [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-09-21 16:31 Yan Shtunder via Tarantool-patches
2021-09-27  6:31 ` Serge Petrenko via Tarantool-patches
2021-08-25  5:54 Yan Shtunder via Tarantool-patches
2021-08-25 12:45 ` Serge Petrenko via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210827121915.260936-1-ya.shtunder@gmail.com \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=ya.shtunder@gmail.com \
    --subject='Re: [Tarantool-patches] [PATCH] replication: the truncate method called from within a transaction' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox