Subject: Use XLogRecPtrIsValid() instead of negated XLogRecPtrIsInvalid

From: vignesh C <[email-masked]>
Date: Fri, 10 Apr 2026 11:41:35 +0530

Hi,

This small cleanup patch updates src/bin/pg_waldump/archive_waldump.c
to use the recently introduced XLogRecPtrIsValid() helper instead of
negating XLogRecPtrIsInvalid(). The current code uses double-negative
checks such as:
Assert(!XLogRecPtrIsInvalid(privateInfo->startptr));
if (!XLogRecPtrIsInvalid(privateInfo->endptr))

This patch changes them to:
Assert(XLogRecPtrIsValid(privateInfo->startptr));
if (XLogRecPtrIsValid(privateInfo->endptr))

This improves readability without changing behavior. The attached
patch has the changes for the same.

Regards,
Vignesh

---

From: Fujii Masao <[email-masked]>
Date: Fri, 10 Apr 2026 23:46:39 +0900

> patch has the changes for the same.

Commit a2b02293bc6 switched various places to use XLogRecPtrIsValid(),
but it looks like later commits accidentally introduced uses of
XLogRecPtrIsInvalid() again. So +1 for this change.

Also, that commit replaced direct comparisons with InvalidXLogRecPtr with
XLogRecPtrIsValid(). I noticed two such comparisons [1]. Should these be
updated as well?

Regards,

[1]
$ git grep -E "[=\!]= InvalidXLogRecPtr"
src/backend/commands/repack_worker.c:   Assert(ctx->reader->EndRecPtr
!= InvalidXLogRecPtr);
src/backend/replication/walreceiver.c:  applyPtr = (latestApplyPtr ==
InvalidXLogRecPtr) ?

-- 
Fujii Masao

---

From: vignesh C <[email-masked]>
Date: Mon, 13 Apr 2026 12:40:06 +0530

> XLogRecPtrIsValid(). I noticed two such comparisons [1]. Should these be

I felt these also should be updated, the attached v2 version patch
includes the changes for the same.

Regards,
Vignesh

---

From: Fujii Masao <[email-masked]>
Date: Thu, 16 Apr 2026 13:11:52 +0900

> includes the changes for the same.

Thanks for updating the patch!

-       applyPtr = (latestApplyPtr == InvalidXLogRecPtr) ?
+       applyPtr = (XLogRecPtrIsInvalid(latestApplyPtr)) ?

XLogRecPtrIsValid() should be used here, instead?

Regards,

-- 
Fujii Masao

---

From: Xiaopeng Wang <[email-masked]>
Date: Thu, 16 Apr 2026 13:27:13 +0800

> XLogRecPtrIsValid() should be used here, instead?

Yeah, I was about to raise the same comment, and Fujii-san beat me. I believe it should be XLogRecPtrIsValid().

Otherwise, the patch looks good to me.

Regards,
Xiaopeng Wang

---

From: vignesh C <[email-masked]>
Date: Thu, 16 Apr 2026 16:25:31 +0530

> XLogRecPtrIsValid() should be used here, instead?

Yes, that seems better, the attached v3 version patch has the changes
for the same.

Regards,
Vignesh

---

From: Amul Sul <[email-masked]>
Date: Thu, 16 Apr 2026 18:00:38 +0530

> > XLogRecPtrIsValid() should be used here, instead?

The outer parentheses do not seem to be needed, as
XLogRecPtrIsInvalid() already includes them.

Other than that, the v3 patch looks good to me.

Regards,
Amul

---

From: Fujii Masao <[email-masked]>
Date: Thu, 16 Apr 2026 23:06:25 +0900

> Other than that, the v3 patch looks good to me.

I've updated the patch based on Amul's suggestion and pushed it. Thanks!

Regards,

-- 
Fujii Masao

---

From: vignesh C <[email-masked]>
Date: Thu, 16 Apr 2026 19:42:07 +0530

> I've updated the patch based on Amul's suggestion and pushed it. Thanks!

Thanks for pushing the patch.

Regards,
Vignesh