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

Commit 5824947

Browse files
committed
Add create/restore/release savepoint context methods to XTM
1 parent eb90a7d commit 5824947

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

contrib/mmts/multimaster.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ static bool MtmDetectGlobalDeadLock(PGPROC* proc);
146146
static void MtmAddSubtransactions(MtmTransState* ts, TransactionId* subxids, int nSubxids);
147147
static char const* MtmGetName(void);
148148
static size_t MtmGetTransactionStateSize(void);
149-
static void MtmSerializeTransactionState(void* ctx);
150-
static void MtmDeserializeTransactionState(void* ctx);
151-
static void MtmInitializeSequence(int64* start, int64* step);
149+
static void MtmSerializeTransactionState(void* ctx);
150+
static void MtmDeserializeTransactionState(void* ctx);
151+
static void MtmInitializeSequence(int64* start, int64* step);
152+
static void* MtmCreateSavepointContext(void);
153+
static void MtmRestoreSavepointContext(void* ctx);
154+
static void MtmReleaseSavepointContext(void* ctx);
152155

153156
static void MtmCheckClusterLock(void);
154157
static void MtmCheckSlots(void);
@@ -197,7 +200,10 @@ static TransactionManager MtmTM =
197200
MtmGetTransactionStateSize,
198201
MtmSerializeTransactionState,
199202
MtmDeserializeTransactionState,
200-
MtmInitializeSequence
203+
MtmInitializeSequence,
204+
MtmCreateSavepointContext,
205+
MtmRestoreSavepointContext,
206+
MtmReleaseSavepointContext
201207
};
202208

203209
char const* const MtmNodeStatusMnem[] =
@@ -466,6 +472,20 @@ MtmInitializeSequence(int64* start, int64* step)
466472
}
467473
}
468474

475+
static void* MtmCreateSavepointContext(void)
476+
{
477+
return (void*)(size_t)MtmTx.containsDML;
478+
}
479+
480+
static void MtmRestoreSavepointContext(void* ctx)
481+
{
482+
MtmTx.containsDML = ctx != NULL;
483+
}
484+
485+
static void MtmReleaseSavepointContext(void* ctx)
486+
{
487+
}
488+
469489

470490
/*
471491
* -------------------------------------------

src/backend/access/transam/xact.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ typedef struct TransactionStateData
176176
SubTransactionId subTransactionId; /* my subxact ID */
177177
char *name; /* savepoint name, if any */
178178
int savepointLevel; /* savepoint level */
179+
void* savepointContext; /* savepoint XTM context */
179180
TransState state; /* low-level state */
180181
TBlockState blockState; /* high-level state */
181182
int nestingLevel; /* transaction nesting depth */
@@ -4095,6 +4096,7 @@ DefineSavepoint(char *name)
40954096
*/
40964097
if (name)
40974098
s->name = MemoryContextStrdup(TopTransactionContext, name);
4099+
s->savepointContext = TM->CreateSavepointContext();
40984100
break;
40994101

41004102
/* These cases are invalid. */
@@ -4227,6 +4229,7 @@ ReleaseSavepoint(List *options)
42274229
{
42284230
Assert(xact->blockState == TBLOCK_SUBINPROGRESS);
42294231
xact->blockState = TBLOCK_SUBRELEASE;
4232+
TM->ReleaseSavepointContext(xact->savepointContext);
42304233
if (xact == target)
42314234
break;
42324235
xact = xact->parent;
@@ -4346,9 +4349,11 @@ RollbackToSavepoint(List *options)
43464349
else
43474350
elog(FATAL, "RollbackToSavepoint: unexpected state %s",
43484351
BlockStateAsString(xact->blockState));
4352+
TM->ReleaseSavepointContext(xact->savepointContext);
43494353
xact = xact->parent;
43504354
Assert(PointerIsValid(xact));
43514355
}
4356+
TM->RestoreSavepointContext(xact->savepointContext);
43524357

43534358
/* And mark the target as "restart pending" */
43544359
if (xact->blockState == TBLOCK_SUBINPROGRESS)

src/backend/access/transam/xtm.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,27 @@ PgDeserializeTransactionState(void* ctx)
5252
{
5353
}
5454

55-
void PgInitializeSequence(int64* init, int64* step)
55+
void
56+
PgInitializeSequence(int64* init, int64* step)
5657
{
5758
*init = 1;
5859
*step = 1;
5960
}
6061

6162

63+
void* PgCreateSavepointContext(void)
64+
{
65+
return NULL;
66+
}
67+
68+
void PgRestoreSavepointContext(void* ctx)
69+
{
70+
}
71+
72+
void PgReleaseSavepointContext(void* ctx)
73+
{
74+
}
75+
6276
TransactionManager PgTM = {
6377
PgTransactionIdGetStatus,
6478
PgTransactionIdSetTreeStatus,
@@ -73,7 +87,10 @@ TransactionManager PgTM = {
7387
PgGetTransactionStateSize,
7488
PgSerializeTransactionState,
7589
PgDeserializeTransactionState,
76-
PgInitializeSequence
90+
PgInitializeSequence,
91+
PgCreateSavepointContext,
92+
PgRestoreSavepointContext,
93+
PgReleaseSavepointContext
7794
};
7895

7996
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)