aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/access/transam/twophase.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index e98286d768b..23dd0c6ef6e 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1505,6 +1505,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
GlobalTransaction gxact;
PGPROC *proc;
TransactionId xid;
+ bool ondisk;
char *buf;
char *bufptr;
TwoPhaseFileHeader *hdr;
@@ -1657,6 +1658,12 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
PredicateLockTwoPhaseFinish(xid, isCommit);
+ /*
+ * Read this value while holding the two-phase lock, as the on-disk 2PC
+ * file is physically removed after the lock is released.
+ */
+ ondisk = gxact->ondisk;
+
/* Clear shared memory state */
RemoveGXact(gxact);
@@ -1672,7 +1679,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
/*
* And now we can clean up any files we may have left.
*/
- if (gxact->ondisk)
+ if (ondisk)
RemoveTwoPhaseFile(xid, true);
MyLockedGxact = NULL;