Skip to content

Commit

Permalink
Always SnapshotResetXmin() during ClearTransaction()
Browse files Browse the repository at this point in the history
Avoid corner cases during 2PC with 6bad580
  • Loading branch information
simonat2ndQuadrant committed Apr 6, 2017
1 parent 3217327 commit cd0ceba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/backend/access/transam/xact.c
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ CleanupTransaction(void)
* do abort cleanup processing
*/
AtCleanup_Portals(); /* now safe to release portal memory */
AtEOXact_Snapshot(false, false); /* and release the transaction's snapshots */
AtEOXact_Snapshot(false, true); /* and release the transaction's snapshots */

CurrentResourceOwner = NULL; /* and resource owner */
if (TopTransactionResourceOwner)
Expand Down
15 changes: 7 additions & 8 deletions src/backend/utils/time/snapmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ AtSubAbort_Snapshot(int level)
* Snapshot manager's cleanup function for end of transaction
*/
void
AtEOXact_Snapshot(bool isCommit, bool isPrepare)
AtEOXact_Snapshot(bool isCommit, bool resetXmin)
{
/*
* In transaction-snapshot mode we must release our privately-managed
Expand Down Expand Up @@ -1137,16 +1137,15 @@ AtEOXact_Snapshot(bool isCommit, bool isPrepare)
FirstSnapshotSet = false;

/*
* During normal commit and abort processing, we call
* ProcArrayEndTransaction() or ProcArrayClearTransaction() to
* reset the PgXact->xmin. That call happens prior to the call to
* AtEOXact_Snapshot(), so we need not touch xmin here at all,
* accept when we are preparing a transaction.
* During normal commit processing, we call
* ProcArrayEndTransaction() to reset the PgXact->xmin. That call
* happens prior to the call to AtEOXact_Snapshot(), so we need
* not touch xmin here at all.
*/
if (isPrepare)
if (resetXmin)
SnapshotResetXmin();

Assert(isPrepare || MyPgXact->xmin == 0);
Assert(resetXmin || MyPgXact->xmin == 0);
}


Expand Down
2 changes: 1 addition & 1 deletion src/include/utils/snapmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);

extern void AtSubCommit_Snapshot(int level);
extern void AtSubAbort_Snapshot(int level);
extern void AtEOXact_Snapshot(bool isCommit, bool isPrepare);
extern void AtEOXact_Snapshot(bool isCommit, bool resetXmin);

extern void ImportSnapshot(const char *idstr);
extern bool XactHasExportedSnapshots(void);
Expand Down

0 comments on commit cd0ceba

Please sign in to comment.