Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 3/5] txn: fix execution order of commit triggers
Date: Fri,  5 Jul 2019 23:25:29 +0300	[thread overview]
Message-ID: <1666e64764af9d1a144461078137fb5a7485ee34.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>

Both commit and rollback triggers are currently added to the list head.
As a result, they are both run in the reverse order. This is correct for
rollback triggers, because this matches the order in which statements
that added the triggers are rolled back, but this is wrong for commit
triggers. For example, suppose we create a space and then create an
index for it in the same transaction. We expect that on success we first
run the trigger that commits the space and only then the trigger that
commits the index, not vice versa. That said, reverse the order of
commit triggers in the scope of preparations for transactional DDL.
---
 src/box/txn.h          | 13 +++++++++++--
 src/lib/core/trigger.h | 11 +++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/box/txn.h b/src/box/txn.h
index a19becce..d1ef220a 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -198,7 +198,16 @@ struct txn {
 	 * in case a fiber stops (all engines).
 	 */
 	struct trigger fiber_on_stop;
-	 /** Commit and rollback triggers */
+	/**
+	 * Commit and rollback triggers.
+	 *
+	 * Note, we commit triggers are added to the tail of
+	 * the list while rollback triggers are added to the
+	 * head, see txn_on_commit() and txn_on_rollback().
+	 * This ensures that the triggers are fired in the
+	 * same order as statements that added them, both on
+	 * commit and on rollback.
+	 */
 	struct rlist on_commit, on_rollback;
 	struct sql_txn *psql_txn;
 };
@@ -279,7 +288,7 @@ static inline void
 txn_on_commit(struct txn *txn, struct trigger *trigger)
 {
 	txn_init_triggers(txn);
-	trigger_add(&txn->on_commit, trigger);
+	trigger_add_tail(&txn->on_commit, trigger);
 }
 
 static inline void
diff --git a/src/lib/core/trigger.h b/src/lib/core/trigger.h
index d3ffb9a8..4bc4da1a 100644
--- a/src/lib/core/trigger.h
+++ b/src/lib/core/trigger.h
@@ -84,6 +84,17 @@ trigger_add(struct rlist *list, struct trigger *trigger)
 	rlist_add_entry(list, trigger, link);
 }
 
+/**
+ * Same as trigger_add(), but adds a trigger to the tail of the list
+ * rather than to the head. Use it when you need to ensure a certain
+ * execution order among triggers.
+ */
+static inline void
+trigger_add_tail(struct rlist *list, struct trigger *trigger)
+{
+	rlist_add_tail_entry(list, trigger, link);
+}
+
 static inline void
 trigger_add_unique(struct rlist *list, struct trigger *trigger)
 {
-- 
2.11.0

  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 ` [PATCH 2/5] txn: run on_rollback triggers on txn_abort Vladimir Davydov
2019-07-08  9:32   ` 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 ` Vladimir Davydov [this message]
2019-07-08 12:17   ` [PATCH 3/5] txn: fix execution order of commit triggers 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=1666e64764af9d1a144461078137fb5a7485ee34.1562357452.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 3/5] txn: fix execution order of commit triggers' \
    /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