Hi hackers, While working on refactoring some code in [1], one of the changes was:
- if (initial_restart_lsn != InvalidXLogRecPtr && - initial_restart_lsn < oldestLSN) + XLogRecPtr restart_lsn = s->data.restart_lsn; + + if (restart_lsn != InvalidXLogRecPtr && + restart_lsn < oldestLSN) Sawada-san suggested to use the XLogRecPtrIsInvalid() macro here. But this != InvalidXLogRecPtr check was existing code, so why not consistently use XLogRecPtrIsInvalid() where we check equality against InvalidXLogRecPtr? At the time the current XLogRecPtrIsInvalid() has been introduced (0ab9d1c4b316) all the InvalidXLogRecPtr equality checks were done using XLogRecPtrIsInvalid(). But since, it has changed: I looked at it and this is not the case anymore in 20 files. PFA, patches to $SUBJECT. To ease the review, I created one patch per modified file. I suspect the same approach could be applied to some other macros too. Let's start with XLogRecPtrIsInvalid() first. I think that's one of the things we could do once a year, like Peter does with his annual "clang-tidy" check ([2]). Thoughts? [1]: https://www.postgresql.org/message-id/CAD21AoB_C6V1PLNs%3DSuOejgGh1o6ZHJMstD7X4X1b_z%3D%3DLdH1Q%40mail.gmail.com [2]: https://www.postgresql.org/message-id/cah2-wzmxpqaf_zhwruo3rzvk3yyj_4mqbgiqxaggo5nfyv3...@mail.gmail.com Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
>From 16e7a6e300ece55efaf67bf22e9d5f5d488e5114 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:39:59 +0000 Subject: [PATCH v1 01/20] make use of XLogRecPtrIsInvalid in rewriteheap.c --- src/backend/access/heap/rewriteheap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 100.0% src/backend/access/heap/ diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 8061e92f044..e4cff133886 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -1169,7 +1169,7 @@ CheckPointLogicalRewriteHeap(void) cutoff = ReplicationSlotsComputeLogicalRestartLSN(); /* don't start earlier than the restart lsn */ - if (cutoff != InvalidXLogRecPtr && redo < cutoff) + if (!XLogRecPtrIsInvalid(cutoff) && redo < cutoff) cutoff = redo; mappings_dir = AllocateDir(PG_LOGICAL_MAPPINGS_DIR); @@ -1204,7 +1204,7 @@ CheckPointLogicalRewriteHeap(void) lsn = ((uint64) hi) << 32 | lo; - if (lsn < cutoff || cutoff == InvalidXLogRecPtr) + if (lsn < cutoff || XLogRecPtrIsInvalid(cutoff)) { elog(DEBUG1, "removing logical rewrite file \"%s\"", path); if (unlink(path) < 0) -- 2.34.1
>From b851563ba0efede5db4c683d7319caf029c531cb Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:42:51 +0000 Subject: [PATCH v1 02/20] make use of XLogRecPtrIsInvalid in twophase.c --- src/backend/access/transam/twophase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 33369fbe23a..362a5afc4de 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -2198,7 +2198,7 @@ ProcessTwoPhaseBuffer(FullTransactionId fxid, Assert(LWLockHeldByMeInMode(TwoPhaseStateLock, LW_EXCLUSIVE)); if (!fromdisk) - Assert(prepare_start_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(prepare_start_lsn)); /* Already processed? */ if (TransactionIdDidCommit(XidFromFullTransactionId(fxid)) || -- 2.34.1
>From 8997aba7245bdf8b5009228844599a839dd82861 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:47:29 +0000 Subject: [PATCH v1 03/20] make use of XLogRecPtrIsInvalid in xlog.c --- src/backend/access/transam/xlog.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index eceab341255..176bebf1ea9 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -847,7 +847,7 @@ XLogInsertRecord(XLogRecData *rdata, if (doPageWrites && (!prevDoPageWrites || - (fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr))) + (!XLogRecPtrIsInvalid(fpw_lsn) && fpw_lsn <= RedoRecPtr))) { /* * Oops, some buffer now needs to be backed up that the caller @@ -881,7 +881,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(XLogRecPtrIsInvalid(fpw_lsn)); WALInsertLockAcquireExclusive(); inserted = ReserveXLogSwitch(&StartPos, &EndPos, &rechdr->xl_prev); } @@ -896,7 +896,7 @@ XLogInsertRecord(XLogRecData *rdata, * not check RedoRecPtr before inserting the record; we just need to * update it afterwards. */ - Assert(fpw_lsn == InvalidXLogRecPtr); + Assert(XLogRecPtrIsInvalid(fpw_lsn)); WALInsertLockAcquireExclusive(); ReserveXLogInsertLocation(rechdr->xl_tot_len, &StartPos, &EndPos, &rechdr->xl_prev); @@ -1600,7 +1600,7 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto) */ } while (insertingat < upto); - if (insertingat != InvalidXLogRecPtr && insertingat < finishedUpto) + if (!XLogRecPtrIsInvalid(insertingat) && insertingat < finishedUpto) finishedUpto = insertingat; } @@ -7354,7 +7354,7 @@ CreateCheckPoint(int flags) * Update the average distance between checkpoints if the prior checkpoint * exists. */ - if (PriorRedoPtr != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(PriorRedoPtr)) UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr); INJECTION_POINT("checkpoint-before-old-wal-removal", NULL); @@ -7802,7 +7802,7 @@ CreateRestartPoint(int flags) * Update the average distance between checkpoints/restartpoints if the * prior checkpoint exists. */ - if (PriorRedoPtr != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(PriorRedoPtr)) UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr); /* @@ -8009,7 +8009,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) /* Calculate how many segments are kept by slots. */ keep = XLogGetReplicationSlotMinimumLSN(); - if (keep != InvalidXLogRecPtr && keep < recptr) + if (!XLogRecPtrIsInvalid(keep) && keep < recptr) { XLByteToSeg(keep, segno, wal_segment_size); @@ -8036,7 +8036,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) * summarized. */ keep = GetOldestUnsummarizedLSN(NULL, NULL); - if (keep != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(keep)) { XLogSegNo unsummarized_segno; @@ -8594,7 +8594,7 @@ xlog_redo(XLogReaderState *record) LocalMinRecoveryPoint = ControlFile->minRecoveryPoint; LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI; } - if (LocalMinRecoveryPoint != InvalidXLogRecPtr && LocalMinRecoveryPoint < lsn) + if (!XLogRecPtrIsInvalid(LocalMinRecoveryPoint) && LocalMinRecoveryPoint < lsn) { TimeLineID replayTLI; -- 2.34.1
>From c4c5601e2110a46928726bb1b120486862a49a24 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:53:48 +0000 Subject: [PATCH v1 04/20] make use of XLogRecPtrIsInvalid in xloginsert.c --- src/backend/access/transam/xloginsert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 496e0fa4ac6..9c873393c1b 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -523,7 +523,7 @@ XLogInsert(RmgrId rmid, uint8 info) EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpi, topxid_included); - } while (EndPos == InvalidXLogRecPtr); + } while (XLogRecPtrIsInvalid(EndPos)); XLogResetInsertion(); @@ -633,7 +633,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, needs_backup = (page_lsn <= RedoRecPtr); if (!needs_backup) { - if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn) + if (XLogRecPtrIsInvalid(*fpw_lsn) || page_lsn < *fpw_lsn) *fpw_lsn = page_lsn; } } -- 2.34.1
>From 2fa79374dc2be16764360093cb0d3ff3660a2a4d Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:55:21 +0000 Subject: [PATCH v1 05/20] make use of XLogRecPtrIsInvalid in xlogreader.c --- src/backend/access/transam/xlogreader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index dcc8d4f9c1b..5e3ebdeacc3 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -558,7 +558,7 @@ XLogDecodeNextRecord(XLogReaderState *state, bool nonblocking) RecPtr = state->NextRecPtr; - if (state->DecodeRecPtr != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(state->DecodeRecPtr)) { /* read the record after the one we just read */ -- 2.34.1
>From 172d98bcca7b733f8e5f7e1e0266029cedf0aede Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 05:58:08 +0000 Subject: [PATCH v1 06/20] make use of XLogRecPtrIsInvalid in xlogrecovery.c --- src/backend/access/transam/xlogrecovery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 3e3c4da01a2..eb999584aa9 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -757,9 +757,9 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, * end-of-backup record), and we can enter archive recovery directly. */ if (ArchiveRecoveryRequested && - (ControlFile->minRecoveryPoint != InvalidXLogRecPtr || + (!XLogRecPtrIsInvalid(ControlFile->minRecoveryPoint) || ControlFile->backupEndRequired || - ControlFile->backupEndPoint != InvalidXLogRecPtr || + !XLogRecPtrIsInvalid(ControlFile->backupEndPoint) || ControlFile->state == DB_SHUTDOWNED)) { InArchiveRecovery = true; @@ -3151,7 +3151,7 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, /* Pass through parameters to XLogPageRead */ private->fetching_ckpt = fetching_ckpt; private->emode = emode; - private->randAccess = (xlogreader->ReadRecPtr == InvalidXLogRecPtr); + private->randAccess = (XLogRecPtrIsInvalid(xlogreader->ReadRecPtr)); private->replayTLI = replayTLI; /* This is the first attempt to read this page. */ @@ -4336,7 +4336,7 @@ XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source) * Skip scanning the timeline ID that the logfile segment to read * doesn't belong to */ - if (hent->begin != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(hent->begin)) { XLogSegNo beginseg = 0; -- 2.34.1
>From f39f1db6f737bd155a804ec8f1859ab781dd83c4 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:00:26 +0000 Subject: [PATCH v1 07/20] make use of XLogRecPtrIsInvalid in xlogutils.c --- src/backend/access/transam/xlogutils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 100.0% src/backend/access/transam/ diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 38176d9688e..9e8a5ac627b 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -710,7 +710,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, const XLogRecPtr lastReadPage = (state->seg.ws_segno * state->segcxt.ws_segsize + state->segoff); - Assert(wantPage != InvalidXLogRecPtr && wantPage % XLOG_BLCKSZ == 0); + Assert(!XLogRecPtrIsInvalid(wantPage) && wantPage % XLOG_BLCKSZ == 0); Assert(wantLength <= XLOG_BLCKSZ); Assert(state->readLen == 0 || state->readLen <= XLOG_BLCKSZ); Assert(currTLI != 0); @@ -741,7 +741,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, */ if (state->currTLI == currTLI && wantPage >= lastReadPage) { - Assert(state->currTLIValidUntil == InvalidXLogRecPtr); + Assert(XLogRecPtrIsInvalid(state->currTLIValidUntil)); return; } @@ -750,7 +750,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, * timeline and the timeline we're reading from is valid until the end of * the current segment we can just keep reading. */ - if (state->currTLIValidUntil != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(state->currTLIValidUntil) && state->currTLI != currTLI && state->currTLI != 0 && ((wantPage + wantLength) / state->segcxt.ws_segsize) < @@ -790,7 +790,7 @@ XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, state->currTLIValidUntil = tliSwitchPoint(state->currTLI, timelineHistory, &state->nextTLI); - Assert(state->currTLIValidUntil == InvalidXLogRecPtr || + Assert(XLogRecPtrIsInvalid(state->currTLIValidUntil) || wantPage + wantLength < state->currTLIValidUntil); list_free_deep(timelineHistory); -- 2.34.1
>From 85bc1c838d16db2fc7d097868a85a93a8e992eeb Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:01:56 +0000 Subject: [PATCH v1 08/20] make use of XLogRecPtrIsInvalid in pg_subscription.c --- src/backend/catalog/pg_subscription.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 100.0% src/backend/catalog/ diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c index 15b233a37d8..c3ecd717de0 100644 --- a/src/backend/catalog/pg_subscription.c +++ b/src/backend/catalog/pg_subscription.c @@ -293,7 +293,7 @@ AddSubscriptionRelState(Oid subid, Oid relid, char state, values[Anum_pg_subscription_rel_srsubid - 1] = ObjectIdGetDatum(subid); values[Anum_pg_subscription_rel_srrelid - 1] = ObjectIdGetDatum(relid); values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state); - if (sublsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(sublsn)) values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn); else nulls[Anum_pg_subscription_rel_srsublsn - 1] = true; @@ -366,7 +366,7 @@ UpdateSubscriptionRelState(Oid subid, Oid relid, char state, values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state); replaces[Anum_pg_subscription_rel_srsublsn - 1] = true; - if (sublsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(sublsn)) values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn); else nulls[Anum_pg_subscription_rel_srsublsn - 1] = true; -- 2.34.1
>From 66b5a37a26613d830ead892411466329f5d53b6f Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:08:37 +0000 Subject: [PATCH v1 09/20] make use of XLogRecPtrIsInvalid in logical.c --- src/backend/replication/logical/logical.c | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 93ed2eb368e..295e83ad9d6 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -546,9 +546,9 @@ CreateDecodingContext(XLogRecPtr start_lsn, /* slot must be valid to allow decoding */ Assert(slot->data.invalidated == RS_INVAL_NONE); - Assert(slot->data.restart_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(slot->data.restart_lsn)); - if (start_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(start_lsn)) { /* continue from last position */ start_lsn = slot->data.confirmed_flush; @@ -757,7 +757,7 @@ output_plugin_error_callback(void *arg) LogicalErrorCallbackState *state = (LogicalErrorCallbackState *) arg; /* not all callbacks have an associated LSN */ - if (state->report_location != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(state->report_location)) errcontext("slot \"%s\", output plugin \"%s\", in the %s callback, associated LSN %X/%08X", NameStr(state->ctx->slot->data.name), NameStr(state->ctx->slot->data.plugin), @@ -1711,7 +1711,7 @@ LogicalIncreaseXminForSlot(XLogRecPtr current_lsn, TransactionId xmin) * Only increase if the previous values have been applied, otherwise we * might never end up updating if the receiver acks too slowly. */ - else if (slot->candidate_xmin_lsn == InvalidXLogRecPtr) + else if (XLogRecPtrIsInvalid(slot->candidate_xmin_lsn)) { slot->candidate_catalog_xmin = xmin; slot->candidate_xmin_lsn = current_lsn; @@ -1749,8 +1749,8 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart slot = MyReplicationSlot; Assert(slot != NULL); - Assert(restart_lsn != InvalidXLogRecPtr); - Assert(current_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(restart_lsn)); + Assert(!XLogRecPtrIsInvalid(current_lsn)); SpinLockAcquire(&slot->mutex); @@ -1779,7 +1779,7 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart * might never end up updating if the receiver acks too slowly. A missed * value here will just cause some extra effort after reconnecting. */ - else if (slot->candidate_restart_valid == InvalidXLogRecPtr) + else if (XLogRecPtrIsInvalid(slot->candidate_restart_valid)) { slot->candidate_restart_valid = current_lsn; slot->candidate_restart_lsn = restart_lsn; @@ -1819,11 +1819,11 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart void LogicalConfirmReceivedLocation(XLogRecPtr lsn) { - Assert(lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(lsn)); /* Do an unlocked check for candidate_lsn first. */ - if (MyReplicationSlot->candidate_xmin_lsn != InvalidXLogRecPtr || - MyReplicationSlot->candidate_restart_valid != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(MyReplicationSlot->candidate_xmin_lsn) || + !XLogRecPtrIsInvalid(MyReplicationSlot->candidate_restart_valid)) { bool updated_xmin = false; bool updated_restart = false; @@ -1849,7 +1849,7 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn) MyReplicationSlot->data.confirmed_flush = lsn; /* if we're past the location required for bumping xmin, do so */ - if (MyReplicationSlot->candidate_xmin_lsn != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(MyReplicationSlot->candidate_xmin_lsn) && MyReplicationSlot->candidate_xmin_lsn <= lsn) { /* @@ -1871,10 +1871,10 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn) } } - if (MyReplicationSlot->candidate_restart_valid != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(MyReplicationSlot->candidate_restart_valid) && MyReplicationSlot->candidate_restart_valid <= lsn) { - Assert(MyReplicationSlot->candidate_restart_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(MyReplicationSlot->candidate_restart_lsn)); MyReplicationSlot->data.restart_lsn = MyReplicationSlot->candidate_restart_lsn; MyReplicationSlot->candidate_restart_lsn = InvalidXLogRecPtr; @@ -2089,7 +2089,7 @@ LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto, ResourceOwner old_resowner PG_USED_FOR_ASSERTS_ONLY = CurrentResourceOwner; XLogRecPtr retlsn; - Assert(moveto != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(moveto)); if (found_consistent_snapshot) *found_consistent_snapshot = false; @@ -2163,7 +2163,7 @@ LogicalSlotAdvanceAndCheckSnapState(XLogRecPtr moveto, if (found_consistent_snapshot && DecodingContextReady(ctx)) *found_consistent_snapshot = true; - if (ctx->reader->EndRecPtr != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(ctx->reader->EndRecPtr)) { LogicalConfirmReceivedLocation(moveto); -- 2.34.1
>From c93a6925615fe4384e6c85941c28198e4a66c10e Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:10:16 +0000 Subject: [PATCH v1 10/20] make use of XLogRecPtrIsInvalid in logicalfuncs.c --- src/backend/replication/logical/logicalfuncs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c index 25f890ddeed..4d1e7a55d6d 100644 --- a/src/backend/replication/logical/logicalfuncs.c +++ b/src/backend/replication/logical/logicalfuncs.c @@ -276,7 +276,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin } /* check limits */ - if (upto_lsn != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(upto_lsn) && upto_lsn <= ctx->reader->EndRecPtr) break; if (upto_nchanges != 0 && @@ -289,7 +289,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin * Next time, start where we left off. (Hunting things, the family * business..) */ - if (ctx->reader->EndRecPtr != InvalidXLogRecPtr && confirm) + if (!XLogRecPtrIsInvalid(ctx->reader->EndRecPtr) && confirm) { LogicalConfirmReceivedLocation(ctx->reader->EndRecPtr); -- 2.34.1
>From 0eeb8b4ad8288c2000e6478b0121e17c8f7596a7 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:14:38 +0000 Subject: [PATCH v1 11/20] make use of XLogRecPtrIsInvalid in origin.c --- src/backend/replication/logical/origin.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c index bcd5d9aad62..3573a0cedca 100644 --- a/src/backend/replication/logical/origin.c +++ b/src/backend/replication/logical/origin.c @@ -984,8 +984,8 @@ replorigin_advance(RepOriginId node, /* initialize new slot */ LWLockAcquire(&free_state->lock, LW_EXCLUSIVE); replication_state = free_state; - Assert(replication_state->remote_lsn == InvalidXLogRecPtr); - Assert(replication_state->local_lsn == InvalidXLogRecPtr); + Assert(XLogRecPtrIsInvalid(replication_state->remote_lsn)); + Assert(XLogRecPtrIsInvalid(replication_state->local_lsn)); replication_state->roident = node; } @@ -1020,7 +1020,7 @@ replorigin_advance(RepOriginId node, */ if (go_backward || replication_state->remote_lsn < remote_commit) replication_state->remote_lsn = remote_commit; - if (local_commit != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(local_commit) && (go_backward || replication_state->local_lsn < local_commit)) replication_state->local_lsn = local_commit; LWLockRelease(&replication_state->lock); @@ -1064,7 +1064,7 @@ replorigin_get_progress(RepOriginId node, bool flush) LWLockRelease(ReplicationOriginLock); - if (flush && local_lsn != InvalidXLogRecPtr) + if (flush && !XLogRecPtrIsInvalid(local_lsn)) XLogFlush(local_lsn); return remote_lsn; @@ -1197,8 +1197,8 @@ replorigin_session_setup(RepOriginId node, int acquired_by) /* initialize new slot */ session_replication_state = &replication_states[free_slot]; - Assert(session_replication_state->remote_lsn == InvalidXLogRecPtr); - Assert(session_replication_state->local_lsn == InvalidXLogRecPtr); + Assert(XLogRecPtrIsInvalid(session_replication_state->remote_lsn)); + Assert(XLogRecPtrIsInvalid(session_replication_state->local_lsn)); session_replication_state->roident = node; } @@ -1282,7 +1282,7 @@ replorigin_session_get_progress(bool flush) local_lsn = session_replication_state->local_lsn; LWLockRelease(&session_replication_state->lock); - if (flush && local_lsn != InvalidXLogRecPtr) + if (flush && !XLogRecPtrIsInvalid(local_lsn)) XLogFlush(local_lsn); return remote_lsn; @@ -1454,7 +1454,7 @@ pg_replication_origin_session_progress(PG_FUNCTION_ARGS) remote_lsn = replorigin_session_get_progress(flush); - if (remote_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(remote_lsn)) PG_RETURN_NULL(); PG_RETURN_LSN(remote_lsn); @@ -1543,7 +1543,7 @@ pg_replication_origin_progress(PG_FUNCTION_ARGS) remote_lsn = replorigin_get_progress(roident, flush); - if (remote_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(remote_lsn)) PG_RETURN_NULL(); PG_RETURN_LSN(remote_lsn); -- 2.34.1
>From 8265d4a2d4a06bf27727796497100bb928c7cd18 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:20:44 +0000 Subject: [PATCH v1 12/20] make use of XLogRecPtrIsInvalid in proto.c --- src/backend/replication/logical/proto.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c index ed62888764c..28f0e2e45f1 100644 --- a/src/backend/replication/logical/proto.c +++ b/src/backend/replication/logical/proto.c @@ -64,7 +64,7 @@ logicalrep_read_begin(StringInfo in, LogicalRepBeginData *begin_data) { /* read fields */ begin_data->final_lsn = pq_getmsgint64(in); - if (begin_data->final_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(begin_data->final_lsn)) elog(ERROR, "final_lsn not set in begin message"); begin_data->committime = pq_getmsgint64(in); begin_data->xid = pq_getmsgint(in, 4); @@ -135,10 +135,10 @@ logicalrep_read_begin_prepare(StringInfo in, LogicalRepPreparedTxnData *begin_da { /* read fields */ begin_data->prepare_lsn = pq_getmsgint64(in); - if (begin_data->prepare_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(begin_data->prepare_lsn)) elog(ERROR, "prepare_lsn not set in begin prepare message"); begin_data->end_lsn = pq_getmsgint64(in); - if (begin_data->end_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(begin_data->end_lsn)) elog(ERROR, "end_lsn not set in begin prepare message"); begin_data->prepare_time = pq_getmsgint64(in); begin_data->xid = pq_getmsgint(in, 4); @@ -207,10 +207,10 @@ logicalrep_read_prepare_common(StringInfo in, char *msgtype, /* read fields */ prepare_data->prepare_lsn = pq_getmsgint64(in); - if (prepare_data->prepare_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(prepare_data->prepare_lsn)) elog(ERROR, "prepare_lsn is not set in %s message", msgtype); prepare_data->end_lsn = pq_getmsgint64(in); - if (prepare_data->end_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(prepare_data->end_lsn)) elog(ERROR, "end_lsn is not set in %s message", msgtype); prepare_data->prepare_time = pq_getmsgint64(in); prepare_data->xid = pq_getmsgint(in, 4); @@ -274,10 +274,10 @@ logicalrep_read_commit_prepared(StringInfo in, LogicalRepCommitPreparedTxnData * /* read fields */ prepare_data->commit_lsn = pq_getmsgint64(in); - if (prepare_data->commit_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(prepare_data->commit_lsn)) elog(ERROR, "commit_lsn is not set in commit prepared message"); prepare_data->end_lsn = pq_getmsgint64(in); - if (prepare_data->end_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(prepare_data->end_lsn)) elog(ERROR, "end_lsn is not set in commit prepared message"); prepare_data->commit_time = pq_getmsgint64(in); prepare_data->xid = pq_getmsgint(in, 4); @@ -333,10 +333,10 @@ logicalrep_read_rollback_prepared(StringInfo in, /* read fields */ rollback_data->prepare_end_lsn = pq_getmsgint64(in); - if (rollback_data->prepare_end_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(rollback_data->prepare_end_lsn)) elog(ERROR, "prepare_end_lsn is not set in rollback prepared message"); rollback_data->rollback_end_lsn = pq_getmsgint64(in); - if (rollback_data->rollback_end_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(rollback_data->rollback_end_lsn)) elog(ERROR, "rollback_end_lsn is not set in rollback prepared message"); rollback_data->prepare_time = pq_getmsgint64(in); rollback_data->rollback_time = pq_getmsgint64(in); -- 2.34.1
>From 727e6a69fc0a94942be9f90074aa886347c0de26 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:27:43 +0000 Subject: [PATCH v1 13/20] make use of XLogRecPtrIsInvalid in reorderbuffer.c --- .../replication/logical/reorderbuffer.c | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index b57aef9916d..316f81c73e3 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -701,7 +701,7 @@ ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create, { /* initialize the new entry, if creation was requested */ Assert(ent != NULL); - Assert(lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(lsn)); ent->txn = ReorderBufferAllocTXN(rb); ent->txn->xid = xid; @@ -849,7 +849,7 @@ ReorderBufferQueueChange(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, change->lsn = lsn; change->txn = txn; - Assert(InvalidXLogRecPtr != lsn); + Assert(!XLogRecPtrIsInvalid(lsn)); dlist_push_tail(&txn->changes, &change->node); txn->nentries++; txn->nentries_mem++; @@ -966,14 +966,14 @@ AssertTXNLsnOrder(ReorderBuffer *rb) iter.cur); /* start LSN must be set */ - Assert(cur_txn->first_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(cur_txn->first_lsn)); /* If there is an end LSN, it must be higher than start LSN */ - if (cur_txn->end_lsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(cur_txn->end_lsn)) Assert(cur_txn->first_lsn <= cur_txn->end_lsn); /* Current initial LSN must be strictly higher than previous */ - if (prev_first_lsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(prev_first_lsn)) Assert(prev_first_lsn < cur_txn->first_lsn); /* known-as-subtxn txns must not be listed */ @@ -990,10 +990,10 @@ AssertTXNLsnOrder(ReorderBuffer *rb) /* base snapshot (and its LSN) must be set */ Assert(cur_txn->base_snapshot != NULL); - Assert(cur_txn->base_snapshot_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(cur_txn->base_snapshot_lsn)); /* current LSN must be strictly higher than previous */ - if (prev_base_snap_lsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(prev_base_snap_lsn)) Assert(prev_base_snap_lsn < cur_txn->base_snapshot_lsn); /* known-as-subtxn txns must not be listed */ @@ -1022,11 +1022,11 @@ AssertChangeLsnOrder(ReorderBufferTXN *txn) cur_change = dlist_container(ReorderBufferChange, node, iter.cur); - Assert(txn->first_lsn != InvalidXLogRecPtr); - Assert(cur_change->lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->first_lsn)); + Assert(!XLogRecPtrIsInvalid(cur_change->lsn)); Assert(txn->first_lsn <= cur_change->lsn); - if (txn->end_lsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(txn->end_lsn)) Assert(cur_change->lsn <= txn->end_lsn); Assert(prev_lsn <= cur_change->lsn); @@ -1053,7 +1053,7 @@ ReorderBufferGetOldestTXN(ReorderBuffer *rb) txn = dlist_head_element(ReorderBufferTXN, node, &rb->toplevel_by_lsn); Assert(!rbtxn_is_known_subxact(txn)); - Assert(txn->first_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->first_lsn)); return txn; } @@ -2276,7 +2276,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, * We can't call start stream callback before processing first * change. */ - if (prev_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(prev_lsn)) { if (streaming) { @@ -2291,7 +2291,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, * subtransactions. The changes may have the same LSN due to * MULTI_INSERT xlog records. */ - Assert(prev_lsn == InvalidXLogRecPtr || prev_lsn <= change->lsn); + Assert(XLogRecPtrIsInvalid(prev_lsn) || prev_lsn <= change->lsn); prev_lsn = change->lsn; @@ -2975,7 +2975,7 @@ ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid, * have been updated in it by now. */ Assert((txn->txn_flags & RBTXN_PREPARE_STATUS_MASK) == RBTXN_IS_PREPARED); - Assert(txn->final_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->final_lsn)); txn->gid = pstrdup(gid); @@ -3041,7 +3041,7 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid, */ Assert((txn->txn_flags & RBTXN_PREPARE_STATUS_MASK) == (RBTXN_IS_PREPARED | RBTXN_SKIPPED_PREPARE)); - Assert(txn->final_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->final_lsn)); /* * By this time the txn has the prepare record information and it is @@ -4552,8 +4552,8 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn, dlist_mutable_iter cleanup_iter; File *fd = &file->vfd; - Assert(txn->first_lsn != InvalidXLogRecPtr); - Assert(txn->final_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->first_lsn)); + Assert(!XLogRecPtrIsInvalid(txn->final_lsn)); /* free current entries, so we have memory for more */ dlist_foreach_modify(cleanup_iter, &txn->changes) @@ -4860,8 +4860,8 @@ ReorderBufferRestoreCleanup(ReorderBuffer *rb, ReorderBufferTXN *txn) XLogSegNo cur; XLogSegNo last; - Assert(txn->first_lsn != InvalidXLogRecPtr); - Assert(txn->final_lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(txn->first_lsn)); + Assert(!XLogRecPtrIsInvalid(txn->final_lsn)); XLByteToSeg(txn->first_lsn, first, wal_segment_size); XLByteToSeg(txn->final_lsn, last, wal_segment_size); -- 2.34.1
>From a886f2c23b3b93ab3fa3742e9e57eaee3cd896a2 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:31:31 +0000 Subject: [PATCH v1 14/20] make use of XLogRecPtrIsInvalid in snapbuild.c --- src/backend/replication/logical/snapbuild.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 100.0% src/backend/replication/logical/ diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index 98ddee20929..6014b423853 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1210,7 +1210,7 @@ SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xact * oldest ongoing txn might have started when we didn't yet serialize * anything because we hadn't reached a consistent state yet. */ - if (txn != NULL && txn->restart_decoding_lsn != InvalidXLogRecPtr) + if (txn != NULL && !XLogRecPtrIsInvalid(txn->restart_decoding_lsn)) LogicalIncreaseRestartDecodingForSlot(lsn, txn->restart_decoding_lsn); /* @@ -1218,8 +1218,8 @@ SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xact * we have one. */ else if (txn == NULL && - builder->reorder->current_restart_decoding_lsn != InvalidXLogRecPtr && - builder->last_serialized_snapshot != InvalidXLogRecPtr) + !XLogRecPtrIsInvalid(builder->reorder->current_restart_decoding_lsn) && + !XLogRecPtrIsInvalid(builder->last_serialized_snapshot)) LogicalIncreaseRestartDecodingForSlot(lsn, builder->last_serialized_snapshot); } @@ -1293,7 +1293,7 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn */ if (running->oldestRunningXid == running->nextXid) { - if (builder->start_decoding_at == InvalidXLogRecPtr || + if (XLogRecPtrIsInvalid(builder->start_decoding_at) || builder->start_decoding_at <= lsn) /* can decode everything after this */ builder->start_decoding_at = lsn + 1; @@ -1509,8 +1509,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn) struct stat stat_buf; Size sz; - Assert(lsn != InvalidXLogRecPtr); - Assert(builder->last_serialized_snapshot == InvalidXLogRecPtr || + Assert(!XLogRecPtrIsInvalid(lsn)); + Assert(XLogRecPtrIsInvalid(builder->last_serialized_snapshot) || builder->last_serialized_snapshot <= lsn); /* @@ -2029,7 +2029,7 @@ CheckPointSnapBuild(void) lsn = ((uint64) hi) << 32 | lo; /* check whether we still need it */ - if (lsn < cutoff || cutoff == InvalidXLogRecPtr) + if (lsn < cutoff || XLogRecPtrIsInvalid(cutoff)) { elog(DEBUG1, "removing snapbuild snapshot %s", path); -- 2.34.1
>From 02b68eec1227dd24a0b09f6a0771a47851ff593e Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:35:43 +0000 Subject: [PATCH v1 15/20] make use of XLogRecPtrIsInvalid in slot.c --- src/backend/replication/slot.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 100.0% src/backend/replication/ diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 1e9f4602c69..a1df3740851 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1270,15 +1270,15 @@ ReplicationSlotsComputeRequiredLSN(void) */ if (persistency == RS_PERSISTENT) { - if (last_saved_restart_lsn != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(last_saved_restart_lsn) && restart_lsn > last_saved_restart_lsn) { restart_lsn = last_saved_restart_lsn; } } - if (restart_lsn != InvalidXLogRecPtr && - (min_required == InvalidXLogRecPtr || + if (!XLogRecPtrIsInvalid(restart_lsn) && + (XLogRecPtrIsInvalid(min_required) || restart_lsn < min_required)) min_required = restart_lsn; } @@ -1350,17 +1350,17 @@ ReplicationSlotsComputeLogicalRestartLSN(void) */ if (persistency == RS_PERSISTENT) { - if (last_saved_restart_lsn != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(last_saved_restart_lsn) && restart_lsn > last_saved_restart_lsn) { restart_lsn = last_saved_restart_lsn; } } - if (restart_lsn == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(restart_lsn)) continue; - if (result == InvalidXLogRecPtr || + if (XLogRecPtrIsInvalid(result) || restart_lsn < result) result = restart_lsn; } @@ -1573,8 +1573,8 @@ ReplicationSlotReserveWal(void) ReplicationSlot *slot = MyReplicationSlot; Assert(slot != NULL); - Assert(slot->data.restart_lsn == InvalidXLogRecPtr); - Assert(slot->last_saved_restart_lsn == InvalidXLogRecPtr); + Assert(XLogRecPtrIsInvalid(slot->data.restart_lsn)); + Assert(XLogRecPtrIsInvalid(slot->last_saved_restart_lsn)); /* * The replication slot mechanism is used to prevent removal of required @@ -1755,7 +1755,7 @@ DetermineSlotInvalidationCause(uint32 possible_causes, ReplicationSlot *s, if (possible_causes & RS_INVAL_WAL_REMOVED) { - if (initial_restart_lsn != InvalidXLogRecPtr && + if (!XLogRecPtrIsInvalid(initial_restart_lsn) && initial_restart_lsn < oldestLSN) return RS_INVAL_WAL_REMOVED; } -- 2.34.1
>From adc5faeb2046c8a22ebd8d8833c8a46cb90cb5a2 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:37:29 +0000 Subject: [PATCH v1 16/20] make use of XLogRecPtrIsInvalid in slotfuncs.c --- src/backend/replication/slotfuncs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 100.0% src/backend/replication/ diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index b8f21153e7b..7a593a663e5 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -308,12 +308,12 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) else nulls[i++] = true; - if (slot_contents.data.restart_lsn != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(slot_contents.data.restart_lsn)) values[i++] = LSNGetDatum(slot_contents.data.restart_lsn); else nulls[i++] = true; - if (slot_contents.data.confirmed_flush != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(slot_contents.data.confirmed_flush)) values[i++] = LSNGetDatum(slot_contents.data.confirmed_flush); else nulls[i++] = true; @@ -467,7 +467,7 @@ pg_physical_replication_slot_advance(XLogRecPtr moveto) XLogRecPtr startlsn = MyReplicationSlot->data.restart_lsn; XLogRecPtr retlsn = startlsn; - Assert(moveto != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(moveto)); if (startlsn < moveto) { -- 2.34.1
>From 75f70794adf53a95d32893f909c041809e249bf8 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:39:26 +0000 Subject: [PATCH v1 17/20] make use of XLogRecPtrIsInvalid in walsender.c --- src/backend/replication/walsender.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 100.0% src/backend/replication/ diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 548eafa7a73..622bb35e8c7 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -2397,7 +2397,7 @@ PhysicalConfirmReceivedLocation(XLogRecPtr lsn) bool changed = false; ReplicationSlot *slot = MyReplicationSlot; - Assert(lsn != InvalidXLogRecPtr); + Assert(!XLogRecPtrIsInvalid(lsn)); SpinLockAcquire(&slot->mutex); if (slot->data.restart_lsn != lsn) { @@ -2519,7 +2519,7 @@ ProcessStandbyReplyMessage(void) /* * Advance our local xmin horizon when the client confirmed a flush. */ - if (MyReplicationSlot && flushPtr != InvalidXLogRecPtr) + if (MyReplicationSlot && !XLogRecPtrIsInvalid(flushPtr)) { if (SlotIsLogical(MyReplicationSlot)) LogicalConfirmReceivedLocation(flushPtr); @@ -3536,7 +3536,7 @@ XLogSendLogical(void) * If first time through in this session, initialize flushPtr. Otherwise, * we only need to update flushPtr if EndRecPtr is past it. */ - if (flushPtr == InvalidXLogRecPtr || + if (XLogRecPtrIsInvalid(flushPtr) || logical_decoding_ctx->reader->EndRecPtr >= flushPtr) { /* -- 2.34.1
>From 81f495d7c2739fe00e521b6bb191b8df4cf8ef4f Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:41:06 +0000 Subject: [PATCH v1 18/20] make use of XLogRecPtrIsInvalid in pg_receivewal.c --- src/bin/pg_basebackup/pg_receivewal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 100.0% src/bin/pg_basebackup/ diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index 289ca14dcfe..0cebdbca6c3 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -535,7 +535,7 @@ StreamLog(void) * Figure out where to start streaming. First scan the local directory. */ stream.startpos = FindStreamingStart(&stream.timeline); - if (stream.startpos == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(stream.startpos)) { /* * Try to get the starting point from the slot if any. This is @@ -556,14 +556,14 @@ StreamLog(void) * If it the starting point is still not known, use the current WAL * flush value as last resort. */ - if (stream.startpos == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(stream.startpos)) { stream.startpos = serverpos; stream.timeline = servertli; } } - Assert(stream.startpos != InvalidXLogRecPtr && + Assert(!XLogRecPtrIsInvalid(stream.startpos) && stream.timeline != 0); /* -- 2.34.1
>From 4c143cd83eba7a7c7de41c2037faa6c1c0e448be Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:43:24 +0000 Subject: [PATCH v1 19/20] make use of XLogRecPtrIsInvalid in pg_recvlogical.c --- src/bin/pg_basebackup/pg_recvlogical.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 100.0% src/bin/pg_basebackup/ diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 7a4d1a2d2ca..36184156f26 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -482,7 +482,7 @@ StreamLogicalLog(void) } replyRequested = copybuf[pos]; - if (endpos != InvalidXLogRecPtr && walEnd >= endpos) + if (!XLogRecPtrIsInvalid(endpos) && walEnd >= endpos) { /* * If there's nothing to read on the socket until a keepalive @@ -535,7 +535,7 @@ StreamLogicalLog(void) /* Extract WAL location for this block */ cur_record_lsn = fe_recvint64(©buf[1]); - if (endpos != InvalidXLogRecPtr && cur_record_lsn > endpos) + if (!XLogRecPtrIsInvalid(endpos) && cur_record_lsn > endpos) { /* * We've read past our endpoint, so prepare to go away being @@ -583,7 +583,7 @@ StreamLogicalLog(void) goto error; } - if (endpos != InvalidXLogRecPtr && cur_record_lsn == endpos) + if (!XLogRecPtrIsInvalid(endpos) && cur_record_lsn == endpos) { /* endpos was exactly the record we just processed, we're done */ if (!flushAndSendFeedback(conn, &now)) @@ -913,14 +913,14 @@ main(int argc, char **argv) exit(1); } - if (startpos != InvalidXLogRecPtr && (do_create_slot || do_drop_slot)) + if (!XLogRecPtrIsInvalid(startpos) && (do_create_slot || do_drop_slot)) { pg_log_error("cannot use --create-slot or --drop-slot together with --startpos"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } - if (endpos != InvalidXLogRecPtr && !do_start_slot) + if (!XLogRecPtrIsInvalid(endpos) && !do_start_slot) { pg_log_error("--endpos may only be specified with --start"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); -- 2.34.1
>From 23ca9d19dbb0584756f0cd7be9aa123dac40217b Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Tue, 28 Oct 2025 06:45:47 +0000 Subject: [PATCH v1 20/20] make use of XLogRecPtrIsInvalid in pg_waldump.c --- src/bin/pg_waldump/pg_waldump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 100.0% src/bin/pg_waldump/ diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 13d3ec2f5be..620ab2d5e44 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -393,7 +393,7 @@ WALDumpReadPage(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, int count = XLOG_BLCKSZ; WALReadError errinfo; - if (private->endptr != InvalidXLogRecPtr) + if (!XLogRecPtrIsInvalid(private->endptr)) { if (targetPagePtr + XLOG_BLCKSZ <= private->endptr) count = XLOG_BLCKSZ; @@ -1213,7 +1213,7 @@ main(int argc, char **argv) /* first find a valid recptr to start from */ first_record = XLogFindNextRecord(xlogreader_state, private.startptr); - if (first_record == InvalidXLogRecPtr) + if (XLogRecPtrIsInvalid(first_record)) pg_fatal("could not find a valid record after %X/%08X", LSN_FORMAT_ARGS(private.startptr)); -- 2.34.1
