Consistently use the XLogRecPtrIsInvalid() macro

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Consistently use the XLogRecPtrIsInvalid() macro
Date: 2025-10-28 08:13:06
Message-ID: aQB7EvGqrbZXrMlg@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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_4mqbgiQXAGGO5nFYV3D8Q@mail.gmail.com

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-make-use-of-XLogRecPtrIsInvalid-in-rewriteheap.c.patch text/x-diff 1.2 KB
v1-0002-make-use-of-XLogRecPtrIsInvalid-in-twophase.c.patch text/x-diff 947 bytes
v1-0003-make-use-of-XLogRecPtrIsInvalid-in-xlog.c.patch text/x-diff 3.5 KB
v1-0004-make-use-of-XLogRecPtrIsInvalid-in-xloginsert.c.patch text/x-diff 1.2 KB
v1-0005-make-use-of-XLogRecPtrIsInvalid-in-xlogreader.c.patch text/x-diff 883 bytes
v1-0006-make-use-of-XLogRecPtrIsInvalid-in-xlogrecovery.c.patch text/x-diff 1.9 KB
v1-0007-make-use-of-XLogRecPtrIsInvalid-in-xlogutils.c.patch text/x-diff 2.2 KB
v1-0008-make-use-of-XLogRecPtrIsInvalid-in-pg_subscriptio.patch text/x-diff 1.5 KB
v1-0009-make-use-of-XLogRecPtrIsInvalid-in-logical.c.patch text/x-diff 5.0 KB
v1-0010-make-use-of-XLogRecPtrIsInvalid-in-logicalfuncs.c.patch text/x-diff 1.3 KB
v1-0011-make-use-of-XLogRecPtrIsInvalid-in-origin.c.patch text/x-diff 3.1 KB
v1-0012-make-use-of-XLogRecPtrIsInvalid-in-proto.c.patch text/x-diff 3.6 KB
v1-0013-make-use-of-XLogRecPtrIsInvalid-in-reorderbuffer..patch text/x-diff 5.5 KB
v1-0014-make-use-of-XLogRecPtrIsInvalid-in-snapbuild.c.patch text/x-diff 2.7 KB
v1-0015-make-use-of-XLogRecPtrIsInvalid-in-slot.c.patch text/x-diff 2.4 KB
v1-0016-make-use-of-XLogRecPtrIsInvalid-in-slotfuncs.c.patch text/x-diff 1.4 KB
v1-0017-make-use-of-XLogRecPtrIsInvalid-in-walsender.c.patch text/x-diff 1.5 KB
v1-0018-make-use-of-XLogRecPtrIsInvalid-in-pg_receivewal..patch text/x-diff 1.4 KB
v1-0019-make-use-of-XLogRecPtrIsInvalid-in-pg_recvlogical.patch text/x-diff 2.1 KB
v1-0020-make-use-of-XLogRecPtrIsInvalid-in-pg_waldump.c.patch text/x-diff 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2025-10-28 08:36:13 Re: C11: should we use char32_t for unicode code points?
Previous Message Arkady Skvorcov 2025-10-28 08:11:09 [PATCH] Implement dynamic predicate lock ratio limits