Skip to content

Commit

Permalink
sql: remove VDBE from TXN
Browse files Browse the repository at this point in the history
VDBE was added to TXN because the generated identifiers were added
to VDBE in the sequence_next() function. Since they are now stored
in the VDBE itself, it is not necessary to have it in TXN.

Follow-up #4188
  • Loading branch information
ImeevMA committed Jul 3, 2019
1 parent 274add0 commit 1f40d81
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/box/sql/vdbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ case OP_CheckViewReferences: {
* Otherwise, raise an error with appropriate error message.
*/
case OP_TransactionBegin: {
if (sql_txn_begin(p) != 0)
if (sql_txn_begin() != 0)
goto abort_due_to_error;
p->auto_commit = false ;
break;
Expand Down Expand Up @@ -2980,7 +2980,7 @@ case OP_TransactionRollback: {
*/
case OP_TTransaction: {
if (!box_txn()) {
if (sql_txn_begin(p) != 0)
if (sql_txn_begin() != 0)
goto abort_due_to_error;
} else {
p->anonymous_savepoint = sql_savepoint(p, NULL);
Expand Down
3 changes: 1 addition & 2 deletions src/box/sql/vdbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ Vdbe *sqlVdbeCreate(Parse *);
* Allocate and initialize SQL-specific struct which completes
* original Tarantool's txn struct using region allocator.
*
* @param v Vdbe with which associate this transaction.
* @retval NULL on OOM, new psql_txn struct on success.
**/
struct sql_txn *
sql_alloc_txn(struct Vdbe *v);
sql_alloc_txn();

/**
* Prepare given VDBE to execution: initialize structs connected
Expand Down
2 changes: 1 addition & 1 deletion src/box/sql/vdbeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ u32 sqlVdbeSerialGet(const unsigned char *, u32, Mem *);
int sqlVdbeExec(Vdbe *);
int sqlVdbeList(Vdbe *);
int
sql_txn_begin(Vdbe *p);
sql_txn_begin();
Savepoint *
sql_savepoint(Vdbe *p,
const char *zName);
Expand Down
10 changes: 4 additions & 6 deletions src/box/sql/vdbeaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sqlVdbeCreate(Parse * pParse)
}

struct sql_txn *
sql_alloc_txn(struct Vdbe *v)
sql_alloc_txn()
{
struct sql_txn *txn = region_alloc_object(&fiber()->gc,
struct sql_txn);
Expand All @@ -86,7 +86,6 @@ sql_alloc_txn(struct Vdbe *v)
"struct sql_txn");
return NULL;
}
txn->vdbe = v;
txn->pSavepoint = NULL;
txn->fk_deferred_count = 0;
return txn;
Expand All @@ -106,11 +105,10 @@ sql_vdbe_prepare(struct Vdbe *vdbe)
* check FK violations, at least now.
*/
if (txn->psql_txn == NULL) {
txn->psql_txn = sql_alloc_txn(vdbe);
txn->psql_txn = sql_alloc_txn();
if (txn->psql_txn == NULL)
return -1;
}
txn->psql_txn->vdbe = vdbe;
}
return 0;
}
Expand Down Expand Up @@ -1997,7 +1995,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
}

int
sql_txn_begin(Vdbe *p)
sql_txn_begin()
{
if (in_txn()) {
diag_set(ClientError, ER_ACTIVE_TRANSACTION);
Expand All @@ -2006,7 +2004,7 @@ sql_txn_begin(Vdbe *p)
struct txn *ptxn = txn_begin(false);
if (ptxn == NULL)
return -1;
ptxn->psql_txn = sql_alloc_txn(p);
ptxn->psql_txn = sql_alloc_txn();
if (ptxn->psql_txn == NULL) {
box_txn_rollback();
return -1;
Expand Down
17 changes: 0 additions & 17 deletions src/box/txn.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ struct sql_txn {
* VDBE to the next in the same transaction.
*/
uint32_t fk_deferred_count;
/** Current VDBE. */
struct Vdbe *vdbe;
};

/**
Expand Down Expand Up @@ -396,21 +394,6 @@ txn_last_stmt(struct txn *txn)
void
txn_on_stop(struct trigger *trigger, void *event);

/**
* Return VDBE that is being currently executed.
*
* @retval VDBE that is being currently executed.
* @retval NULL Either txn or ptxn_sql or vdbe is NULL;
*/
static inline struct Vdbe *
txn_vdbe()
{
struct txn *txn = in_txn();
if (txn == NULL || txn->psql_txn == NULL)
return NULL;
return txn->psql_txn->vdbe;
}

/**
* FFI bindings: do not throw exceptions, do not accept extra
* arguments
Expand Down

0 comments on commit 1f40d81

Please sign in to comment.