xlog.c: Invent openLogTLI.
authorRobert Haas <[email protected]>
Mon, 1 Nov 2021 14:56:18 +0000 (10:56 -0400)
committerRobert Haas <[email protected]>
Mon, 1 Nov 2021 16:45:31 +0000 (12:45 -0400)
Currently, XLogFileClose() depends on the TLI corresponding to
openLogSegNo being ThisTimeLineID. Instead, invent a new variable
openLogTLI which is precisely the timeline ID of the xlog file
we're accessing via openLogFile.

src/backend/access/transam/xlog.c

index 16f90769c28da5b555b866f386ad8036d285bfb0..95b64e6093475c2c95c428e374676888bd60f880 100644 (file)
@@ -801,12 +801,15 @@ static const char *const xlogSourceNames[] = {"any", "archive", "pg_wal", "strea
 
 /*
  * openLogFile is -1 or a kernel FD for an open log file segment.
- * openLogSegNo identifies the segment.  These variables are only used to
- * write the XLOG, and so will normally refer to the active segment.
+ * openLogSegNo identifies the segment, and openLogTLI the corresponding TLI.
+ * These variables are only used to write the XLOG, and so will normally refer
+ * to the active segment.
+ *
  * Note: call Reserve/ReleaseExternalFD to track consumption of this FD.
  */
 static int     openLogFile = -1;
 static XLogSegNo openLogSegNo = 0;
+static TimeLineID openLogTLI = 0;
 
 /*
  * These variables are used similarly to the ones above, but for reading
@@ -2511,6 +2514,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
                                XLogFileClose();
                        XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo,
                                                        wal_segment_size);
+                       openLogTLI = tli;
 
                        /* create/use new log file */
                        openLogFile = XLogFileInit(openLogSegNo, tli);
@@ -2522,6 +2526,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
                {
                        XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo,
                                                        wal_segment_size);
+                       openLogTLI = tli;
                        openLogFile = XLogFileOpen(openLogSegNo, tli);
                        ReserveExternalFD();
                }
@@ -2695,6 +2700,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
                        {
                                XLByteToPrevSeg(LogwrtResult.Write, openLogSegNo,
                                                                wal_segment_size);
+                               openLogTLI = tli;
                                openLogFile = XLogFileOpen(openLogSegNo, tli);
                                ReserveExternalFD();
                        }
@@ -3946,7 +3952,7 @@ XLogFileClose(void)
                char            xlogfname[MAXFNAMELEN];
                int                     save_errno = errno;
 
-               XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, wal_segment_size);
+               XLogFileName(xlogfname, openLogTLI, openLogSegNo, wal_segment_size);
                errno = save_errno;
                ereport(PANIC,
                                (errcode_for_file_access(),
@@ -5416,6 +5422,7 @@ BootStrapXLOG(void)
        record->xl_crc = crc;
 
        /* Create first XLOG segment file */
+       openLogTLI = ThisTimeLineID;
        openLogFile = XLogFileInit(1, ThisTimeLineID);
 
        /*
@@ -10863,7 +10870,7 @@ assign_xlog_sync_method(int new_sync_method, void *extra)
                                int                     save_errno;
 
                                save_errno = errno;
-                               XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo,
+                               XLogFileName(xlogfname, openLogTLI, openLogSegNo,
                                                         wal_segment_size);
                                errno = save_errno;
                                ereport(PANIC,