xlog.c: Make xlog_redo() not depend on ThisTimeLineID global variable.
authorRobert Haas <[email protected]>
Mon, 1 Nov 2021 16:58:15 +0000 (12:58 -0400)
committerRobert Haas <[email protected]>
Mon, 1 Nov 2021 16:58:15 +0000 (12:58 -0400)
The same value is available in shared memory as XLogCtl->replayEndTLI
so use that instead.

src/backend/access/transam/xlog.c

index 054241403c55b420e3f71e32ddcc9a8a341d9635..b6f30382ebafc474f56ea81d01e932b703cdb85c 100644 (file)
@@ -10349,6 +10349,10 @@ xlog_redo(XLogReaderState *record)
 {
        uint8           info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
        XLogRecPtr      lsn = record->EndRecPtr;
+       TimeLineID      replayTLI;
+
+       /* No other process can change this, so we can read it without a lock. */
+       replayTLI = XLogCtl->replayEndTLI;
 
        /*
         * In XLOG rmgr, backup blocks are only used by XLOG_FPI and
@@ -10462,10 +10466,10 @@ xlog_redo(XLogReaderState *record)
                 * We should've already switched to the new TLI before replaying this
                 * record.
                 */
-               if (checkPoint.ThisTimeLineID != ThisTimeLineID)
+               if (checkPoint.ThisTimeLineID != replayTLI)
                        ereport(PANIC,
                                        (errmsg("unexpected timeline ID %u (should be %u) in checkpoint record",
-                                                       checkPoint.ThisTimeLineID, ThisTimeLineID)));
+                                                       checkPoint.ThisTimeLineID, replayTLI)));
 
                RecoveryRestartPoint(&checkPoint);
        }
@@ -10518,10 +10522,10 @@ xlog_redo(XLogReaderState *record)
                SpinLockRelease(&XLogCtl->info_lck);
 
                /* TLI should not change in an on-line checkpoint */
-               if (checkPoint.ThisTimeLineID != ThisTimeLineID)
+               if (checkPoint.ThisTimeLineID != replayTLI)
                        ereport(PANIC,
                                        (errmsg("unexpected timeline ID %u (should be %u) in checkpoint record",
-                                                       checkPoint.ThisTimeLineID, ThisTimeLineID)));
+                                                       checkPoint.ThisTimeLineID, replayTLI)));
 
                RecoveryRestartPoint(&checkPoint);
        }
@@ -10548,10 +10552,10 @@ xlog_redo(XLogReaderState *record)
                 * We should've already switched to the new TLI before replaying this
                 * record.
                 */
-               if (xlrec.ThisTimeLineID != ThisTimeLineID)
+               if (xlrec.ThisTimeLineID != replayTLI)
                        ereport(PANIC,
                                        (errmsg("unexpected timeline ID %u (should be %u) in checkpoint record",
-                                                       xlrec.ThisTimeLineID, ThisTimeLineID)));
+                                                       xlrec.ThisTimeLineID, replayTLI)));
        }
        else if (info == XLOG_NOOP)
        {
@@ -10621,7 +10625,7 @@ xlog_redo(XLogReaderState *record)
                        if (ControlFile->minRecoveryPoint < lsn)
                        {
                                ControlFile->minRecoveryPoint = lsn;
-                               ControlFile->minRecoveryPointTLI = ThisTimeLineID;
+                               ControlFile->minRecoveryPointTLI = replayTLI;
                        }
                        ControlFile->backupStartPoint = InvalidXLogRecPtr;
                        ControlFile->backupEndRequired = false;
@@ -10662,7 +10666,7 @@ xlog_redo(XLogReaderState *record)
                if (minRecoveryPoint != InvalidXLogRecPtr && minRecoveryPoint < lsn)
                {
                        ControlFile->minRecoveryPoint = lsn;
-                       ControlFile->minRecoveryPointTLI = ThisTimeLineID;
+                       ControlFile->minRecoveryPointTLI = replayTLI;
                }
 
                CommitTsParameterChange(xlrec.track_commit_timestamp,