[PATCH 1.7 1/4] txn: zap txn_savepoint->is_first flag
Vladimir Davydov
vdavydov.dev at gmail.com
Tue Jan 23 13:06:11 MSK 2018
This flag isn't necessary as we can set txn_savepoint->stmt to NULL when
a savepoint is created inside an empty transaction. Using a separate
flag for this purpose obscures the code flow and complicates further
progress so let's remove it.
---
src/box/txn.c | 23 +++++++++++++----------
src/box/txn.h | 9 +++------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/box/txn.c b/src/box/txn.c
index f7ea122e..b09df8c6 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -456,12 +456,7 @@ box_txn_savepoint()
"region", "struct txn_savepoint");
return NULL;
}
- if (stailq_empty(&txn->stmts)) {
- svp->is_first = true;
- return svp;
- }
- svp->is_first = false;
- svp->stmt = txn_last_stmt(txn);
+ svp->stmt = stailq_last(&txn->stmts);
svp->in_sub_stmt = txn->in_sub_stmt;
return svp;
}
@@ -474,14 +469,22 @@ box_txn_rollback_to_savepoint(box_txn_savepoint_t *svp)
diag_set(ClientError, ER_SAVEPOINT_NO_TRANSACTION);
return -1;
}
- struct txn_stmt *stmt = svp->stmt;
- if (!svp->is_first && (stmt == NULL || stmt->space == NULL ||
- svp->in_sub_stmt != txn->in_sub_stmt)) {
+ struct txn_stmt *stmt = svp->stmt == NULL ? NULL :
+ stailq_entry(svp->stmt, struct txn_stmt, next);
+ if (stmt != NULL && stmt->space == NULL) {
+ /*
+ * The statement at which this savepoint was
+ * created has been rolled back.
+ */
+ diag_set(ClientError, ER_NO_SUCH_SAVEPOINT);
+ return -1;
+ }
+ if (svp->in_sub_stmt != txn->in_sub_stmt) {
diag_set(ClientError, ER_NO_SUCH_SAVEPOINT);
return -1;
}
struct stailq rollback_stmts;
- if (svp->is_first) {
+ if (stmt == NULL) {
rollback_stmts = txn->stmts;
stailq_create(&txn->stmts);
} else {
diff --git a/src/box/txn.h b/src/box/txn.h
index ac208d5e..f9f25d5d 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -82,13 +82,10 @@ struct txn_savepoint {
/**
* Statement, on which a savepoint is created. On rollback
* to this savepoint all newer statements are rolled back.
+ * Initialized to NULL in case a savepoint is created in
+ * an empty transaction.
*/
- struct txn_stmt *stmt;
- /**
- * True, if a savepoint is created when a transaction is
- * empty. In such a case stmt can not be used.
- */
- bool is_first;
+ struct stailq_entry *stmt;
};
extern double too_long_threshold;
--
2.11.0
More information about the Tarantool-patches
mailing list