summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas2021-11-01 14:56:18 +0000
committerRobert Haas2021-11-01 16:45:31 +0000
commitf905cfd9d2ee9962038ed00435eef47b0ced144c (patch)
treef5ecba6d47d2c2f13b28d7b10b1b9dd2bbb934b8
parente88517e6f5993e340fbfb69aa63081640491b20d (diff)
xlog.c: Invent openLogTLI.
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.
-rw-r--r--src/backend/access/transam/xlog.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 16f90769c2..95b64e6093 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -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,