[PATCH 23/25] txn: add helper to detect transaction boundaries
Vladimir Davydov
vdavydov.dev at gmail.com
Fri Jul 27 14:30:03 MSK 2018
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
More information about the Tarantool-patches
mailing list