From 668365014d7b330fa828826ff94653d446971a86 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 18 Dec 2019 10:11:36 +0900 Subject: [PATCH] Remove shadow variables linked to RedoRecPtr in xlog.c This changes the routines in charge of recycling WAL segments past the last redo LSN to not use anymore "RedoRecPtr" as a local variable, which is also available in the context of the session as a static declaration, replacing it with "lastredoptr". This confusion has been introduced by d9fadbf, so backpatch down to v11 like the other commit. Thanks to Tom Lane, Robert Haas, Alvaro Herrera, Mark Dilger and Kyotaro Horiguchi for the input provided. Author: Ranier Vilela Discussion: https://postgr.es/m/MN2PR18MB2927F7B5F690065E1194B258E35D0@MN2PR18MB2927.namprd18.prod.outlook.com Backpatch-through: 11 --- src/backend/access/transam/xlog.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6ce037bd83..f6cd4fde2b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -887,8 +887,8 @@ static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr); static void XLogFileClose(void); static void PreallocXlogFiles(XLogRecPtr endptr); -static void RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr RedoRecPtr, XLogRecPtr endptr); -static void RemoveXlogFile(const char *segname, XLogRecPtr RedoRecPtr, XLogRecPtr endptr); +static void RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr); +static void RemoveXlogFile(const char *segname, XLogRecPtr lastredoptr, XLogRecPtr endptr); static void UpdateLastRemovedPtr(char *filename); static void ValidateXLOGDirectoryStructure(void); static void CleanupBackupHistory(void); @@ -2293,7 +2293,7 @@ assign_checkpoint_completion_target(double newval, void *extra) * XLOG segments? Returns the highest segment that should be preallocated. */ static XLogSegNo -XLOGfileslop(XLogRecPtr RedoRecPtr) +XLOGfileslop(XLogRecPtr lastredoptr) { XLogSegNo minSegNo; XLogSegNo maxSegNo; @@ -2305,9 +2305,9 @@ XLOGfileslop(XLogRecPtr RedoRecPtr) * correspond to. Always recycle enough segments to meet the minimum, and * remove enough segments to stay below the maximum. */ - minSegNo = RedoRecPtr / wal_segment_size + + minSegNo = lastredoptr / wal_segment_size + ConvertToXSegs(min_wal_size_mb, wal_segment_size) - 1; - maxSegNo = RedoRecPtr / wal_segment_size + + maxSegNo = lastredoptr / wal_segment_size + ConvertToXSegs(max_wal_size_mb, wal_segment_size) - 1; /* @@ -2322,7 +2322,7 @@ XLOGfileslop(XLogRecPtr RedoRecPtr) /* add 10% for good measure. */ distance *= 1.10; - recycleSegNo = (XLogSegNo) ceil(((double) RedoRecPtr + distance) / + recycleSegNo = (XLogSegNo) ceil(((double) lastredoptr + distance) / wal_segment_size); if (recycleSegNo < minSegNo) @@ -3887,12 +3887,12 @@ UpdateLastRemovedPtr(char *filename) /* * Recycle or remove all log files older or equal to passed segno. * - * endptr is current (or recent) end of xlog, and RedoRecPtr is the + * endptr is current (or recent) end of xlog, and lastredoptr is the * redo pointer of the last checkpoint. These are used to determine * whether we want to recycle rather than delete no-longer-wanted log files. */ static void -RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr RedoRecPtr, XLogRecPtr endptr) +RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr) { DIR *xldir; struct dirent *xlde; @@ -3935,7 +3935,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr RedoRecPtr, XLogRecPtr endptr) /* Update the last removed location in shared memory first */ UpdateLastRemovedPtr(xlde->d_name); - RemoveXlogFile(xlde->d_name, RedoRecPtr, endptr); + RemoveXlogFile(xlde->d_name, lastredoptr, endptr); } } } @@ -4009,14 +4009,14 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI) /* * Recycle or remove a log file that's no longer needed. * - * endptr is current (or recent) end of xlog, and RedoRecPtr is the + * endptr is current (or recent) end of xlog, and lastredoptr is the * redo pointer of the last checkpoint. These are used to determine * whether we want to recycle rather than delete no-longer-wanted log files. - * If RedoRecPtr is not known, pass invalid, and the function will recycle, + * If lastredoptr is not known, pass invalid, and the function will recycle, * somewhat arbitrarily, 10 future segments. */ static void -RemoveXlogFile(const char *segname, XLogRecPtr RedoRecPtr, XLogRecPtr endptr) +RemoveXlogFile(const char *segname, XLogRecPtr lastredoptr, XLogRecPtr endptr) { char path[MAXPGPATH]; #ifdef WIN32 @@ -4030,10 +4030,10 @@ RemoveXlogFile(const char *segname, XLogRecPtr RedoRecPtr, XLogRecPtr endptr) * Initialize info about where to try to recycle to. */ XLByteToSeg(endptr, endlogSegNo, wal_segment_size); - if (RedoRecPtr == InvalidXLogRecPtr) + if (lastredoptr == InvalidXLogRecPtr) recycleSegNo = endlogSegNo + 10; else - recycleSegNo = XLOGfileslop(RedoRecPtr); + recycleSegNo = XLOGfileslop(lastredoptr); snprintf(path, MAXPGPATH, XLOGDIR "/%s", segname);