From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 23/25] txn: add helper to detect transaction boundaries Date: Fri, 27 Jul 2018 14:30:03 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Add txn_is_first_statement() function, which returns true if this is the first statement of the transaction. The function is supposed to be used from on_replace trigger to detect transaction boundaries. Needed for #2129 --- src/box/txn.c | 3 +-- src/box/txn.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index 8947ac35..17d97d76 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -398,8 +398,7 @@ txn_abort(struct txn *txn) int txn_check_singlestatement(struct txn *txn, const char *where) { - if (!txn->is_autocommit || - stailq_last(&txn->stmts) != stailq_first(&txn->stmts)) { + if (!txn->is_autocommit || !txn_is_first_statement(txn)) { diag_set(ClientError, ER_UNSUPPORTED, where, "multi-statement transactions"); return -1; diff --git a/src/box/txn.h b/src/box/txn.h index 9a1f175a..19330b1f 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -280,6 +280,17 @@ txn_rollback_stmt(); int txn_check_singlestatement(struct txn *txn, const char *where); +/** + * Returns true if the transaction has a single statement. + * Supposed to be used from a space on_replace trigger to + * detect transaction boundaries. + */ +static inline bool +txn_is_first_statement(struct txn *txn) +{ + return stailq_last(&txn->stmts) == stailq_first(&txn->stmts); +} + /** The current statement of the transaction. */ static inline struct txn_stmt * txn_current_stmt(struct txn *txn) -- 2.11.0