diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 6350820a42ac56cd7515bdbf8dcc9cb48ebe50f1..a07c049592f4e340bbcbfd290d3a80544967d619 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1324,8 +1324,6 @@ EndPrepare(GlobalTransaction gxact) /* Add the prepared record to our global list */ add_recover_post_checkpoint_prepared_transactions_map_entry(xid, &gxact->prepare_begin_lsn, "EndPrepare"); - MyProc->inCommit = true; - XLogFlush(gxact->prepare_lsn); /* diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index bbd2736a7f31ec56ee5e378314887484fd3c6c3a..d9679b2182717d493e8c10b56c0b83ffd042c014 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -1038,15 +1038,14 @@ AtSubStart_ResourceOwner(void) * * Returns latest XID among xact and its children, or InvalidTransactionId * if the xact has no XID. (We compute that here just because it's easier.) - * - * This is exported only to support an ugly hack in VACUUM FULL. */ -TransactionId +static TransactionId RecordTransactionCommit(void) { TransactionId xid; bool markXidCommitted; TransactionId latestXid = InvalidTransactionId; + bool save_inCommit; MIRRORED_LOCK_DECLARE; int32 persistentCommitSerializeLen; @@ -1164,6 +1163,7 @@ RecordTransactionCommit(void) * bit fuzzy, but it doesn't matter. */ START_CRIT_SECTION(); + save_inCommit = MyProc->inCommit; MyProc->inCommit = true; MIRRORED_LOCK; @@ -1370,7 +1370,7 @@ RecordTransactionCommit(void) */ if (markXidCommitted) { - MyProc->inCommit = false; + MyProc->inCommit = save_inCommit; END_CRIT_SECTION(); MIRRORED_UNLOCK; @@ -3428,6 +3428,15 @@ CommitTransaction(void) * and FileRepResyncManager_InResyncTransition() */ MIRRORED_LOCK; + /* + * Need to ensure the recording of the commit record and the + * persistent post-commit work will be done either before or after a + * checkpoint. The commit xlog record carries the information for + * objects which serves us for crash-recovery till post-commit + * persistent object work is done, hence cannot allow checkpoint in + * between. + */ + MyProc->inCommit = true; } /* Prevent cancel/die interrupt while cleaning up */ @@ -3546,6 +3555,7 @@ CommitTransaction(void) if (willHaveObjectsFromSmgr) { MIRRORED_UNLOCK; + MyProc->inCommit = false; } AtEOXact_MultiXact(); diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 3e2104d4d52000a2bae1c019465533c818ad3424..17db5f419a2b858f2483e3aab6fd20e2c48bda6f 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -247,7 +247,6 @@ extern void UnregisterXactCallbackOnce(XactCallback callback, void *arg); extern void RegisterSubXactCallback(SubXactCallback callback, void *arg); extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg); -extern TransactionId RecordTransactionCommit(void); extern void RecordDistributedForgetCommitted(struct TMGXACT_LOG *gxact_log); extern bool RecordCrashTransactionAbortRecord( TransactionId xid,