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

Commit 20d98ab

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 4d278b7 commit 20d98ab

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
@@ -6331,6 +6331,10 @@ StartupXLOG(void)
63316331
/* No need to hold ControlFileLock yet, we aren't up far enough */
63326332
UpdateControlFile();
63336333

6334+
/* initialize shared-memory copy of latest checkpoint XID/epoch */
6335+
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
6336+
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
6337+
63346338
/* initialize our local copy of minRecoveryPoint */
63356339
minRecoveryPoint = ControlFile->minRecoveryPoint;
63366340

@@ -6875,10 +6879,6 @@ StartupXLOG(void)
68756879
/* start the archive_timeout timer running */
68766880
XLogCtl->Write.lastSegSwitchTime = (pg_time_t) time(NULL);
68776881

6878-
/* initialize shared-memory copy of latest checkpoint XID/epoch */
6879-
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
6880-
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
6881-
68826882
/* also initialize latestCompletedXid, to nextXid - 1 */
68836883
ShmemVariableCache->latestCompletedXid = ShmemVariableCache->nextXid;
68846884
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
@@ -8461,6 +8461,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
84618461
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
84628462
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
84638463

8464+
/* Update shared-memory copy of checkpoint XID/epoch */
8465+
{
8466+
/* use volatile pointer to prevent code rearrangement */
8467+
volatile XLogCtlData *xlogctl = XLogCtl;
8468+
8469+
SpinLockAcquire(&xlogctl->info_lck);
8470+
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
8471+
xlogctl->ckptXid = checkPoint.nextXid;
8472+
SpinLockRelease(&xlogctl->info_lck);
8473+
}
8474+
84648475
/*
84658476
* TLI may change in a shutdown checkpoint, but it shouldn't decrease
84668477
*/
@@ -8501,6 +8512,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
85018512
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
85028513
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
85038514

8515+
/* Update shared-memory copy of checkpoint XID/epoch */
8516+
{
8517+
/* use volatile pointer to prevent code rearrangement */
8518+
volatile XLogCtlData *xlogctl = XLogCtl;
8519+
8520+
SpinLockAcquire(&xlogctl->info_lck);
8521+
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
8522+
xlogctl->ckptXid = checkPoint.nextXid;
8523+
SpinLockRelease(&xlogctl->info_lck);
8524+
}
8525+
85048526
/* TLI should not change in an on-line checkpoint */
85058527
if (checkPoint.ThisTimeLineID != ThisTimeLineID)
85068528
ereport(PANIC,

0 commit comments

Comments
 (0)