/*
* Shared copy of ThisTimeLineID. Does not change after end-of-recovery.
- * If we created a new timeline when the system was started up,
- * PrevTimeLineID is the old timeline's ID that we forked off from.
- * Otherwise it's equal to ThisTimeLineID.
+ *
+ * During recovery, ThisTimeLineID and PrevTimeLineID both hold the
+ * timeline of the last record we replayed; they will always be equal.
+ *
+ * At the end of recovery, if we create a new time line, ThisTimeLineID
+ * will be set to the newly-created timeline, and PrevTimeLineID will be
+ * the timeline from which it branched off. If we do not create a new
+ * timeline, ThisTimeLineID will be equal to PrevTimeLineID, and both
+ * will be equal either to the timeline of the last WAL record we replayed,
+ * or the timeline in the checkpoint from which we started up.
+ *
+ * At any point when it's possible to insert new WAL, ThisTimeLineID is
+ * always the timeline that should be used to do that.
*/
TimeLineID ThisTimeLineID;
TimeLineID PrevTimeLineID;
checkPointLoc,
EndOfLog;
TimeLineID EndOfLogTLI;
- TimeLineID PrevTimeLineID;
XLogRecord *record;
TransactionId oldestActiveXID;
bool backupEndRequired = false;
/*
* We must replay WAL entries using the same TimeLineID they were created
* under, so temporarily adopt the TLI indicated by the checkpoint (see
- * also xlog_redo()).
+ * also xlog_redo()). Update shared memory, too.
*/
ThisTimeLineID = checkPoint.ThisTimeLineID;
+ XLogCtl->ThisTimeLineID = ThisTimeLineID;
+ XLogCtl->PrevTimeLineID = ThisTimeLineID;
/*
* Copy any missing timeline history files between 'now' and the recovery
/* Following WAL records should be run with new TLI */
ThisTimeLineID = newTLI;
+ XLogCtl->ThisTimeLineID = ThisTimeLineID;
+ XLogCtl->PrevTimeLineID = ThisTimeLineID;
switchedTLI = true;
}
}
*
* In a normal crash recovery, we can just extend the timeline we were in.
*/
- PrevTimeLineID = ThisTimeLineID;
if (ArchiveRecoveryRequested)
{
char *reason;
Assert(InArchiveRecovery);
ThisTimeLineID = findNewestTimeLine(recoveryTargetTLI) + 1;
+ XLogCtl->ThisTimeLineID = ThisTimeLineID;
ereport(LOG,
(errmsg("selected new timeline ID: %u", ThisTimeLineID)));
unlink(recoveryPath); /* ignore any error */
}
- /* Save the selected TimeLineID in shared memory, too */
- XLogCtl->ThisTimeLineID = ThisTimeLineID;
- XLogCtl->PrevTimeLineID = PrevTimeLineID;
-
/*
* Actually, if WAL ended in an incomplete record, skip the parts that
* made it through and start writing after the portion that persisted.