Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 1/3] txn: move fk_deferred_count from psql_txn to txn
Date: Wed,  7 Aug 2019 18:13:12 +0300	[thread overview]
Message-ID: <c65e460c8777263f8c75ee9c05826ce6ed479f5b.1565190104.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1565190104.git.korablev@tarantool.org>
In-Reply-To: <cover.1565190104.git.korablev@tarantool.org>

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

  reply	other threads:[~2019-08-07 15:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07 15:13 [tarantool-patches] [PATCH 0/3] Merge struct sql_txn into struct txn/savepoint Nikita Pettik
2019-08-07 15:13 ` Nikita Pettik [this message]
2019-08-09 20:59   ` [tarantool-patches] Re: [PATCH 1/3] txn: move fk_deferred_count from psql_txn to txn Vladislav Shpilevoy
2019-08-15 11:03     ` n.pettik
2019-08-07 15:13 ` [tarantool-patches] [PATCH 2/3] txn: merge struct sql_txn into struct txn Nikita Pettik
2019-08-07 15:26   ` [tarantool-patches] " Konstantin Osipov
2019-08-09 21:02   ` Vladislav Shpilevoy
2019-08-12 21:55     ` Konstantin Osipov
2019-08-15 11:04     ` n.pettik
2019-08-15 22:03       ` Vladislav Shpilevoy
2019-08-16 18:52         ` n.pettik
2019-08-19 20:47           ` Vladislav Shpilevoy
2019-08-21  0:23             ` n.pettik
2019-08-21 20:45               ` Vladislav Shpilevoy
2019-08-07 15:13 ` [tarantool-patches] [PATCH 3/3] sql: use struct txn_savepoint as anonymous savepoint Nikita Pettik
2019-08-07 15:26 ` [tarantool-patches] Re: [PATCH 0/3] Merge struct sql_txn into struct txn/savepoint Konstantin Osipov
2019-08-22 11:56 ` Kirill Yukhin

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=c65e460c8777263f8c75ee9c05826ce6ed479f5b.1565190104.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 1/3] txn: move fk_deferred_count from psql_txn to txn' \
    /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