Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vDfSd-00DEPI-Bo for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 08:53:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vDfSc-00Bg7F-96 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 08:53:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vDfSb-00Bg75-VW for pgsql-hackers@lists.postgresql.org; Tue, 28 Oct 2025 08:53:45 +0000 Received: from mail-m16.yeah.net ([220.197.32.18]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vDfSU-004fVs-11 for pgsql-hackers@lists.postgresql.org; Tue, 28 Oct 2025 08:53:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From: Content-Type; bh=yD5K8Yu1qlXCt7Pogqtx2t4A8algQWfe+4VYoaUrdag=; b=gd1TRzfah5x3D0kGH6SuxZ7Ze+oCxgus6bcvs2lFjL6tyHXPKs2UKFuoqqnLPf rZE5KnwmLR+O+VsuTsgAzPibiAliUKO+BOzW4WKocP8luE4Nwm7/lt9wvLfzfKbX +4fRyFDL/4sJ61CV4h01T8a+D1AFqcHmebUgKZcpc3UM4= Received: from [192.168.10.60] (unknown []) by gzsmtp3 (Coremail) with SMTP id M88vCgDnbhqJhABpXzjOAA--.1555S2; Tue, 28 Oct 2025 16:53:30 +0800 (CST) Message-ID: <20213178-92cd-4ab9-9699-c68cd75bae58@yeah.net> Date: Tue, 28 Oct 2025 16:53:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Consistently use the XLogRecPtrIsInvalid() macro To: Bertrand Drouvot , pgsql-hackers@lists.postgresql.org References: Content-Language: en-US From: Quan Zongliang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: M88vCgDnbhqJhABpXzjOAA--.1555S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZF4kCFykuw1UGw17WFW3Wrg_yoW8WFW7pr W2kF43J3ykZ340vryUGr18X3Z5KFy8W343W39xK34j9ry5JFn2yr97Ka9FqF4UAryj9FW2 va4akrWkAa9rXaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j3eOdUUUUU= X-Originating-IP: [117.10.92.190] X-CM-SenderInfo: htxd06xrqjzxxdqjq5hhdkh0dhw/1tbiIQudwWkAhIvPGgAA3F List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/28/25 4:13 PM, Bertrand Drouvot wrote: > 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. > Agree. This patch has made the code style more consistent. And using such macros is also in line with the usual practice. Just like OidIsValid and TransactionIdIsValid. > 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, >