Remove emode argument from XLogFileRead() and XLogFileReadAnyTLI()

This change makes the code slightly easier to reason about, because
there is actually no need to know if a specific caller of one of these
routines should fail hard on a PANIC, or just let it go through with a
DEBUG2.

The only caller of XLogFileReadAnyTLI() used DEBUG2, and XLogFileRead()
has never used its emode.  This can be simplified since 1bb2558046
that has introduced XLogFileReadAnyTLI(), splitting both.

Author: Yugo Nagata
Discussion: https://postgr.es/m/20240906201043.a640f3b44e755d4db2b6943e@sraoss.co.jp
This commit is contained in:
Michael Paquier 2024-09-10 08:44:31 +09:00
parent bb77752342
commit fba49d5293
1 changed files with 9 additions and 12 deletions

View File

@ -430,9 +430,9 @@ static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr);
static XLogRecord *ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher, static XLogRecord *ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher,
XLogRecPtr RecPtr, TimeLineID replayTLI); XLogRecPtr RecPtr, TimeLineID replayTLI);
static bool rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN); static bool rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN);
static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, static int XLogFileRead(XLogSegNo segno, TimeLineID tli,
XLogSource source, bool notfoundOk); XLogSource source, bool notfoundOk);
static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source); static int XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source);
static bool CheckForStandbyTrigger(void); static bool CheckForStandbyTrigger(void);
static void SetPromoteIsTriggered(void); static void SetPromoteIsTriggered(void);
@ -3780,7 +3780,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
* Try to restore the file from archive, or read an existing * Try to restore the file from archive, or read an existing
* file from pg_wal. * file from pg_wal.
*/ */
readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2, readFile = XLogFileReadAnyTLI(readSegNo,
currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY : currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY :
currentSource); currentSource);
if (readFile >= 0) if (readFile >= 0)
@ -3929,8 +3929,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
{ {
if (!expectedTLEs) if (!expectedTLEs)
expectedTLEs = readTimeLineHistory(recoveryTargetTLI); expectedTLEs = readTimeLineHistory(recoveryTargetTLI);
readFile = XLogFileRead(readSegNo, PANIC, readFile = XLogFileRead(readSegNo, receiveTLI,
receiveTLI,
XLOG_FROM_STREAM, false); XLOG_FROM_STREAM, false);
Assert(readFile >= 0); Assert(readFile >= 0);
} }
@ -4201,7 +4200,7 @@ rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)
* Otherwise, it's assumed to be already available in pg_wal. * Otherwise, it's assumed to be already available in pg_wal.
*/ */
static int static int
XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, XLogFileRead(XLogSegNo segno, TimeLineID tli,
XLogSource source, bool notfoundOk) XLogSource source, bool notfoundOk)
{ {
char xlogfname[MAXFNAMELEN]; char xlogfname[MAXFNAMELEN];
@ -4283,7 +4282,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
* This version searches for the segment with any TLI listed in expectedTLEs. * This version searches for the segment with any TLI listed in expectedTLEs.
*/ */
static int static int
XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source) XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source)
{ {
char path[MAXPGPATH]; char path[MAXPGPATH];
ListCell *cell; ListCell *cell;
@ -4347,8 +4346,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
if (source == XLOG_FROM_ANY || source == XLOG_FROM_ARCHIVE) if (source == XLOG_FROM_ANY || source == XLOG_FROM_ARCHIVE)
{ {
fd = XLogFileRead(segno, emode, tli, fd = XLogFileRead(segno, tli, XLOG_FROM_ARCHIVE, true);
XLOG_FROM_ARCHIVE, true);
if (fd != -1) if (fd != -1)
{ {
elog(DEBUG1, "got WAL segment from archive"); elog(DEBUG1, "got WAL segment from archive");
@ -4360,8 +4358,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_WAL) if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_WAL)
{ {
fd = XLogFileRead(segno, emode, tli, fd = XLogFileRead(segno, tli, XLOG_FROM_PG_WAL, true);
XLOG_FROM_PG_WAL, true);
if (fd != -1) if (fd != -1)
{ {
if (!expectedTLEs) if (!expectedTLEs)
@ -4374,7 +4371,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
/* Couldn't find it. For simplicity, complain about front timeline */ /* Couldn't find it. For simplicity, complain about front timeline */
XLogFilePath(path, recoveryTargetTLI, segno, wal_segment_size); XLogFilePath(path, recoveryTargetTLI, segno, wal_segment_size);
errno = ENOENT; errno = ENOENT;
ereport(emode, ereport(DEBUG2,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", path))); errmsg("could not open file \"%s\": %m", path)));
return -1; return -1;