summaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@kurilemu.de>2025-11-06 20:33:57 +0100
committerÁlvaro Herrera <alvherre@kurilemu.de>2025-11-06 20:33:57 +0100
commita2b02293bc65dbb2401cb19c724f52c6ee0f2faf (patch)
treef982dafa5b106905027b0e11fe9cdee9fc0bab6f /src/backend/access/transam/xlog.c
parent06edbed478625829b19c35d0c17d805be588afa6 (diff)
Use XLogRecPtrIsValid() in various places
Now that commit 06edbed47862 has introduced XLogRecPtrIsValid(), we can use that instead of: - XLogRecPtrIsInvalid() - direct comparisons with InvalidXLogRecPtr - direct comparisons with literal 0 This makes the code more consistent. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/aQB7EvGqrbZXrMlg@ip-10-97-1-34.eu-west-3.compute.internal
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 7c959051e11..101b616b028 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -849,7 +849,7 @@ XLogInsertRecord(XLogRecData *rdata,
if (doPageWrites &&
(!prevDoPageWrites ||
- (fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
+ (XLogRecPtrIsValid(fpw_lsn) && fpw_lsn <= RedoRecPtr)))
{
/*
* Oops, some buffer now needs to be backed up that the caller
@@ -883,7 +883,7 @@ XLogInsertRecord(XLogRecData *rdata,
* Those checks are only needed for records that can contain buffer
* references, and an XLOG_SWITCH record never does.
*/
- Assert(fpw_lsn == InvalidXLogRecPtr);
+ Assert(!XLogRecPtrIsValid(fpw_lsn));
WALInsertLockAcquireExclusive();
inserted = ReserveXLogSwitch(&StartPos, &EndPos, &rechdr->xl_prev);
}
@@ -898,7 +898,7 @@ XLogInsertRecord(XLogRecData *rdata,
* not check RedoRecPtr before inserting the record; we just need to
* update it afterwards.
*/
- Assert(fpw_lsn == InvalidXLogRecPtr);
+ Assert(!XLogRecPtrIsValid(fpw_lsn));
WALInsertLockAcquireExclusive();
ReserveXLogInsertLocation(rechdr->xl_tot_len, &StartPos, &EndPos,
&rechdr->xl_prev);
@@ -1603,7 +1603,7 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto)
*/
} while (insertingat < upto);
- if (insertingat != InvalidXLogRecPtr && insertingat < finishedUpto)
+ if (XLogRecPtrIsValid(insertingat) && insertingat < finishedUpto)
finishedUpto = insertingat;
}
@@ -1762,7 +1762,7 @@ WALReadFromBuffers(char *dstbuf, XLogRecPtr startptr, Size count,
if (RecoveryInProgress() || tli != GetWALInsertionTimeLine())
return 0;
- Assert(!XLogRecPtrIsInvalid(startptr));
+ Assert(XLogRecPtrIsValid(startptr));
/*
* Caller should ensure that the requested data has been inserted into WAL
@@ -2717,7 +2717,7 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force)
* available is replayed in this case. This also saves from extra locks
* taken on the control file from the startup process.
*/
- if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && InRecovery)
+ if (!XLogRecPtrIsValid(LocalMinRecoveryPoint) && InRecovery)
{
updateMinRecoveryPoint = false;
return;
@@ -2729,7 +2729,7 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force)
LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
- if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint))
+ if (!XLogRecPtrIsValid(LocalMinRecoveryPoint))
updateMinRecoveryPoint = false;
else if (force || LocalMinRecoveryPoint < lsn)
{
@@ -3149,7 +3149,7 @@ XLogNeedsFlush(XLogRecPtr record)
* which cannot update its local copy of minRecoveryPoint as long as
* it has not replayed all WAL available when doing crash recovery.
*/
- if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && InRecovery)
+ if (!XLogRecPtrIsValid(LocalMinRecoveryPoint) && InRecovery)
{
updateMinRecoveryPoint = false;
return false;
@@ -3170,7 +3170,7 @@ XLogNeedsFlush(XLogRecPtr record)
* process doing crash recovery, which should not update the control
* file value if crash recovery is still running.
*/
- if (XLogRecPtrIsInvalid(LocalMinRecoveryPoint))
+ if (!XLogRecPtrIsValid(LocalMinRecoveryPoint))
updateMinRecoveryPoint = false;
/* check again */
@@ -5935,7 +5935,7 @@ StartupXLOG(void)
*/
if (InRecovery &&
(EndOfLog < LocalMinRecoveryPoint ||
- !XLogRecPtrIsInvalid(ControlFile->backupStartPoint)))
+ XLogRecPtrIsValid(ControlFile->backupStartPoint)))
{
/*
* Ran off end of WAL before reaching end-of-backup WAL record, or
@@ -5945,7 +5945,7 @@ StartupXLOG(void)
*/
if (ArchiveRecoveryRequested || ControlFile->backupEndRequired)
{
- if (!XLogRecPtrIsInvalid(ControlFile->backupStartPoint) || ControlFile->backupEndRequired)
+ if (XLogRecPtrIsValid(ControlFile->backupStartPoint) || ControlFile->backupEndRequired)
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("WAL ends before end of online backup"),
@@ -6047,7 +6047,7 @@ StartupXLOG(void)
* (It's critical to first write an OVERWRITE_CONTRECORD message, which
* we'll do as soon as we're open for writing new WAL.)
*/
- if (!XLogRecPtrIsInvalid(missingContrecPtr))
+ if (XLogRecPtrIsValid(missingContrecPtr))
{
/*
* We should only have a missingContrecPtr if we're not switching to a
@@ -6057,7 +6057,7 @@ StartupXLOG(void)
* disregard.
*/
Assert(newTLI == endOfRecoveryInfo->lastRecTLI);
- Assert(!XLogRecPtrIsInvalid(abortedRecPtr));
+ Assert(XLogRecPtrIsValid(abortedRecPtr));
EndOfLog = missingContrecPtr;
}
@@ -6161,9 +6161,9 @@ StartupXLOG(void)
LocalSetXLogInsertAllowed();
/* If necessary, write overwrite-contrecord before doing anything else */
- if (!XLogRecPtrIsInvalid(abortedRecPtr))
+ if (XLogRecPtrIsValid(abortedRecPtr))
{
- Assert(!XLogRecPtrIsInvalid(missingContrecPtr));
+ Assert(XLogRecPtrIsValid(missingContrecPtr));
CreateOverwriteContrecordRecord(abortedRecPtr, missingContrecPtr, newTLI);
}
@@ -7363,7 +7363,7 @@ CreateCheckPoint(int flags)
* Update the average distance between checkpoints if the prior checkpoint
* exists.
*/
- if (PriorRedoPtr != InvalidXLogRecPtr)
+ if (XLogRecPtrIsValid(PriorRedoPtr))
UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
INJECTION_POINT("checkpoint-before-old-wal-removal", NULL);
@@ -7693,7 +7693,7 @@ CreateRestartPoint(int flags)
* restartpoint. It's assumed that flushing the buffers will do that as a
* side-effect.
*/
- if (XLogRecPtrIsInvalid(lastCheckPointRecPtr) ||
+ if (!XLogRecPtrIsValid(lastCheckPointRecPtr) ||
lastCheckPoint.redo <= ControlFile->checkPointCopy.redo)
{
ereport(DEBUG2,
@@ -7811,7 +7811,7 @@ CreateRestartPoint(int flags)
* Update the average distance between checkpoints/restartpoints if the
* prior checkpoint exists.
*/
- if (PriorRedoPtr != InvalidXLogRecPtr)
+ if (XLogRecPtrIsValid(PriorRedoPtr))
UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
/*
@@ -7936,7 +7936,7 @@ GetWALAvailability(XLogRecPtr targetLSN)
/*
* slot does not reserve WAL. Either deactivated, or has never been active
*/
- if (XLogRecPtrIsInvalid(targetLSN))
+ if (!XLogRecPtrIsValid(targetLSN))
return WALAVAIL_INVALID_LSN;
/*
@@ -8018,7 +8018,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
/* Calculate how many segments are kept by slots. */
keep = XLogGetReplicationSlotMinimumLSN();
- if (keep != InvalidXLogRecPtr && keep < recptr)
+ if (XLogRecPtrIsValid(keep) && keep < recptr)
{
XLByteToSeg(keep, segno, wal_segment_size);
@@ -8045,7 +8045,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
* summarized.
*/
keep = GetOldestUnsummarizedLSN(NULL, NULL);
- if (keep != InvalidXLogRecPtr)
+ if (XLogRecPtrIsValid(keep))
{
XLogSegNo unsummarized_segno;
@@ -8352,8 +8352,8 @@ xlog_redo(XLogReaderState *record)
* never arrive.
*/
if (ArchiveRecoveryRequested &&
- !XLogRecPtrIsInvalid(ControlFile->backupStartPoint) &&
- XLogRecPtrIsInvalid(ControlFile->backupEndPoint))
+ XLogRecPtrIsValid(ControlFile->backupStartPoint) &&
+ !XLogRecPtrIsValid(ControlFile->backupEndPoint))
ereport(PANIC,
(errmsg("online backup was canceled, recovery cannot continue")));
@@ -8603,7 +8603,7 @@ xlog_redo(XLogReaderState *record)
LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
}
- if (LocalMinRecoveryPoint != InvalidXLogRecPtr && LocalMinRecoveryPoint < lsn)
+ if (XLogRecPtrIsValid(LocalMinRecoveryPoint) && LocalMinRecoveryPoint < lsn)
{
TimeLineID replayTLI;