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

Commit 3114cb6

Browse files
committed
Don't advance checkPoint.nextXid near the end of a checkpoint sequence.
This reverts commit c111306 in favor of actually fixing the problem: namely, that we should never have been modifying the checkpoint record's nextXid at this point to begin with. The nextXid should match the state as of the checkpoint's logical WAL position (ie the redo point), not the state as of its physical position. It's especially bogus to advance it in some wal_levels and not others. In any case there is no need for the checkpoint record to carry the same nextXid shown in the XLOG_RUNNING_XACTS record just emitted by LogStandbySnapshot, as any replay operation will already have adopted that value as current. This fixes bug #7710 from Tarvi Pillessaar, and probably also explains bug #6291 from Daniel Farina, in that if a checkpoint were in progress at the instant of XID wraparound, the epoch bump would be lost as reported. (And, of course, these days there's at least a 50-50 chance of a checkpoint being in progress at any given instant.) Diagnosed by me and independently by Andres Freund. Back-patch to all branches supporting hot standby.
1 parent 5c11725 commit 3114cb6

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

src/backend/access/transam/xlog.c

+1-10
Original file line numberDiff line numberDiff line change
@@ -7119,18 +7119,9 @@ CreateCheckPoint(int flags)
71197119
*
71207120
* If we are shutting down, or Startup process is completing crash
71217121
* recovery we don't need to write running xact data.
7122-
*
7123-
* Update checkPoint.nextXid since we may have a later value. If we
7124-
* do update the value, and we have wrapped, increment epoch also.
71257122
*/
71267123
if (!shutdown && XLogStandbyInfoActive())
7127-
{
7128-
TransactionId prevXid = checkPoint.nextXid;
7129-
7130-
LogStandbySnapshot(&checkPoint.nextXid);
7131-
if (checkPoint.nextXid < prevXid)
7132-
checkPoint.nextXidEpoch++;
7133-
}
7124+
LogStandbySnapshot();
71347125

71357126
START_CRIT_SECTION();
71367127

src/backend/storage/ipc/standby.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ standby_redo(XLogRecPtr lsn, XLogRecord *record)
848848
* from a time when they were possible.
849849
*/
850850
void
851-
LogStandbySnapshot(TransactionId *nextXid)
851+
LogStandbySnapshot(void)
852852
{
853853
RunningTransactions running;
854854
xl_standby_lock *locks;
@@ -877,8 +877,6 @@ LogStandbySnapshot(TransactionId *nextXid)
877877
LogCurrentRunningXacts(running);
878878
/* GetRunningTransactionData() acquired XidGenLock, we must release it */
879879
LWLockRelease(XidGenLock);
880-
881-
*nextXid = running->nextXid;
882880
}
883881

884882
/*

src/include/storage/standby.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ typedef RunningTransactionsData *RunningTransactions;
113113
extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid);
114114
extern void LogAccessExclusiveLockPrepare(void);
115115

116-
extern void LogStandbySnapshot(TransactionId *nextXid);
116+
extern void LogStandbySnapshot(void);
117117

118118
#endif /* STANDBY_H */

0 commit comments

Comments
 (0)