From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 2/5] txn: run on_rollback triggers on txn_abort Date: Fri, 5 Jul 2019 23:25:28 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: 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