[tarantool-patches] [PATCH 3/3] sql: use struct txn_savepoint as anonymous savepoint
Nikita Pettik
korablev at tarantool.org
Wed Aug 7 18:13:14 MSK 2019
This allows us to completely remove SQL specific struct Savepoint and
use instead original struct txn_savepoint.
---
src/box/sql/sqlInt.h | 13 -------------
src/box/sql/vdbe.c | 2 +-
src/box/sql/vdbeInt.h | 6 ++----
src/box/sql/vdbeaux.c | 30 ++----------------------------
4 files changed, 5 insertions(+), 46 deletions(-)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 87e5d22ee..c61605046 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1050,7 +1050,6 @@ typedef struct NameContext NameContext;
typedef struct Parse Parse;
typedef struct PrintfArguments PrintfArguments;
typedef struct RowSet RowSet;
-typedef struct Savepoint Savepoint;
typedef struct Select Select;
typedef struct sqlThread sqlThread;
typedef struct SelectDest SelectDest;
@@ -1406,18 +1405,6 @@ enum trim_side_mask {
{nArg, (nc*SQL_FUNC_NEEDCOLL)|extraFlags, \
SQL_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}, type}
-/*
- * All current savepoints are stored in a linked list starting at
- * sql.pSavepoint. The first element in the list is the most recently
- * opened savepoint. Savepoints are added to the list by the vdbe
- * OP_Savepoint instruction.
- */
-struct Savepoint {
- box_txn_savepoint_t *tnt_savepoint; /* Tarantool's savepoint struct */
- char *zName; /* Savepoint name (nul-terminated) */
- Savepoint *pNext; /* Parent savepoint (if any) */
-};
-
/*
* The following are used as the second parameter to sqlSavepoint(),
* and as the P1 argument to the OP_Savepoint instruction.
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 7d05ce11c..9165db6c3 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2977,7 +2977,7 @@ case OP_TTransaction: {
if (sql_txn_begin() != 0)
goto abort_due_to_error;
} else {
- p->anonymous_savepoint = sql_savepoint(p, NULL);
+ p->anonymous_savepoint = txn_savepoint_new(in_txn(), NULL);
if (p->anonymous_savepoint == NULL)
goto abort_due_to_error;
}
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 5582d9506..f3e05a180 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -425,7 +425,7 @@ struct Vdbe {
/** Parser flags with which this object was built. */
uint32_t sql_flags;
/* Anonymous savepoint for aborts only */
- Savepoint *anonymous_savepoint;
+ struct txn_savepoint *anonymous_savepoint;
};
/*
@@ -455,9 +455,7 @@ int sqlVdbeExec(Vdbe *);
int sqlVdbeList(Vdbe *);
int
sql_txn_begin();
-Savepoint *
-sql_savepoint(Vdbe *p,
- const char *zName);
+
int sqlVdbeHalt(Vdbe *);
int sqlVdbeMemTooBig(Mem *);
int sqlVdbeMemCopy(Mem *, const Mem *);
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 3d256f86a..7e512dbea 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1937,12 +1937,12 @@ int
sqlVdbeCloseStatement(Vdbe * p, int eOp)
{
int rc = 0;
- const Savepoint *savepoint = p->anonymous_savepoint;
+ struct txn_savepoint *savepoint = p->anonymous_savepoint;
/*
* If we have an anonymous transaction opened -> perform eOp.
*/
if (savepoint && eOp == SAVEPOINT_ROLLBACK)
- rc = box_txn_rollback_to_savepoint(savepoint->tnt_savepoint);
+ rc = box_txn_rollback_to_savepoint(savepoint);
p->anonymous_savepoint = NULL;
return rc;
}
@@ -1984,32 +1984,6 @@ sql_txn_begin()
return 0;
}
-Savepoint *
-sql_savepoint(MAYBE_UNUSED Vdbe *p, const char *zName)
-{
- assert(p);
- size_t nName = zName ? strlen(zName) + 1 : 0;
- size_t savepoint_sz = sizeof(Savepoint) + nName;
- Savepoint *pNew;
-
- pNew = (Savepoint *)region_aligned_alloc(&fiber()->gc,
- savepoint_sz,
- alignof(Savepoint));
- if (pNew == NULL) {
- diag_set(OutOfMemory, savepoint_sz, "region",
- "savepoint");
- return NULL;
- }
- pNew->tnt_savepoint = box_txn_savepoint();
- if (!pNew->tnt_savepoint)
- return NULL;
- if (zName) {
- pNew->zName = (char *)&pNew[1];
- memcpy(pNew->zName, zName, nName);
- };
- return pNew;
-}
-
/*
* This routine is called the when a VDBE tries to halt. If the VDBE
* has made changes and is in autocommit mode, then commit those
--
2.15.1
More information about the Tarantool-patches
mailing list