10000 Correct epoch of txid_current() when executed on a Hot Standby server. · jandas/postgres@efff1cc · GitHub
[go: up one dir, main page]

Skip to content

Commit efff1cc

Browse files
Correct epoch of txid_current() when executed on a Hot Standby server.
Initialise ckptXidEpoch from starting checkpoint and maintain the correct value as we roll forwards. This allows GetNextXidAndEpoch() to return the correct epoch when executed during recovery. Backpatch to 9.0 when the problem is first observable by a user. Bug report from Daniel Farina
1 parent 70e94d2 commit efff1cc

File tree

1 file changed

+26
-4
lines changed
  • src/backend/access/transam

1 file changed

+26
-4
lines changed

src/backend/access/transam/xlog.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6022,6 +6022,10 @@ StartupXLOG(void)
60226022
/* No need to hold ControlFileLock yet, we aren't up far enough */
60236023
UpdateControlFile();
60246024

6025+
/* initialize shared-memory copy of latest checkpoint XID/epoch */
6026+
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
6027+
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
6028+
60256029
/* initialize our local copy of minRecoveryPoint */
60266030
minRecoveryPoint = ControlFile->minRecoveryPoint;
60276031

@@ -6529,10 +6533,6 @@ StartupXLOG(void)
65296533
/* start the archive_timeout timer running */
65306534
XLogCtl->Write.lastSegSwitchTime = (pg_time_t) time(NULL);
65316535

6532-
/* initialize shared-memory copy of latest checkpoint XID/epoch */
6533-
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
6534-
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
6535-
65366536
/* also initialize latestCompletedXid, to nextXid - 1 */
65376537
ShmemVariableCache->latestCompletedXid = ShmemVariableCache->nextXid;
65386538
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
@@ -8013,6 +8013,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
80138013
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
80148014
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
80158015

8016+
/* Update shared-memory copy of checkpoint XID/epoch */
8017+
{
8018+
/* use volatile pointer to prevent code rearrangement */
8019+
volatile XLogCtlData *xlogctl = XLogCtl;
8020+
8021+
SpinLockAcquire(&xlogctl->info_lck);
8022+
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
8023+
xlogctl->ckptXid = checkPoint.nextXid;
8024+
SpinLockRelease(&xlogctl->info_lck);
8025+
}
8026+
80168027
/*
80178028
* TLI may change in a shutdown checkpoint, but it shouldn't decrease
80188029
*/
@@ -8053,6 +8064,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
80538064
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
80548065
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
80558066

8067+
/* Update shared-memory copy of checkpoint XID/epoch */
8068+
{
8069+
/* use volatile pointer to prevent code rearrangement */
8070+
volatile XLogCtlData *xlogctl = XLogCtl;
8071+
8072+
SpinLockAcquire(&xlogctl->info_lck);
8073+
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
8074+
xlogctl->ckptXid = checkPoint.nextXid;
8075+
SpinLockRelease(&xlogctl->info_lck);
8076+
}
8077+
80568078
/* TLI should not change in an on-line checkpoint */
80578079
if (checkPoint.ThisTimeLineID != ThisTimeLineID)
80588080
ereport(PANIC,

0 commit comments

Comments
 (0)
0