Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nf4VL-0002eM-By for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 18:47:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nf4VI-0001u0-H4 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 18:47:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nf4VI-0001tn-7u for pgsql-hackers@lists.postgresql.org; Thu, 14 Apr 2022 18:47:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nf4VB-0006h8-Ky for pgsql-hackers@lists.postgresql.org; Thu, 14 Apr 2022 18:47:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 23EIlQbT1533666; Thu, 14 Apr 2022 14:47:27 -0400 From: Tom Lane To: Andres Freund cc: Robert Haas , Justin Pryzby , Kyotaro Horiguchi , Erik Rijkers , Matthias van de Meent , PostgreSQL Hackers Subject: Re: TRAP: FailedAssertion("HaveRegisteredOrActiveSnapshot()", File: "toast_internals.c", Line: 670, PID: 19403) In-reply-to: <20220414165425.pxn22hdlwdrcouh6@alap3.anarazel.de> References: <20220330.100617.1491348930290941094.horikyota.ntt@gmail.com> <20220330.114613.1177577626285014184.horikyota.ntt@gmail.com> <20220330.175824.936439875658680065.horikyota.ntt@gmail.com> <20220413202819.GR26620@telsasoft.com> <20220414003802.e37dgzkgbi5t7ha4@alap3.anarazel.de> <1471620.1649947373@sss.pgh.pa.us> <1484483.1649951206@sss.pgh.pa.us> <20220414165425.pxn22hdlwdrcouh6@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 14 Apr 2022 09:54:25 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1533664.1649962046.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 14 Apr 2022 14:47:26 -0400 Message-ID: <1533665.1649962046@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2022-04-14 12:16:45 -0400, Robert Haas wrote: >> I got curious and looked at the underlying problem here and I am >> wondering whether HaveRegisteredOrActiveSnapshot() is just buggy. It >> seems to me that the code is always going to return true if there are >> any active snapshots, and the rest of the function is intended to test >> whether there is a registered snapshot other than the catalog >> snapshot. But I don't think that's what this code does: >> = >> if (pairingheap_is_empty(&RegisteredSnapshots) || >> !pairingheap_is_singular(&RegisteredSnapshots)) >> return false; >> = >> return CatalogSnapshot =3D=3D NULL; > Certainly looks off... Yeah, this is broken. Whilst waiting around for a build on wrasse's host, I reproduced the problem shown in this thread, and here's what I see at the point of the exception: (gdb) p RegisteredSnapshots $5 =3D {ph_compare =3D 0x9a6000 , ph_arg =3D 0x0, = ph_root =3D 0xec3168 } (gdb) p *RegisteredSnapshots.ph_root $6 =3D {first_child =3D 0x2d85d70, next_sibling =3D 0x0, prev_or_parent =3D= 0x0} (gdb) p CatalogSnapshotData $7 =3D {snapshot_type =3D SNAPSHOT_MVCC, xmin =3D 52155, xmax =3D 52155, = xip =3D 0x2d855b0, xcnt =3D 0, subxip =3D 0x2de9130, subxcnt =3D 0, = suboverflowed =3D false, takenDuringRecovery =3D false, copied =3D false= , = curcid =3D 0, speculativeToken =3D 0, vistest =3D 0x0, active_count =3D = 0, = regd_count =3D 0, ph_node =3D {first_child =3D 0x2d85d70, next_sibling =3D= 0x0, = prev_or_parent =3D 0x0}, whenTaken =3D 0, lsn =3D 0, snapXactCompletio= nCount =3D 1} (gdb) p CatalogSnapshot = $8 =3D (Snapshot) 0xec3120 (gdb) p *(Snapshot) (0x2d85d70-72) $9 =3D {snapshot_type =3D SNAPSHOT_MVCC, xmin =3D 52155, xmax =3D 52155, x= ip =3D 0x0, = xcnt =3D 0, subxip =3D 0x0, subxcnt =3D 0, suboverflowed =3D false, = takenDuringRecovery =3D false, copied =3D true, curcid =3D 0, = speculativeToken =3D 0, vistest =3D 0x0, active_count =3D 0, regd_count = =3D 2, = ph_node =3D {first_child =3D 0x0, next_sibling =3D 0x0, = prev_or_parent =3D 0xec3168 }, whenTaken =3D 0= , = lsn =3D 0, snapXactCompletionCount =3D 0} (gdb) p ActiveSnapshot $10 =3D (ActiveSnapshotElt *) 0x0 So in fact there IS another registered snapshot, and HaveRegisteredOrActiveSnapshot is just lying. I think the correct test is more nearly what we have in InvalidateCatalogSnapshotConditionally: if (CatalogSnapshot && ActiveSnapshot =3D=3D NULL && pairingheap_is_singular(&RegisteredSnapshots)) // then the CatalogSnapshot is the only one. Ergo, this actually is a bug in 277692220. regards, tom lane