mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 09:41:17 +02:00
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
This commit is contained in:
parent
4d278b785e
commit
20d98ab6e4
@ -6331,6 +6331,10 @@ StartupXLOG(void)
|
|||||||
/* No need to hold ControlFileLock yet, we aren't up far enough */
|
/* No need to hold ControlFileLock yet, we aren't up far enough */
|
||||||
UpdateControlFile();
|
UpdateControlFile();
|
||||||
|
|
||||||
|
/* initialize shared-memory copy of latest checkpoint XID/epoch */
|
||||||
|
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
|
||||||
|
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
|
||||||
|
|
||||||
/* initialize our local copy of minRecoveryPoint */
|
/* initialize our local copy of minRecoveryPoint */
|
||||||
minRecoveryPoint = ControlFile->minRecoveryPoint;
|
minRecoveryPoint = ControlFile->minRecoveryPoint;
|
||||||
|
|
||||||
@ -6875,10 +6879,6 @@ StartupXLOG(void)
|
|||||||
/* start the archive_timeout timer running */
|
/* start the archive_timeout timer running */
|
||||||
XLogCtl->Write.lastSegSwitchTime = (pg_time_t) time(NULL);
|
XLogCtl->Write.lastSegSwitchTime = (pg_time_t) time(NULL);
|
||||||
|
|
||||||
/* initialize shared-memory copy of latest checkpoint XID/epoch */
|
|
||||||
XLogCtl->ckptXidEpoch = ControlFile->checkPointCopy.nextXidEpoch;
|
|
||||||
XLogCtl->ckptXid = ControlFile->checkPointCopy.nextXid;
|
|
||||||
|
|
||||||
/* also initialize latestCompletedXid, to nextXid - 1 */
|
/* also initialize latestCompletedXid, to nextXid - 1 */
|
||||||
ShmemVariableCache->latestCompletedXid = ShmemVariableCache->nextXid;
|
ShmemVariableCache->latestCompletedXid = ShmemVariableCache->nextXid;
|
||||||
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
|
TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
|
||||||
@ -8461,6 +8461,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
|
|||||||
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
|
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
|
||||||
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
|
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
|
||||||
|
|
||||||
|
/* Update shared-memory copy of checkpoint XID/epoch */
|
||||||
|
{
|
||||||
|
/* use volatile pointer to prevent code rearrangement */
|
||||||
|
volatile XLogCtlData *xlogctl = XLogCtl;
|
||||||
|
|
||||||
|
SpinLockAcquire(&xlogctl->info_lck);
|
||||||
|
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
|
||||||
|
xlogctl->ckptXid = checkPoint.nextXid;
|
||||||
|
SpinLockRelease(&xlogctl->info_lck);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TLI may change in a shutdown checkpoint, but it shouldn't decrease
|
* TLI may change in a shutdown checkpoint, but it shouldn't decrease
|
||||||
*/
|
*/
|
||||||
@ -8501,6 +8512,17 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
|
|||||||
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
|
ControlFile->checkPointCopy.nextXidEpoch = checkPoint.nextXidEpoch;
|
||||||
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
|
ControlFile->checkPointCopy.nextXid = checkPoint.nextXid;
|
||||||
|
|
||||||
|
/* Update shared-memory copy of checkpoint XID/epoch */
|
||||||
|
{
|
||||||
|
/* use volatile pointer to prevent code rearrangement */
|
||||||
|
volatile XLogCtlData *xlogctl = XLogCtl;
|
||||||
|
|
||||||
|
SpinLockAcquire(&xlogctl->info_lck);
|
||||||
|
xlogctl->ckptXidEpoch = checkPoint.nextXidEpoch;
|
||||||
|
xlogctl->ckptXid = checkPoint.nextXid;
|
||||||
|
SpinLockRelease(&xlogctl->info_lck);
|
||||||
|
}
|
||||||
|
|
||||||
/* TLI should not change in an on-line checkpoint */
|
/* TLI should not change in an on-line checkpoint */
|
||||||
if (checkPoint.ThisTimeLineID != ThisTimeLineID)
|
if (checkPoint.ThisTimeLineID != ThisTimeLineID)
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
|
Loading…
Reference in New Issue
Block a user