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 1r0PF8-005SYj-8B for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 16:47:58 +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 1r0PF6-00A6h4-9G for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 16:47:56 +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 1r0PF5-00A6gw-JI for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 16:47:55 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0PF2-004QUT-Le for pgsql-hackers@postgresql.org; Tue, 07 Nov 2023 16:47:54 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 309485F7B7; Tue, 7 Nov 2023 11:47:46 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snowman.net; s=dkim; t=1699375666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZYvvh4TZoIxKNQ0F+RIQSggGfXxnsjtjTsyH81ImXF8=; b=DsCJ22EA2zCyAwHeHCgyG1M68nwjIEteyU6r1U5hp9jLl2azT67ShH45D/iZHONAMEweV8 Qcb+EovapYInAYhhx4VOuvGIB8YGthK79d8651Ge8/uTHPU6MZUSlNELqI5xSvfk7Rcz5p tKRL1nS1Ovplj/TO6INfwwip85b5u/s= Date: Tue, 7 Nov 2023 11:47:46 -0500 From: Stephen Frost To: Nathan Bossart Cc: John Morris , Bharath Rupireddy , Andres Freund , Michael Paquier , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Atomic ops for unlogged LSN Message-ID: References: <20231026203433.GA1088329@nathanxps13> <20231102034006.GA85609@nathanxps13> <20231106203350.GA598180@nathanxps13> <20231107033558.GC729644@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="YlO15m++s4N5xoGd" Content-Disposition: inline In-Reply-To: <20231107033558.GC729644@nathanxps13> User-Agent: Mutt/2.1.4 (2021-12-11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --YlO15m++s4N5xoGd Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Nathan Bossart (nathandbossart@gmail.com) wrote: > On Tue, Nov 07, 2023 at 12:57:32AM +0000, John Morris wrote: > > I incorporated your suggestions and added a few more. The changes are > > mainly related to catching potential errors if some basic assumptions > > aren=E2=80=99t met. >=20 > Hm. Could we move that to a separate patch? We've lived without these > extra checks for a very long time, and I'm not aware of any related issue= s, > so I'm not sure it's worth the added complexity. And IMO it'd be better = to > keep it separate from the initial atomics conversion, anyway. I do see the value in adding in an Assert though I don't want to throw away the info about what the recent unlogged LSN was when we crash. As that basically boils down to a one-line addition, I don't think it really needs to be in a separate patch. > > I found the comment about cache coherency a bit confusing. We are deali= ng > > with a single address, so there should be no memory ordering or coheren= cy > > issues. (Did I misunderstand?) I see it more as a race condition. Rather > > than merely explaining why it shouldn=E2=80=99t happen, the new version= verifies > > the assumptions and throws an Assert() if something goes wrong. >=20 > I was thinking of the comment for pg_atomic_read_u32() that I cited earli= er > [0]. This comment also notes that pg_atomic_read_u32/64() has no barrier > semantics. My interpretation of that comment is that these functions > provide no guarantee that the value returned is the most up-to-date value. There seems to be some serious misunderstanding about what is happening here. The value written into the control file for unlogged LSN during normal operation does *not* need to be the most up-to-date value and talking about it as if it needs to be the absolutely most up-to-date and correct value is, if anything, adding to the confusion, not reducing confusion. The reason to write in anything other than a zero during these routine checkpoints for unlogged LSN is entirely for forensics purposes, not because we'll ever actually use the value- during crash recovery and backup/restore, we're going to reset the unlogged LSN counter anyway and we're going to throw away all of unlogged table contents across the entire system. We only care about the value of the unlogged LSN being correct during normal shutdown when we're writing out the shutdown checkpoint, but by that time everything else has been shut down and the value absolutely should not be changing. Thanks, Stephen --YlO15m++s4N5xoGd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwf6gbxKhD863zrx/7WyKOINHZFUFAmVKai8ACgkQ7WyKOINH ZFU1CBAAq0gTRTl+eBFUbjycUd73Ehlt8b8+8SirkCr8LBhGmj4ru+hPujZ+y/7N DgpriR/3TUnmbn8ZxocZc4liaV7LhrDgEzv0S2G+w9rAC62ptSAkmiE9qvzGGX/F cGLZKp4VR6Y6N6GNCrr35pGLiogEv7iqssR4qbyieulY8bqMj/p5Z4FIuuZJmnia NkAS3fjdKEB2EV0YlrQPrvB9vLPzuPFiN7nZPRltT+m4gQ6qvumQYe/HZ/VboasP 92RYu6M2tkFgZUkZhA381WaTvsOCAHQ4SbSucKbNby6zlaA2PvHVlG+s8Q2+EKS/ 137OlzEbc40t1bkTV95sDQ3BBuZYZi9awINoUCwzfChHVh44ateJx23ifNjD9Xe2 biMEwAmV8k+duskS5ebQoELBDApXznPse2AWi7fLvFOyjv7rrlawl+wbjyggTPIO jgGfXNfV9w5tRzdqnJYuSdbmQy2LhfN5ISkxou8dSsa9n+Gcltmex9IAbJIZ3Aen 4+L2MrFSTTH/KOlaGhc9UiFYpVefxv6LUFQuh6y8Iknwd4vqC9+Sc4lvT7q1Vqte BZ7nZANwyJr3VZHwYd4mu2CwNpZRId1BXqrN/dfKGV4ngF/wX2tDES5HEwzeldBG G4p2RYi8ZuAlj22+ZjcXJKpKxU4YE+95N43Z5c3rQy1g/rLAf0E= =GDDu -----END PGP SIGNATURE----- --YlO15m++s4N5xoGd--