Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a3c7add

Browse files
committed
port SavepointContexts
1 parent 509e809 commit a3c7add

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/backend/access/transam/xact.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ typedef struct TransactionStateData
179179
SubTransactionId subTransactionId; /* my subxact ID */
180180
char *name; /* savepoint name, if any */
181181
int savepointLevel; /* savepoint level */
182+
void* savepointContext; /* savepoint XTM context */
182183
TransState state; /* low-level state */
183184
TBlockState blockState; /* high-level state */
184185
int nestingLevel; /* transaction nesting depth */
@@ -210,6 +211,7 @@ static TransactionStateData TopTransactionStateData = {
210211
0, /* subtransaction id */
211212
NULL, /* savepoint name */
212213
0, /* savepoint level */
214+
NULL, /* savepoint context */
213215
TRANS_DEFAULT, /* transaction state */
214216
TBLOCK_DEFAULT, /* transaction block state from the client
215217
* perspective */
@@ -4264,6 +4266,7 @@ ReleaseSavepoint(List *options)
42644266
{
42654267
Assert(xact->blockState == TBLOCK_SUBINPROGRESS);
42664268
xact->blockState = TBLOCK_SUBRELEASE;
4269+
TM->ReleaseSavepointContext(xact->savepointContext);
42674270
if (xact == target)
42684271
break;
42694272
xact = xact->parent;
@@ -4383,9 +4386,11 @@ RollbackToSavepoint(List *options)
43834386
else
43844387
elog(FATAL, "RollbackToSavepoint: unexpected state %s",
43854388
BlockStateAsString(xact->blockState));
4389+
TM->ReleaseSavepointContext(xact->savepointContext);
43864390
xact = xact->parent;
43874391
Assert(PointerIsValid(xact));
43884392
}
4393+
TM->RestoreSavepointContext(xact->savepointContext);
43894394

43904395
/* And mark the target as "restart pending" */
43914396
if (xact->blockState == TBLOCK_SUBINPROGRESS)
@@ -4563,6 +4568,8 @@ RollbackAndReleaseCurrentSubTransaction(void)
45634568
CleanupSubTransaction();
45644569

45654570
s = CurrentTransactionState; /* changed by pop */
4571+
TM->RestoreSavepointContext(s->savepointContext);
4572+
45664573
AssertState(s->blockState == TBLOCK_SUBINPROGRESS ||
45674574
s->blockState == TBLOCK_INPROGRESS ||
45684575
s->blockState == TBLOCK_STARTED);
@@ -5141,6 +5148,7 @@ PushTransaction(void)
51415148
GetUserIdAndSecContext(&s->prevUser, &s->prevSecContext);
51425149
s->prevXactReadOnly = XactReadOnly;
51435150
s->parallelModeLevel = 0;
5151+
s->savepointContext = TM->CreateSavepointContext();
51445152

51455153
CurrentTransactionState = s;
51465154

@@ -5171,6 +5179,7 @@ PopTransaction(void)
51715179
if (s->parent == NULL)
51725180
elog(FATAL, "PopTransaction with no parent");
51735181

5182+
TM->ReleaseSavepointContext(s->savepointContext);
51745183
CurrentTransactionState = s->parent;
51755184

51765185
/* Let's just make sure CurTransactionContext is good */

src/backend/access/transam/xtm.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ void PgInitializeSequence(int64* init, int64* step)
5858
*step = 1;
5959
}
6060

61+
void* PgCreateSavepointContext(void)
62+
{
63+
return NULL;
64+
}
65+
66+
void PgRestoreSavepointContext(void* ctx)
67+
{
68+
}
69+
70+
void PgReleaseSavepointContext(void* ctx)
71+
{
72+
}
73+
6174

6275
TransactionManager PgTM = {
6376
PgTransactionIdGetStatus,
@@ -73,7 +86,10 @@ TransactionManager PgTM = {
7386
PgGetTransactionStateSize,
7487
PgSerializeTransactionState,
7588
PgDeserializeTransactionState,
76-
PgInitializeSequence
89+
PgInitializeSequence,
90+
PgCreateSavepointContext,
91+
PgRestoreSavepointContext,
92+
PgReleaseSavepointContext
7793
};
7894

7995
TransactionManager *TM = &PgTM;

src/include/access/xtm.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ typedef struct
9494
*/
9595
void (*InitializeSequence)(int64* start, int64* step);
9696

97+
/*
98+
* Create custom savepoint context.
99+
* This function can be used to accociate any data with savepoint which will be used by RestoreSavepointContext function to restore context
100+
*/
101+
void* (*CreateSavepointContext)(void);
102+
103+
/*
104+
* Restore context saved by CreateSavepointContext
105+
*/
106+
void (*RestoreSavepointContext)(void* ctx);
107+
108+
/*
109+
* Release context saved by CreateSavepointContext
110+
*/
111+
void (*ReleaseSavepointContext)(void* ctx);
112+
97113
} TransactionManager;
98114

99115
/* Get pointer to transaction manager: actually returns content of TM variable */
@@ -128,6 +144,9 @@ extern size_t PgGetTransactionStateSize(void);
128144
extern void PgSerializeTransactionState(void* ctx);
129145
extern void PgDeserializeTransactionState(void* ctx);
130146
extern void PgInitializeSequence(int64* start, int64* step);
147+
extern void* PgCreateSavepointContext(void);
148+
extern void PgRestoreSavepointContext(void*);
149+
extern void PgReleaseSavepointContext(void*);
131150

132151

133152
#endif

0 commit comments

Comments
 (0)