Remove emode argument from XLogFileRead/XLogFileReadAnyTLI

Started by Yugo Nagataover 1 year ago4 messages
#1Yugo Nagata
nagata@sraoss.co.jp
1 attachment(s)

Hi,

Since 1bb2558046c, XLogFileRead() doesn't use the emode argument.
Also, since abf5c5c9a4f, XLogFileReadAnyTLI() is called just once
and emode is always DEBUG2. So, I think we can remove the emode
argument from these functions. I've atached the patch.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

Remove_emode_from_XLogFileRead.patchtext/x-diff; name=Remove_emode_from_XLogFileRead.patchDownload
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 178491f6f5..b126533273 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -432,7 +432,7 @@ static XLogRecord *ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher,
 static bool rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN);
 static int	XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
 						 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 void SetPromoteIsTriggered(void);
@@ -3780,7 +3780,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 				 * Try to restore the file from archive, or read an existing
 				 * file from pg_wal.
 				 */
-				readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2,
+				readFile = XLogFileReadAnyTLI(readSegNo,
 											  currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY :
 											  currentSource);
 				if (readFile >= 0)
@@ -4283,7 +4283,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
  * This version searches for the segment with any TLI listed in expectedTLEs.
  */
 static int
-XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
+XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source)
 {
 	char		path[MAXPGPATH];
 	ListCell   *cell;
@@ -4347,7 +4347,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
 
 		if (source == XLOG_FROM_ANY || source == XLOG_FROM_ARCHIVE)
 		{
-			fd = XLogFileRead(segno, emode, tli,
+			fd = XLogFileRead(segno, DEBUG2, tli,
 							  XLOG_FROM_ARCHIVE, true);
 			if (fd != -1)
 			{
@@ -4360,7 +4360,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
 
 		if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_WAL)
 		{
-			fd = XLogFileRead(segno, emode, tli,
+			fd = XLogFileRead(segno, DEBUG2, tli,
 							  XLOG_FROM_PG_WAL, true);
 			if (fd != -1)
 			{
@@ -4374,7 +4374,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
 	/* Couldn't find it.  For simplicity, complain about front timeline */
 	XLogFilePath(path, recoveryTargetTLI, segno, wal_segment_size);
 	errno = ENOENT;
-	ereport(emode,
+	ereport(DEBUG2,
 			(errcode_for_file_access(),
 			 errmsg("could not open file \"%s\": %m", path)));
 	return -1;
#2Michael Paquier
michael@paquier.xyz
In reply to: Yugo Nagata (#1)
Re: Remove emode argument from XLogFileRead/XLogFileReadAnyTLI

On Fri, Sep 06, 2024 at 08:10:43PM +0900, Yugo Nagata wrote:

Since 1bb2558046c, XLogFileRead() doesn't use the emode argument.
Also, since abf5c5c9a4f, XLogFileReadAnyTLI() is called just once
and emode is always DEBUG2. So, I think we can remove the emode
argument from these functions. I've atached the patch.

It's true that the last relevant caller of XLogFileReadAnyTLI() that
required an emode is abf5c5c9a4f1, as you say, that's also what I am
tracking down. Any objections to that?
--
Michael

#3Yugo NAGATA
nagata@sraoss.co.jp
In reply to: Michael Paquier (#2)
1 attachment(s)
Re: Remove emode argument from XLogFileRead/XLogFileReadAnyTLI

On Mon, 9 Sep 2024 12:16:01 +0900
Michael Paquier <michael@paquier.xyz> wrote:

On Fri, Sep 06, 2024 at 08:10:43PM +0900, Yugo Nagata wrote:

Since 1bb2558046c, XLogFileRead() doesn't use the emode argument.
Also, since abf5c5c9a4f, XLogFileReadAnyTLI() is called just once
and emode is always DEBUG2. So, I think we can remove the emode
argument from these functions. I've atached the patch.

It's true that the last relevant caller of XLogFileReadAnyTLI() that
required an emode is abf5c5c9a4f1, as you say, that's also what I am
tracking down. Any objections to that?

Thank you for looking into this.

I mean to remove emode from XLogFileRead, too, but this fix is accidentally
missed in the previous patch. I attached the updated patch.

Regards,
Yugo Nagata

--
Yugo NAGATA <nagata@sraoss.co.jp>

Attachments:

v2_Remove_emode_from_XLogFileRead.patchtext/x-diff; name=v2_Remove_emode_from_XLogFileRead.patchDownload
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 178491f6f5..320b14add1 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -430,9 +430,9 @@ static int	emode_for_corrupt_record(int emode, XLogRecPtr RecPtr);
 static XLogRecord *ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher,
 										XLogRecPtr RecPtr, TimeLineID replayTLI);
 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);
-static int	XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source);
+static int	XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source);
 
 static bool CheckForStandbyTrigger(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
 				 * file from pg_wal.
 				 */
-				readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2,
+				readFile = XLogFileReadAnyTLI(readSegNo,
 											  currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY :
 											  currentSource);
 				if (readFile >= 0)
@@ -3929,8 +3929,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 						{
 							if (!expectedTLEs)
 								expectedTLEs = readTimeLineHistory(recoveryTargetTLI);
-							readFile = XLogFileRead(readSegNo, PANIC,
-													receiveTLI,
+							readFile = XLogFileRead(readSegNo, receiveTLI,
 													XLOG_FROM_STREAM, false);
 							Assert(readFile >= 0);
 						}
@@ -4201,7 +4200,7 @@ rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)
  * Otherwise, it's assumed to be already available in pg_wal.
  */
 static int
-XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
+XLogFileRead(XLogSegNo segno, TimeLineID tli,
 			 XLogSource source, bool notfoundOk)
 {
 	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.
  */
 static int
-XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
+XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source)
 {
 	char		path[MAXPGPATH];
 	ListCell   *cell;
@@ -4347,8 +4346,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
 
 		if (source == XLOG_FROM_ANY || source == XLOG_FROM_ARCHIVE)
 		{
-			fd = XLogFileRead(segno, emode, tli,
-							  XLOG_FROM_ARCHIVE, true);
+			fd = XLogFileRead(segno, tli, XLOG_FROM_ARCHIVE, true);
 			if (fd != -1)
 			{
 				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)
 		{
-			fd = XLogFileRead(segno, emode, tli,
-							  XLOG_FROM_PG_WAL, true);
+			fd = XLogFileRead(segno, tli, XLOG_FROM_PG_WAL, true);
 			if (fd != -1)
 			{
 				if (!expectedTLEs)
@@ -4374,7 +4371,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
 	/* Couldn't find it.  For simplicity, complain about front timeline */
 	XLogFilePath(path, recoveryTargetTLI, segno, wal_segment_size);
 	errno = ENOENT;
-	ereport(emode,
+	ereport(DEBUG2,
 			(errcode_for_file_access(),
 			 errmsg("could not open file \"%s\": %m", path)));
 	return -1;
#4Michael Paquier
michael@paquier.xyz
In reply to: Yugo NAGATA (#3)
Re: Remove emode argument from XLogFileRead/XLogFileReadAnyTLI

On Mon, Sep 09, 2024 at 05:45:13PM +0900, Yugo NAGATA wrote:

I mean to remove emode from XLogFileRead, too, but this fix is accidentally
missed in the previous patch. I attached the updated patch.

This is neat because we don't need to guess how XLogFileRead() should
fail on PANIC, allow things with a DEBUG2 or something else, and
XLogFileReadAnyTLI()'s sole caller used DEBUG2. Applied.
--
Michael