Skip to content

Commit 043ce02

Browse files
committed
[PGPRO-4074] missing_ok for FinishPreparedTransaction.
tags: multimaster (cherry picked from commit 9307fdc35017d846face8fcbd2210a15eaa965cb)
1 parent 008afc4 commit 043ce02

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/backend/access/transam/twophase.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ MarkAsPrepared(GlobalTransaction gxact, bool lock_held)
555555
* Locate the prepared transaction and mark it busy for COMMIT or PREPARE.
556556
*/
557557
static GlobalTransaction
558-
LockGXact(const char *gid, Oid user)
558+
LockGXact(const char *gid, Oid user, bool missing_ok)
559559
{
560560
int i;
561561

@@ -615,7 +615,8 @@ LockGXact(const char *gid, Oid user)
615615

616616
LWLockRelease(TwoPhaseStateLock);
617617

618-
ereport(ERROR,
618+
if (!missing_ok)
619+
ereport(ERROR,
619620
(errcode(ERRCODE_UNDEFINED_OBJECT),
620621
errmsg("prepared transaction with identifier \"%s\" does not exist",
621622
gid)));
@@ -1400,7 +1401,7 @@ StandbyTransactionIdIsPrepared(TransactionId xid)
14001401
* FinishPreparedTransaction: execute COMMIT PREPARED or ROLLBACK PREPARED
14011402
*/
14021403
void
1403-
FinishPreparedTransaction(const char *gid, bool isCommit)
1404+
FinishPreparedTransaction(const char *gid, bool isCommit, bool missing_ok)
14041405
{
14051406
GlobalTransaction gxact;
14061407
PGPROC *proc;
@@ -1420,8 +1421,16 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
14201421
/*
14211422
* Validate the GID, and lock the GXACT to ensure that two backends do not
14221423
* try to commit the same GID at once.
1424+
*
1425+
* missing_ok is multimaster support
14231426
*/
1424-
gxact = LockGXact(gid, GetUserId());
1427+
gxact = LockGXact(gid, GetUserId(), missing_ok);
1428+
if (gxact == NULL)
1429+
{
1430+
Assert(missing_ok);
1431+
return;
1432+
}
1433+
14251434
proc = &ProcGlobal->allProcs[gxact->pgprocno];
14261435
pgxact = &ProcGlobal->allPgXact[gxact->pgprocno];
14271436
xid = pgxact->xid;

src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,12 @@ standard_ProcessUtility(PlannedStmt *pstmt,
635635

636636
case TRANS_STMT_COMMIT_PREPARED:
637637
PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
638-
FinishPreparedTransaction(stmt->gid, true);
638+
FinishPreparedTransaction(stmt->gid, true, false);
639639
break;
640640

641641
case TRANS_STMT_ROLLBACK_PREPARED:
642642
PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
643-
FinishPreparedTransaction(stmt->gid, false);
643+
FinishPreparedTransaction(stmt->gid, false, false);
644644
break;
645645

646646
case TRANS_STMT_ROLLBACK:

src/include/access/twophase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ extern void RecoverPreparedTransactions(void);
5252

5353
extern void CheckPointTwoPhase(XLogRecPtr redo_horizon);
5454

55-
extern void FinishPreparedTransaction(const char *gid, bool isCommit);
55+
extern void FinishPreparedTransaction(const char *gid, bool isCommit,
56+
bool missing_ok);
5657

5758
extern void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn,
5859
XLogRecPtr end_lsn, RepOriginId origin_id);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy