From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 2/5] txn: run on_rollback triggers on txn_abort Date: Fri, 5 Jul 2019 23:25:28 +0300 [thread overview] Message-ID: <d6fe83bebdff89794593fd43d4d51431439a3fe5.1562357452.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1562357452.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1562357452.git.vdavydov.dev@gmail.com> When a memtx transaction is aborted on yield, it isn't enough to rollback individual statements - we must also run on_rollback triggers, otherwise changes done to the schema by an aborted DDL transaction will be visible to other fibers until an attempt to commit it is made. --- src/box/txn.c | 7 ++++++- test/box/transaction.result | 24 ++++++++++++++++++++++++ test/box/transaction.test.lua | 10 ++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/box/txn.c b/src/box/txn.c index 818f405b..5d80833a 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -346,6 +346,7 @@ txn_run_triggers(struct txn *txn, struct rlist *trigger) * Some triggers require for in_txn variable to be set so * restore it for the time triggers are in progress. */ + struct txn *old_txn = in_txn(); fiber_set_txn(fiber(), txn); /* Rollback triggers must not throw. */ if (trigger_run(trigger, txn) != 0) { @@ -357,7 +358,7 @@ txn_run_triggers(struct txn *txn, struct rlist *trigger) unreachable(); panic("commit/rollback trigger failed"); } - fiber_set_txn(fiber(), NULL); + fiber_set_txn(fiber(), old_txn); } /** @@ -556,6 +557,10 @@ void txn_abort(struct txn *txn) { txn_rollback_to_svp(txn, NULL); + if (txn->has_triggers) { + txn_run_triggers(txn, &txn->on_rollback); + txn->has_triggers = false; + } txn->is_aborted = true; } diff --git a/test/box/transaction.result b/test/box/transaction.result index 9da53e5b..857314b7 100644 --- a/test/box/transaction.result +++ b/test/box/transaction.result @@ -698,3 +698,27 @@ box.space.memtx:drop() box.space.vinyl:drop() --- ... +-- +-- Check that changes done to the schema by a DDL statement are +-- rolled back when the transaction is aborted on fiber yield. +-- +s = box.schema.space.create('test') +--- +... +box.begin() s:create_index('pk') s:insert{1} +--- +... +fiber.sleep(0) +--- +... +s.index.pk == nil +--- +- true +... +box.commit() -- error +--- +- error: Transaction has been aborted by a fiber yield +... +s:drop() +--- +... diff --git a/test/box/transaction.test.lua b/test/box/transaction.test.lua index a6789316..8ffae2fe 100644 --- a/test/box/transaction.test.lua +++ b/test/box/transaction.test.lua @@ -363,3 +363,13 @@ if box.space.test then box.space.test:drop() end box.space.memtx:drop() box.space.vinyl:drop() +-- +-- Check that changes done to the schema by a DDL statement are +-- rolled back when the transaction is aborted on fiber yield. +-- +s = box.schema.space.create('test') +box.begin() s:create_index('pk') s:insert{1} +fiber.sleep(0) +s.index.pk == nil +box.commit() -- error +s:drop() -- 2.11.0
next prev parent reply other threads:[~2019-07-05 20:25 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-05 20:25 [PATCH 0/5] Transactional DDL Vladimir Davydov 2019-07-05 20:25 ` [PATCH 1/5] vinyl: don't sync WAL on space alter if not necessary Vladimir Davydov 2019-07-08 9:29 ` Konstantin Osipov 2019-07-08 9:50 ` Vladimir Davydov 2019-07-08 15:01 ` Vladimir Davydov 2019-07-05 20:25 ` Vladimir Davydov [this message] 2019-07-08 9:32 ` [PATCH 2/5] txn: run on_rollback triggers on txn_abort Konstantin Osipov 2019-07-08 9:57 ` Vladimir Davydov 2019-07-08 12:14 ` Konstantin Osipov 2019-07-08 16:37 ` Vladimir Davydov 2019-07-08 21:56 ` Konstantin Osipov 2019-07-09 8:49 ` Vladimir Davydov 2019-07-05 20:25 ` [PATCH 3/5] txn: fix execution order of commit triggers Vladimir Davydov 2019-07-08 12:17 ` Konstantin Osipov 2019-07-08 15:01 ` Vladimir Davydov 2019-07-05 20:25 ` [PATCH 4/5] memtx: fix txn_on_yield for DDL transactions Vladimir Davydov 2019-07-08 12:22 ` Konstantin Osipov 2019-07-08 16:41 ` Vladimir Davydov 2019-07-08 16:58 ` Vladimir Davydov 2019-07-09 10:12 ` Vladimir Davydov 2019-07-08 21:57 ` Konstantin Osipov 2019-07-09 7:51 ` Vladimir Davydov 2019-07-05 20:25 ` [PATCH 5/5] Allow to execute non-yielding DDL statements in transactions Vladimir Davydov 2019-07-05 22:56 ` Konstantin Osipov 2019-07-08 8:09 ` Vladimir Davydov 2019-07-08 8:21 ` Konstantin Osipov 2019-07-08 8:43 ` Vladimir Davydov 2019-07-08 9:25 ` Konstantin Osipov 2019-07-08 16:46 ` Vladimir Davydov 2019-07-08 21:59 ` Konstantin Osipov 2019-07-08 12:26 ` Konstantin Osipov 2019-07-08 16:51 ` Vladimir Davydov 2019-07-08 22:02 ` Konstantin Osipov 2019-07-09 8:11 ` Vladimir Davydov 2019-07-09 11:03 ` Vladimir Davydov 2019-07-08 12:31 ` Konstantin Osipov 2019-07-08 17:00 ` Vladimir Davydov
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=d6fe83bebdff89794593fd43d4d51431439a3fe5.1562357452.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 2/5] txn: run on_rollback triggers on txn_abort' \ /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