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 1vDi4I-00Dzhr-Cb for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 11:40:49 +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 1vDi4F-00CPiL-3T for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 11:40:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vDi4E-00CPiD-QO for pgsql-hackers@lists.postgresql.org; Tue, 28 Oct 2025 11:40:45 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vDi4A-004CJ4-2t for pgsql-hackers@lists.postgresql.org; Tue, 28 Oct 2025 11:40:44 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4cwpMy2DNPz49QCD; Tue, 28 Oct 2025 13:40:30 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1761651631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=79W4LjBWWz/jYsAqDWGwy8nC3Ybr2zsuP5SrUJLMLEY=; b=tVbFMfh5V6+9OxctmPN4c8FHwBMZceQIalHiUZ1QDVRWmRiZoRBMoAIUkrL3ceMm+ZX2ni hCb1B7UdclMrXYsOxpOyb2/duKY8Q5mHOWuICVPlyk1IObnz+mWcl3v8znxUenx8SSlI+/ WNsrCR3eR+onIZUF0NMqxzHj+OxLxnbRu/G0fzcIlQVy4xeey/LWr9R1GvCHtZGKY0Pn8d VcbCV8m60Yo3hNS6vrJlwlyUOlwqgzF2am3peUClXC8DYKfw6L26qsggo3jXgpAHZfwcF4 zLnvdsaO9eCDOHGCyH6liGQNrmFvarFM1wn3XSElzS32kC5iRPlcy6Y58r6GgA== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1761651631; a=rsa-sha256; cv=none; b=WB2A5KWeNQVB/nD65qKiBqWsy0LxZmgkMb8UCCwWiFg8pJvUfIzNc1DzeFHPvGZK5KrgJk 5puKw9qaJdtA40UddTqGdtWSMdrfYjihhvJyHY3xl9epqp/IruO8cu5FeSAwhhr7eoarWH W69WZTWz7rijq0N+bkdDfz6tSyOejXJEpzmsKYwipJNTAP5e8TQKRYXWF31WmXwms9c+Ar 8vdtKUzBC+18tk8tLVaDesE9eDJK41QLToxqrcTmW9oXXoA6KlOEqhzmXEMULPDa4uGpNg d1c0PjXSfhiimrqDYWVrfO5TRxYPG+vQGjFFgc6jO3I9sAsGpoRItgRqkPappQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1761651631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=79W4LjBWWz/jYsAqDWGwy8nC3Ybr2zsuP5SrUJLMLEY=; b=OfIBlLPO05z8AGptDkFtxSOFsT4k2fTuu/k/dxKjJmjjUgHH7uHus5sdEgvh713UNhyawk JQ7P7SY8DjijPfpxc278066s1gB4u4pCdE9E81n7BSpYYt1w/huXEDTGrbK3jzRL1jpDN6 4nfuKmhkNT0sVqQRuK2/4x77NGGiVe/Vd5wbv/BtqHMuSHW0HJETzMbsh7LCjKFeh5ymE/ 07qnFwv2m//YqHcMtkqQD1OswZw/JlWzjZQHMv8AgF3uqLOXUC4Mg4e9baUrsjUMc8hFej uv675E1iTDftSJZ9daPM2aRTREpCG95jwiD1cCyTrrLgSWTsB2un3XdsGOk8Jw== Message-ID: Date: Tue, 28 Oct 2025 13:40:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Consistently use the XLogRecPtrIsInvalid() macro To: Quan Zongliang , Bertrand Drouvot , pgsql-hackers@lists.postgresql.org References: <20213178-92cd-4ab9-9699-c68cd75bae58@yeah.net> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <20213178-92cd-4ab9-9699-c68cd75bae58@yeah.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 28/10/2025 10:53, Quan Zongliang wrote: > On 10/28/25 4:13 PM, Bertrand Drouvot wrote: >> While working on refactoring some code in [1], one of the changes was: >> >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (initial_restart_lsn !=3D Inv= alidXLogRecPtr && >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 initial_= restart_lsn < oldestLSN) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 XLogRecPtr=C2=A0 restart_lsn =3D= s->data.restart_lsn; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (restart_lsn !=3D InvalidXLog= RecPtr && >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 restart_= lsn < oldestLSN) >> >> Sawada-san suggested to use the XLogRecPtrIsInvalid() macro here. >> >> But this !=3D InvalidXLogRecPtr check was existing code, so why not=20 >> consistently use XLogRecPtrIsInvalid() where we check equality >> against InvalidXLogRecPtr? >>=20 >> At the time the current XLogRecPtrIsInvalid() has been introduced=20 >> (0ab9d1c4b316) all the InvalidXLogRecPtr equality checks were done >> using XLogRecPtrIsInvalid(). >>=20 >> But since, it has changed: I looked at it and this is not the case=20 >> anymore in 20 files. >>=20 >> PFA, patches to $SUBJECT. To ease the review, I created one patch >> per modified file. >>=20 >> I suspect the same approach could be applied to some other macros=20 >> too. Let's start with XLogRecPtrIsInvalid() first. >=20 > Agree. This patch has made the code style more consistent. And using=20 > such macros is also in line with the usual practice. Just like=20 > OidIsValid and TransactionIdIsValid. Back in the day, XLogRecPtrIsInvalid() was needed because XLogRecPtr was=20 a struct. 'x =3D=3D InvalidXLogRecPtr' simply did not work. I don't see m= uch=20 need for it nowadays. In fact I wonder if we should go in the other=20 direction and replace XLogRecPtrIsInvalid(x) calls with 'x =3D=3D=20 InvalidXLogRecPtr'. It's also a bit cumbersome that we have XLogRecPtrIsInvalid() rather=20 than XLogRecPtrIsValid(). That's inconsistent with OidIsValid and=20 TransactionIdInValid, and it leads to an awkward double negative 'if=20 (!XLogRecPtrIsInvalid(x))' if you want to check that 'x' is valid. Overall I'm inclined to do nothing. But if anything, perhaps introduce=20 XLogRecPtrIsValid(x) and switch to that, or replace=20 XLogRecPtrIsInvalid(x) calls with 'x =3D=3D InvalidXLogRecPtr' - Heikki