Change ThisTimeLineID to be 'static' rather than 'extern'.
authorRobert Haas <[email protected]>
Fri, 29 Oct 2021 20:59:22 +0000 (16:59 -0400)
committerRobert Haas <[email protected]>
Fri, 29 Oct 2021 21:05:22 +0000 (17:05 -0400)
This means code outside xlog.c can no longer access it. Previous
commits have removed most cases whre that was needed, and this
commit cleans up the last few. In xlogfuncs.c, there are a couple
of places that use ThisTimeLineID to obtain the current timeline;
since the code can't run in recovery, use GetWALInsertionTimeLine()
instead. And, in xlogarchive.c, XLogArchiveNotifySeg() needs to
know the relevant timeline, so have the caller pass it as an
additional argument.

src/backend/access/transam/xlog.c
src/backend/access/transam/xlogarchive.c
src/backend/access/transam/xlogfuncs.c
src/include/access/xlog.h
src/include/access/xlogarchive.h

index 91ea1139d817228c52ecb5dd3cffa784b212d061..801175c177a3d98410e8b4cadfcd3495c84f320e 100644 (file)
@@ -192,7 +192,7 @@ CheckpointStatsData CheckpointStats;
  * ThisTimeLineID will be same in all backends --- it identifies current
  * WAL timeline for the database system.
  */
-TimeLineID     ThisTimeLineID = 0;
+static TimeLineID      ThisTimeLineID = 0;
 
 static XLogRecPtr LastRec;
 
@@ -2631,7 +2631,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
                                LogwrtResult.Flush = LogwrtResult.Write;        /* end of page */
 
                                if (XLogArchivingActive())
-                                       XLogArchiveNotifySeg(openLogSegNo);
+                                       XLogArchiveNotifySeg(openLogSegNo, ThisTimeLineID);
 
                                XLogCtl->lastSegSwitchTime = (pg_time_t) time(NULL);
                                XLogCtl->lastSegSwitchLSN = LogwrtResult.Flush;
index 26b023e754b00309ec39285356c858d375e00433..7d56dad0def113dd687ae0b7ffa721e84a087e96 100644 (file)
@@ -498,11 +498,13 @@ XLogArchiveNotify(const char *xlog)
  * Convenience routine to notify using segment number representation of filename
  */
 void
-XLogArchiveNotifySeg(XLogSegNo segno)
+XLogArchiveNotifySeg(XLogSegNo segno, TimeLineID tli)
 {
        char            xlog[MAXFNAMELEN];
 
-       XLogFileName(xlog, ThisTimeLineID, segno, wal_segment_size);
+       Assert(tli != 0);
+
+       XLogFileName(xlog, tli, segno, wal_segment_size);
        XLogArchiveNotify(xlog);
 }
 
index 5bebcc50dde3b63f1e0cc663fb1bede56b78f87a..dd9a45c18606d61307705570e624b1fb93f7a274 100644 (file)
@@ -469,7 +469,8 @@ pg_walfile_name_offset(PG_FUNCTION_ARGS)
         * xlogfilename
         */
        XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
-       XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, wal_segment_size);
+       XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
+                                wal_segment_size);
 
        values[0] = CStringGetTextDatum(xlogfilename);
        isnull[0] = false;
@@ -511,7 +512,8 @@ pg_walfile_name(PG_FUNCTION_ARGS)
                                                 "pg_walfile_name()")));
 
        XLByteToPrevSeg(locationpoint, xlogsegno, wal_segment_size);
-       XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno, wal_segment_size);
+       XLogFileName(xlogfilename, GetWALInsertionTimeLine(), xlogsegno,
+                                wal_segment_size);
 
        PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
 }
index 22f1d37fb2ca01df2ee770a16d13c439279b628a..51a672b703f6d698a07fd2277b1c54210823fda5 100644 (file)
@@ -29,8 +29,6 @@
 #define SYNC_METHOD_OPEN_DSYNC 4       /* for O_DSYNC */
 extern int     sync_method;
 
-extern PGDLLIMPORT TimeLineID ThisTimeLineID;  /* current TLI */
-
 /*
  * Recovery target type.
  * Only set during a Point in Time recovery, not when in standby mode.
index 3edd1a976c1b48ba38a9778346e04bd49adbb75e..7dcf1bd2dd2e873451ba0d9c182dd1f76bd6ee8d 100644 (file)
@@ -24,7 +24,7 @@ extern void ExecuteRecoveryCommand(const char *command, const char *commandName,
                                                                   bool failOnSignal);
 extern void KeepFileRestoredFromArchive(const char *path, const char *xlogfname);
 extern void XLogArchiveNotify(const char *xlog);
-extern void XLogArchiveNotifySeg(XLogSegNo segno);
+extern void XLogArchiveNotifySeg(XLogSegNo segno, TimeLineID tli);
 extern void XLogArchiveForceDone(const char *xlog);
 extern bool XLogArchiveCheckDone(const char *xlog);
 extern bool XLogArchiveIsBusy(const char *xlog);