[tarantool-patches] [PATCH 1/3] txn: move fk_deferred_count from psql_txn to txn
Nikita Pettik
korablev at tarantool.org
Wed Aug 7 18:13:12 MSK 2019
We are going to merge struct psql_txn with struct txn as a part of SQL
integration into NoSQL, so let's move counter of deferred foreign key
violations directly to struct txn.
---
src/box/sql/vdbe.c | 6 +++---
src/box/sql/vdbeaux.c | 4 +---
src/box/txn.c | 16 ++++++----------
src/box/txn.h | 6 +-----
4 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index e096e1f65..246654cb7 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2900,7 +2900,7 @@ case OP_Savepoint: {
assert(pSavepoint == psql_txn->pSavepoint);
psql_txn->pSavepoint = pSavepoint->pNext;
} else {
- psql_txn->fk_deferred_count =
+ txn->fk_deferred_count =
pSavepoint->tnt_savepoint->fk_deferred_count;
}
}
@@ -4844,7 +4844,7 @@ case OP_FkCounter: {
!p->auto_commit) {
struct txn *txn = in_txn();
assert(txn != NULL && txn->psql_txn != NULL);
- txn->psql_txn->fk_deferred_count += pOp->p2;
+ txn->fk_deferred_count += pOp->p2;
} else {
p->nFkConstraint += pOp->p2;
}
@@ -4868,7 +4868,7 @@ case OP_FkIfZero: { /* jump */
!p->auto_commit) {
struct txn *txn = in_txn();
assert(txn != NULL && txn->psql_txn != NULL);
- if (txn->psql_txn->fk_deferred_count == 0)
+ if (txn->fk_deferred_count == 0)
goto jump_to_p2;
} else {
if (p->nFkConstraint == 0)
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index e7accc745..bbbb99c70 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -87,7 +87,6 @@ sql_alloc_txn()
return NULL;
}
txn->pSavepoint = NULL;
- txn->fk_deferred_count = 0;
return txn;
}
@@ -1988,8 +1987,7 @@ int
sqlVdbeCheckFk(Vdbe * p, int deferred)
{
struct txn *txn = in_txn();
- if ((deferred && txn != NULL && txn->psql_txn != NULL &&
- txn->psql_txn->fk_deferred_count > 0) ||
+ if ((deferred && txn != NULL && txn->fk_deferred_count > 0) ||
(!deferred && p->nFkConstraint > 0)) {
p->is_aborted = true;
p->errorAction = ON_CONFLICT_ACTION_ABORT;
diff --git a/src/box/txn.c b/src/box/txn.c
index 53ebfc053..b57240846 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -222,6 +222,7 @@ txn_begin()
txn->engine = NULL;
txn->engine_tx = NULL;
txn->psql_txn = NULL;
+ txn->fk_deferred_count = 0;
txn->fiber = NULL;
fiber_set_txn(fiber(), txn);
/* fiber_on_yield is initialized by engine on demand */
@@ -537,12 +538,9 @@ txn_prepare(struct txn *txn)
* foreign key constraints must not be violated.
* If not so, just rollback transaction.
*/
- if (txn->psql_txn != NULL) {
- struct sql_txn *sql_txn = txn->psql_txn;
- if (sql_txn->fk_deferred_count != 0) {
- diag_set(ClientError, ER_FOREIGN_KEY_CONSTRAINT);
- return -1;
- }
+ if (txn->fk_deferred_count != 0) {
+ diag_set(ClientError, ER_FOREIGN_KEY_CONSTRAINT);
+ return -1;
}
/*
* Perform transaction conflict resolution. Engine == NULL when
@@ -754,8 +752,7 @@ box_txn_savepoint()
}
svp->stmt = stailq_last(&txn->stmts);
svp->in_sub_stmt = txn->in_sub_stmt;
- if (txn->psql_txn != NULL)
- svp->fk_deferred_count = txn->psql_txn->fk_deferred_count;
+ svp->fk_deferred_count = txn->fk_deferred_count;
return svp;
}
@@ -782,8 +779,7 @@ box_txn_rollback_to_savepoint(box_txn_savepoint_t *svp)
return -1;
}
txn_rollback_to_svp(txn, svp->stmt);
- if (txn->psql_txn != NULL)
- txn->psql_txn->fk_deferred_count = svp->fk_deferred_count;
+ txn->fk_deferred_count = svp->fk_deferred_count;
return 0;
}
diff --git a/src/box/txn.h b/src/box/txn.h
index 37d90932b..87e880a6a 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -135,11 +135,6 @@ extern double too_long_threshold;
struct sql_txn {
/** List of active SQL savepoints. */
struct Savepoint *pSavepoint;
- /**
- * This variables transfer deferred constraints from one
- * VDBE to the next in the same transaction.
- */
- uint32_t fk_deferred_count;
};
/**
@@ -213,6 +208,7 @@ struct txn {
struct trigger fiber_on_stop;
/** Commit and rollback triggers. */
struct rlist on_commit, on_rollback;
+ uint32_t fk_deferred_count;
struct sql_txn *psql_txn;
};
--
2.15.1
More information about the Tarantool-patches
mailing list