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 1nf29a-0000bi-HR for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 16:17:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nf29Z-0000kP-DH for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2022 16:17:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nf29Z-0000kG-29 for pgsql-hackers@lists.postgresql.org; Thu, 14 Apr 2022 16:17:05 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nf29S-0004Kk-Ew for pgsql-hackers@lists.postgresql.org; Thu, 14 Apr 2022 16:17:04 +0000 Received: by mail-lj1-x233.google.com with SMTP id h11so6685650ljb.2 for ; Thu, 14 Apr 2022 09:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=koCqlToQXoCriNXBK1HnoMmfj22db1HOMgqDhBbQFeo=; b=YDcG07AHgLqlBl2RtLRV6uWcup8JdEtc1JSlhgPR+AU9w4HGewuJTu9yLJCRGAkXF6 5A0MhyD7EoqXTKZe+9d37wtJSYzfQgMgnEt5geScbUBEZnS3+VF9GtHjm7IZmzXup3k4 YZxTUqTnofncagcGZcGU7Opeu62LjInMqr9aP76sMLUZD84auLCH3isxYL8JiFNh89r9 kt7ScN96Kih10Xho916gM4wZUOdfwCJJoy9vPb9KxSlI2mwxikl93WJlZeyEmI1riSZM 8vnV3TzZ+bEFdxQ+TRv9bdz2Pg1aE4c277paC+JkWrJQpF/XI5Oh9ipTZZCkxyui0onr dIUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=koCqlToQXoCriNXBK1HnoMmfj22db1HOMgqDhBbQFeo=; b=tDyROrIEZuDMZL+rIuJ4z7yFp+K0UTbpJJ/pplKhMWmUqEg9XLkh8G9IFk/NnBwqvt DgolEI5tuc4jHQ9h7ffNsdgv5UyVpgfGPo/sExCvgQwMSYIDElfeTd3d/kSjJ9XAiSYp xmz2laS4yPHvy2ITOeEXI3PRF8Oo19cg+HKcfREw5orHsQwHqx/WVcljGbIVui9whkxX r1Dv9h16BX44zDZLJ1eiO6i6/z4ZOA8LpObxjxGBJpeIe4xTgiuT1WqaNks0GsHzu5GI GA02IsPOT5WaIb5Vg+qhnMac/UTuxZFPVWxELGR68aKNBqiwdXVYEaOVrnuF2XK3giQq KuDA== X-Gm-Message-State: AOAM533jsc62hIeDoCT6qxZ/vUtwJjgcqcLdvcLAsGYPsZSVdIlXk+d2 i3+nePDXXJIi9ZmxXiPyWkzq4AFTXhmjHqD/QhU= X-Google-Smtp-Source: ABdhPJxPWATiHodx+JqMimdluHZ3ExeHQPQHKXxbLUHDA4Tc+XUP6D66us4Qw3o55Q1OaIigQa30C39zD567O8RfQso= X-Received: by 2002:a2e:93d5:0:b0:24b:5637:bbde with SMTP id p21-20020a2e93d5000000b0024b5637bbdemr1986523ljh.256.1649953016658; Thu, 14 Apr 2022 09:16:56 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <1484483.1649951206@sss.pgh.pa.us> From: Robert Haas Date: Thu, 14 Apr 2022 12:16:45 -0400 Message-ID: Subject: Re: TRAP: FailedAssertion("HaveRegisteredOrActiveSnapshot()", File: "toast_internals.c", Line: 670, PID: 19403) To: Tom Lane Cc: Andres Freund , Justin Pryzby , Kyotaro Horiguchi , Erik Rijkers , Matthias van de Meent , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Apr 14, 2022 at 11:46 AM Tom Lane wrote: > I don't think Andres had any intention of ignoring it indefinitely. > What he is doing is prioritizing it lower than several of the other > open items, an opinion I fully agree with. Well, my point is that, historically, relegating things to the older bugs section often means nothing happens, which I think would not be great in this case. However, I'll try to shut up about the procedural issues for the moment, since I seem to be in the minority. 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 == NULL; So, if there are 0 active snapshots we return false. And if there is 1 active snapshot then we return true if there's no catalog snapshot and otherwise false. So far so good. But if there are 2 or more registered snapshots then the pairing heap will be neither empty nor singular so it seems to me we will return false, which seems to me to be the wrong answer. I tried this: diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index a0be0c411a..4e8e26a362 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1646,9 +1646,10 @@ HaveRegisteredOrActiveSnapshot(void) * removed at any time due to invalidation processing. If explicitly * registered more than one snapshot has to be in RegisteredSnapshots. */ - if (pairingheap_is_empty(&RegisteredSnapshots) || - !pairingheap_is_singular(&RegisteredSnapshots)) + if (pairingheap_is_empty(&RegisteredSnapshots)) return false; + if (!pairingheap_is_singular(&RegisteredSnapshots)) + return true; return CatalogSnapshot == NULL; } I find that 'make check-world' passes with this change, which is disturbing, because it also passes without this change. That means we don't have any tests that reach HaveRegisteredOrActiveSnapshot() with more than one registered snapshot. Also, unless we have plans to use HaveRegisteredOrActiveSnapshot() in more places, I think we should consider revising the whole approach here. The way init_toast_snapshot() is coded, we basically have some code that tests for active and registered snapshots and finds the oldest one. We error out if there isn't one. And then we get to this assertion, which checks the same stuff a second time but with an additional check to see whether we ended up with the catalog snapshot. Wouldn't it make more sense if GetOldestSnapshot() just refused to return the catalog snapshot in the first place? -- Robert Haas EDB: http://www.enterprisedb.com