From 1b97c1cb3fb7c051884d32287da3dd975b9b251f Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 2 Dec 2025 14:01:31 +0800
Subject: [PATCH v2 06/13] cleanup: avoid local variables shadowed by static
 file-scope ones in xlogrecovery.c

This commit fixes several cases in xlogrecovery.c where local variables
used names that conflicted with static variables defined at file scope.
The local identifiers are renamed so they are no longer shadowed by the
static ones.

Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com
---
 src/backend/access/transam/xlogrecovery.c | 100 +++++++++++-----------
 1 file changed, 50 insertions(+), 50 deletions(-)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 21b8f179ba0..903e2afe5ed 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -1208,7 +1208,7 @@ validateRecoveryParameters(void)
  * Returns true if a backup_label was found (and fills the checkpoint
  * location and TLI into *checkPointLoc and *backupLabelTLI, respectively);
  * returns false if not. If this backup_label came from a streamed backup,
- * *backupEndRequired is set to true. If this backup_label was created during
+ * *backupEndNeeded is set to true. If this backup_label was created during
  * recovery, *backupFromStandby is set to true.
  *
  * Also sets the global variables RedoStartLSN and RedoStartTLI with the LSN
@@ -1216,7 +1216,7 @@ validateRecoveryParameters(void)
  */
 static bool
 read_backup_label(XLogRecPtr *checkPointLoc, TimeLineID *backupLabelTLI,
-				  bool *backupEndRequired, bool *backupFromStandby)
+				  bool *backupEndNeeded, bool *backupFromStandby)
 {
 	char		startxlogfilename[MAXFNAMELEN];
 	TimeLineID	tli_from_walseg,
@@ -1233,7 +1233,7 @@ read_backup_label(XLogRecPtr *checkPointLoc, TimeLineID *backupLabelTLI,
 	/* suppress possible uninitialized-variable warnings */
 	*checkPointLoc = InvalidXLogRecPtr;
 	*backupLabelTLI = 0;
-	*backupEndRequired = false;
+	*backupEndNeeded = false;
 	*backupFromStandby = false;
 
 	/*
@@ -1277,13 +1277,13 @@ read_backup_label(XLogRecPtr *checkPointLoc, TimeLineID *backupLabelTLI,
 	 * other option today being from pg_rewind).  If this was a streamed
 	 * backup then we know that we need to play through until we get to the
 	 * end of the WAL which was generated during the backup (at which point we
-	 * will have reached consistency and backupEndRequired will be reset to be
+	 * will have reached consistency and backupEndNeeded will be reset to be
 	 * false).
 	 */
 	if (fscanf(lfp, "BACKUP METHOD: %19s\n", backuptype) == 1)
 	{
 		if (strcmp(backuptype, "streamed") == 0)
-			*backupEndRequired = true;
+			*backupEndNeeded = true;
 	}
 
 	/*
@@ -1927,14 +1927,14 @@ PerformWalRecovery(void)
  * Subroutine of PerformWalRecovery, to apply one WAL record.
  */
 static void
-ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *replayTLI)
+ApplyWalRecord(XLogReaderState *reader, XLogRecord *record, TimeLineID *replayTLI)
 {
 	ErrorContextCallback errcallback;
 	bool		switchedTLI = false;
 
 	/* Setup error traceback support for ereport() */
 	errcallback.callback = rm_redo_error_callback;
-	errcallback.arg = xlogreader;
+	errcallback.arg = reader;
 	errcallback.previous = error_context_stack;
 	error_context_stack = &errcallback;
 
@@ -1961,7 +1961,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 		{
 			CheckPoint	checkPoint;
 
-			memcpy(&checkPoint, XLogRecGetData(xlogreader), sizeof(CheckPoint));
+			memcpy(&checkPoint, XLogRecGetData(reader), sizeof(CheckPoint));
 			newReplayTLI = checkPoint.ThisTimeLineID;
 			prevReplayTLI = checkPoint.PrevTimeLineID;
 		}
@@ -1969,7 +1969,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 		{
 			xl_end_of_recovery xlrec;
 
-			memcpy(&xlrec, XLogRecGetData(xlogreader), sizeof(xl_end_of_recovery));
+			memcpy(&xlrec, XLogRecGetData(reader), sizeof(xl_end_of_recovery));
 			newReplayTLI = xlrec.ThisTimeLineID;
 			prevReplayTLI = xlrec.PrevTimeLineID;
 		}
@@ -1977,7 +1977,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 		if (newReplayTLI != *replayTLI)
 		{
 			/* Check that it's OK to switch to this TLI */
-			checkTimeLineSwitch(xlogreader->EndRecPtr,
+			checkTimeLineSwitch(reader->EndRecPtr,
 								newReplayTLI, prevReplayTLI, *replayTLI);
 
 			/* Following WAL records should be run with new TLI */
@@ -1991,7 +1991,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 	 * XLogFlush will update minRecoveryPoint correctly.
 	 */
 	SpinLockAcquire(&XLogRecoveryCtl->info_lck);
-	XLogRecoveryCtl->replayEndRecPtr = xlogreader->EndRecPtr;
+	XLogRecoveryCtl->replayEndRecPtr = reader->EndRecPtr;
 	XLogRecoveryCtl->replayEndTLI = *replayTLI;
 	SpinLockRelease(&XLogRecoveryCtl->info_lck);
 
@@ -2007,10 +2007,10 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 	 * directly here, rather than in xlog_redo()
 	 */
 	if (record->xl_rmid == RM_XLOG_ID)
-		xlogrecovery_redo(xlogreader, *replayTLI);
+		xlogrecovery_redo(reader, *replayTLI);
 
 	/* Now apply the WAL record itself */
-	GetRmgr(record->xl_rmid).rm_redo(xlogreader);
+	GetRmgr(record->xl_rmid).rm_redo(reader);
 
 	/*
 	 * After redo, check whether the backup pages associated with the WAL
@@ -2018,7 +2018,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 	 * if consistency check is enabled for this record.
 	 */
 	if ((record->xl_info & XLR_CHECK_CONSISTENCY) != 0)
-		verifyBackupPageConsistency(xlogreader);
+		verifyBackupPageConsistency(reader);
 
 	/* Pop the error context stack */
 	error_context_stack = errcallback.previous;
@@ -2028,8 +2028,8 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 	 * replayed.
 	 */
 	SpinLockAcquire(&XLogRecoveryCtl->info_lck);
-	XLogRecoveryCtl->lastReplayedReadRecPtr = xlogreader->ReadRecPtr;
-	XLogRecoveryCtl->lastReplayedEndRecPtr = xlogreader->EndRecPtr;
+	XLogRecoveryCtl->lastReplayedReadRecPtr = reader->ReadRecPtr;
+	XLogRecoveryCtl->lastReplayedEndRecPtr = reader->EndRecPtr;
 	XLogRecoveryCtl->lastReplayedTLI = *replayTLI;
 	SpinLockRelease(&XLogRecoveryCtl->info_lck);
 
@@ -2079,7 +2079,7 @@ ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *repl
 		 * Before we continue on the new timeline, clean up any (possibly
 		 * bogus) future WAL segments on the old timeline.
 		 */
-		RemoveNonParentXlogFiles(xlogreader->EndRecPtr, *replayTLI);
+		RemoveNonParentXlogFiles(reader->EndRecPtr, *replayTLI);
 
 		/* Reset the prefetcher. */
 		XLogPrefetchReconfigure();
@@ -3152,19 +3152,19 @@ ConfirmRecoveryPaused(void)
  * record is available.
  */
 static XLogRecord *
-ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
+ReadRecord(XLogPrefetcher *prefetcher, int emode,
 		   bool fetching_ckpt, TimeLineID replayTLI)
 {
 	XLogRecord *record;
-	XLogReaderState *xlogreader = XLogPrefetcherGetReader(xlogprefetcher);
-	XLogPageReadPrivate *private = (XLogPageReadPrivate *) xlogreader->private_data;
+	XLogReaderState *reader = XLogPrefetcherGetReader(prefetcher);
+	XLogPageReadPrivate *private = (XLogPageReadPrivate *) reader->private_data;
 
 	Assert(AmStartupProcess() || !IsUnderPostmaster);
 
 	/* Pass through parameters to XLogPageRead */
 	private->fetching_ckpt = fetching_ckpt;
 	private->emode = emode;
-	private->randAccess = !XLogRecPtrIsValid(xlogreader->ReadRecPtr);
+	private->randAccess = !XLogRecPtrIsValid(reader->ReadRecPtr);
 	private->replayTLI = replayTLI;
 
 	/* This is the first attempt to read this page. */
@@ -3174,7 +3174,7 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 	{
 		char	   *errormsg;
 
-		record = XLogPrefetcherReadRecord(xlogprefetcher, &errormsg);
+		record = XLogPrefetcherReadRecord(prefetcher, &errormsg);
 		if (record == NULL)
 		{
 			/*
@@ -3190,10 +3190,10 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 			 * overwrite contrecord in the wrong place, breaking everything.
 			 */
 			if (!ArchiveRecoveryRequested &&
-				XLogRecPtrIsValid(xlogreader->abortedRecPtr))
+				XLogRecPtrIsValid(reader->abortedRecPtr))
 			{
-				abortedRecPtr = xlogreader->abortedRecPtr;
-				missingContrecPtr = xlogreader->missingContrecPtr;
+				abortedRecPtr = reader->abortedRecPtr;
+				missingContrecPtr = reader->missingContrecPtr;
 			}
 
 			if (readFile >= 0)
@@ -3209,29 +3209,29 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 			 * shouldn't loop anymore in that case.
 			 */
 			if (errormsg)
-				ereport(emode_for_corrupt_record(emode, xlogreader->EndRecPtr),
+				ereport(emode_for_corrupt_record(emode, reader->EndRecPtr),
 						(errmsg_internal("%s", errormsg) /* already translated */ ));
 		}
 
 		/*
 		 * Check page TLI is one of the expected values.
 		 */
-		else if (!tliInHistory(xlogreader->latestPageTLI, expectedTLEs))
+		else if (!tliInHistory(reader->latestPageTLI, expectedTLEs))
 		{
 			char		fname[MAXFNAMELEN];
 			XLogSegNo	segno;
 			int32		offset;
 
-			XLByteToSeg(xlogreader->latestPagePtr, segno, wal_segment_size);
-			offset = XLogSegmentOffset(xlogreader->latestPagePtr,
+			XLByteToSeg(reader->latestPagePtr, segno, wal_segment_size);
+			offset = XLogSegmentOffset(reader->latestPagePtr,
 									   wal_segment_size);
-			XLogFileName(fname, xlogreader->seg.ws_tli, segno,
+			XLogFileName(fname, reader->seg.ws_tli, segno,
 						 wal_segment_size);
-			ereport(emode_for_corrupt_record(emode, xlogreader->EndRecPtr),
+			ereport(emode_for_corrupt_record(emode, reader->EndRecPtr),
 					errmsg("unexpected timeline ID %u in WAL segment %s, LSN %X/%08X, offset %u",
-						   xlogreader->latestPageTLI,
+						   reader->latestPageTLI,
 						   fname,
-						   LSN_FORMAT_ARGS(xlogreader->latestPagePtr),
+						   LSN_FORMAT_ARGS(reader->latestPagePtr),
 						   offset));
 			record = NULL;
 		}
@@ -3267,8 +3267,8 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
 				if (StandbyModeRequested)
 					EnableStandbyMode();
 
-				SwitchIntoArchiveRecovery(xlogreader->EndRecPtr, replayTLI);
-				minRecoveryPoint = xlogreader->EndRecPtr;
+				SwitchIntoArchiveRecovery(reader->EndRecPtr, replayTLI);
+				minRecoveryPoint = reader->EndRecPtr;
 				minRecoveryPointTLI = replayTLI;
 
 				CheckRecoveryConsistency();
@@ -3321,11 +3321,11 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
  * sleep and retry.
  */
 static int
-XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
+XLogPageRead(XLogReaderState *reader, XLogRecPtr targetPagePtr, int reqLen,
 			 XLogRecPtr targetRecPtr, char *readBuf)
 {
 	XLogPageReadPrivate *private =
-		(XLogPageReadPrivate *) xlogreader->private_data;
+		(XLogPageReadPrivate *) reader->private_data;
 	int			emode = private->emode;
 	uint32		targetPageOff;
 	XLogSegNo	targetSegNo PG_USED_FOR_ASSERTS_ONLY;
@@ -3372,7 +3372,7 @@ retry:
 		 flushedUpto < targetPagePtr + reqLen))
 	{
 		if (readFile >= 0 &&
-			xlogreader->nonblocking &&
+			reader->nonblocking &&
 			readSource == XLOG_FROM_STREAM &&
 			flushedUpto < targetPagePtr + reqLen)
 			return XLREAD_WOULDBLOCK;
@@ -3382,8 +3382,8 @@ retry:
 											private->fetching_ckpt,
 											targetRecPtr,
 											private->replayTLI,
-											xlogreader->EndRecPtr,
-											xlogreader->nonblocking))
+											reader->EndRecPtr,
+											reader->nonblocking))
 		{
 			case XLREAD_WOULDBLOCK:
 				return XLREAD_WOULDBLOCK;
@@ -3467,7 +3467,7 @@ retry:
 	Assert(targetPageOff == readOff);
 	Assert(reqLen <= readLen);
 
-	xlogreader->seg.ws_tli = curFileTLI;
+	reader->seg.ws_tli = curFileTLI;
 
 	/*
 	 * Check the page header immediately, so that we can retry immediately if
@@ -3503,18 +3503,18 @@ retry:
 	 */
 	if (StandbyMode &&
 		(targetPagePtr % wal_segment_size) == 0 &&
-		!XLogReaderValidatePageHeader(xlogreader, targetPagePtr, readBuf))
+		!XLogReaderValidatePageHeader(reader, targetPagePtr, readBuf))
 	{
 		/*
 		 * Emit this error right now then retry this page immediately. Use
 		 * errmsg_internal() because the message was already translated.
 		 */
-		if (xlogreader->errormsg_buf[0])
-			ereport(emode_for_corrupt_record(emode, xlogreader->EndRecPtr),
-					(errmsg_internal("%s", xlogreader->errormsg_buf)));
+		if (reader->errormsg_buf[0])
+			ereport(emode_for_corrupt_record(emode, reader->EndRecPtr),
+					(errmsg_internal("%s", reader->errormsg_buf)));
 
 		/* reset any error XLogReaderValidatePageHeader() might have set */
-		XLogReaderResetError(xlogreader);
+		XLogReaderResetError(reader);
 		goto next_record_is_invalid;
 	}
 
@@ -3526,7 +3526,7 @@ next_record_is_invalid:
 	 * If we're reading ahead, give up fast.  Retries and error reporting will
 	 * be handled by a later read when recovery catches up to this point.
 	 */
-	if (xlogreader->nonblocking)
+	if (reader->nonblocking)
 		return XLREAD_WOULDBLOCK;
 
 	lastSourceFailed = true;
@@ -4104,7 +4104,7 @@ emode_for_corrupt_record(int emode, XLogRecPtr RecPtr)
  * Subroutine to try to fetch and validate a prior checkpoint record.
  */
 static XLogRecord *
-ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher, XLogRecPtr RecPtr,
+ReadCheckpointRecord(XLogPrefetcher *prefetcher, XLogRecPtr RecPtr,
 					 TimeLineID replayTLI)
 {
 	XLogRecord *record;
@@ -4119,8 +4119,8 @@ ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher, XLogRecPtr RecPtr,
 		return NULL;
 	}
 
-	XLogPrefetcherBeginRead(xlogprefetcher, RecPtr);
-	record = ReadRecord(xlogprefetcher, LOG, true, replayTLI);
+	XLogPrefetcherBeginRead(prefetcher, RecPtr);
+	record = ReadRecord(prefetcher, LOG, true, replayTLI);
 
 	if (record == NULL)
 	{
-- 
2.39.5 (Apple Git-154)

