Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH 2/4] txn: reverse commit trigger list only before running commit triggers
Date: Fri, 19 Jul 2019 21:08:40 +0300	[thread overview]
Message-ID: <833a22aef0330df6291250b3f9acb9461ff0cf55.1563559254.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1563559254.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1563559254.git.vdavydov.dev@gmail.com>

Commit triggers must be run in the same order they are added, see commit
013432641283 ("txn: fix execution order of commit triggers"). To achieve
that we added a new trigger method, trigger_add_tail(), which adds new
triggers to the trigger list tail rather than to the head, and now we
use this new method for adding commit triggers.

Come to think of it now, that solution was rather confusing. First,
commit triggers are still added to the head of the list from Lua.
Second, to revert triggers on rollback-to-savepoint it would be really
more convenient to have both commit and rollback trigger lists have the
same order.

So this patch reverts the above-mentioned commit and instead simply
applies rlist_reverse to the commit trigger list before running them.
---
 src/box/txn.c                  | 10 +++++++++-
 src/box/txn.h                  | 13 ++-----------
 src/lib/core/trigger.h         | 11 -----------
 test/engine/transaction.result |  4 ++--
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/box/txn.c b/src/box/txn.c
index 73eaee73..0a42d440 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -381,8 +381,16 @@ txn_complete(struct txn *txn)
 		/* Commit the transaction. */
 		if (txn->engine != NULL)
 			engine_commit(txn->engine, txn);
-		if (txn->has_triggers)
+		if (txn->has_triggers) {
+			/*
+			 * Commit triggers must be run in the same
+			 * order they were added. Since triggers
+			 * are always added to the list head, we
+			 * need to reverse the list.
+			 */
+			rlist_reverse(&txn->on_commit);
 			txn_run_triggers(txn, &txn->on_commit);
+		}
 
 		double stop_tm = ev_monotonic_now(loop());
 		if (stop_tm - txn->start_tm > too_long_threshold) {
diff --git a/src/box/txn.h b/src/box/txn.h
index baeaa0ed..df173924 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -203,16 +203,7 @@ struct txn {
 	 * in case a fiber stops (all engines).
 	 */
 	struct trigger fiber_on_stop;
-	/**
-	 * 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.
-	 */
+	/** Commit and rollback triggers. */
 	struct rlist on_commit, on_rollback;
 	struct sql_txn *psql_txn;
 };
@@ -282,7 +273,7 @@ static inline void
 txn_on_commit(struct txn *txn, struct trigger *trigger)
 {
 	txn_init_triggers(txn);
-	trigger_add_tail(&txn->on_commit, trigger);
+	trigger_add(&txn->on_commit, trigger);
 }
 
 static inline void
diff --git a/src/lib/core/trigger.h b/src/lib/core/trigger.h
index 4bc4da1a..d3ffb9a8 100644
--- a/src/lib/core/trigger.h
+++ b/src/lib/core/trigger.h
@@ -84,17 +84,6 @@ 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)
 {
diff --git a/test/engine/transaction.result b/test/engine/transaction.result
index b18b025c..910abb58 100644
--- a/test/engine/transaction.result
+++ b/test/engine/transaction.result
@@ -377,10 +377,10 @@ inspector:cmd("setopt delimiter ''");
 -- Yes, the order is reversed. Like all other Lua triggers.
 call_list
 ---
-- - on_commit_3
+- - on_commit_1
+  - on_commit_3
   - on_commit_3
   - on_commit_3
-  - on_commit_1
 ...
 funcs
 ---
-- 
2.11.0

  parent reply	other threads:[~2019-07-19 18:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19 18:08 [PATCH 0/4] Support savepoints in DDL transactions Vladimir Davydov
2019-07-19 18:08 ` [PATCH 1/4] Update small library Vladimir Davydov
2019-07-24 22:48   ` [tarantool-patches] " Konstantin Osipov
2019-07-25  9:23     ` Vladimir Davydov
2019-07-19 18:08 ` Vladimir Davydov [this message]
2019-07-24 22:48   ` [tarantool-patches] Re: [PATCH 2/4] txn: reverse commit trigger list only before running commit triggers Konstantin Osipov
2019-07-25  9:24     ` Vladimir Davydov
2019-07-25  9:29       ` Konstantin Osipov
2019-07-25  9:35         ` Vladimir Davydov
2019-07-25 14:56           ` Vladimir Davydov
2019-07-26 19:25             ` Konstantin Osipov
2019-07-29  8:45               ` Vladimir Davydov
2019-07-19 18:08 ` [PATCH 3/4] txn: use savepoints to roll back statements on yield or error Vladimir Davydov
2019-07-24 22:55   ` [tarantool-patches] " Konstantin Osipov
2019-07-24 23:19     ` Konstantin Osipov
2019-07-25  9:28       ` Vladimir Davydov
2019-07-25 11:57     ` Vladimir Davydov
2019-07-19 18:08 ` [PATCH 4/4] txn: undo commit/rollback triggers when reverting to savepoint Vladimir Davydov
2019-07-19 19:36   ` [tarantool-patches] " Vladislav Shpilevoy
2019-07-19 19:42     ` Vladimir Davydov
2019-07-26  8:56   ` Vladimir Davydov
2019-07-29 13:11   ` [tarantool-patches] " Konstantin Osipov
2019-07-30 10:54     ` 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=833a22aef0330df6291250b3f9acb9461ff0cf55.1563559254.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 2/4] txn: reverse commit trigger list only before running 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