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 1mkt9U-0003pq-9U for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Nov 2021 19:20:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mkt8w-00067j-Kp for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Nov 2021 19:20:22 +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 1mkt8u-00067a-Ll for pgsql-bugs@lists.postgresql.org; Wed, 10 Nov 2021 19:20:22 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkt8p-0007T5-QW for pgsql-bugs@lists.postgresql.org; Wed, 10 Nov 2021 19:20:19 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 565425C0251; Wed, 10 Nov 2021 14:20:12 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 10 Nov 2021 14:20:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=A0vtexqL/Q68GWQthppLDTvd2Ko PtJTywKb9y75d804=; b=DtRbxWN479whhfb5A5s/RGAyk82qdLh/4nHOzKF4HHM nzctENRgTKgEcIWnImATRFICACuqUIkoY13P2OXXZWk6KpfhgJmth5TIGg16emOv YVBBplg4JvckvYrqBE6hTR8RT18X2bwQEoAUUYWjJu4X/3QIYtGOG4noL8SvxjOr LgIFbeXgnKs6OxIV/Dybnu5Rzs7DwZe635HFxuRnFjOqXMedtHI1ojgrSM8TbS3r MEJnSRow2gzCkwPPaoTV2c2hDpOlU9e6PWr+snytl0JD6fl3QJ4323ZBFQOIE9K8 C0XpcCNiSx58RBYRCv0dbeQvOnKgTWjrs3D6vhssRwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=A0vtex qL/Q68GWQthppLDTvd2KoPtJTywKb9y75d804=; b=OOH06JYY/0Jn5sq07fXRxw nJTlgHczDrWfv5iVALbBv1HZK+1I7AesAuWo49Rxek6wUDthpDqSowAGMB4xrbci v+BvffJ+F3hPwooMZbV8jyJwH1zQ8GdJ69h9coG4qKkmqDhPgMLA7iVXJVW/obev cQ5Wo7Hd6lFSWxuIUpacanr3wHlxauUMIQvlBXpL1PcSiyav0FsJEfQNjzGcpvro R4vg1h38tbS1/dmNjR6+l9RoMwUw8TWiBMcttwxh4gIDNF+DYb/6Uo870K3gJTbz HKdzqGhjI0sRPCm2ANXrkUKXKeRHXuJRuyCJv1Ah9a3ph08XY2jaRIfhrTXFq0NQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudekgdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepudekhfekleeugeevteehleffffejgeelueduleeffeeutdelffeujeffhfeu ffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 10 Nov 2021 14:20:11 -0500 (EST) Date: Wed, 10 Nov 2021 11:20:10 -0800 From: Andres Freund To: Peter Geoghegan Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Lakhin , Matthias van de Meent , PostgreSQL mailing lists Subject: Re: BUG #17255: Server crashes in index_delete_sort_cmp() due to race condition with vacuum Message-ID: <20211110192010.ckvfzz352hsba5xf@alap3.anarazel.de> References: <17255-14c0ac58d0f9b583@postgresql.org> <20211029145532.kfwqwlrdekunwoa2@localhost> <20211030213948.3i3f7cieqxzhd7kq@alap3.anarazel.de> <20211031192051.e3r2uxft3bulymrr@localhost> <08c2445c-c3c9-ba45-18d3-6399707d8306@gmail.com> <20211108172852.pvsarxoxi54uatch@localhost> <20211109150216.fgfybn35mwnkeef3@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2021-11-09 15:31:37 -0800, Peter Geoghegan wrote: > I'm not sure why this seems to have become more of a problem following > the snapshot scalability work from Andres -- Alexander mentioned that > commit dc7420c2 looked like it was the source of the problem here, but > I can't see any reason why that might be true (even though I accept > that it might well *appear* to be true). I believe Andres has some > theory on that, but I don't know the details myself. AFAICT, this is a > live bug on all supported versions. We simply weren't being careful > enough about breaking the invariant that an LP_REDIRECT can only point > to a valid heap-only tuple. The really surprising thing here is that > it took this long for it to visibly break. The way this definitely breaks - I have been able to reproduce this in isolation - is when one tuple is processed twice by heap_prune_chain(), and the result of HeapTupleSatisfiesVacuum() changes from HEAPTUPLE_DELETE_IN_PROGRESS to DEAD. Consider a page like this: lp 1: redirect to lp2 lp 2: deleted by xid x, not yet committed and a sequence of events like this: 1) heap_prune_chain(rootlp = 1) 2) commit x 3) heap_prune_chain(rootlp = 2) 1) heap_prune_chain(rootlp = 1) will go to lp2, and see a HEAPTUPLE_DELETE_IN_PROGRESS and thus not do anything. 3) then could, with the snapshot scalability changes, get DEAD back from HTSV. Due to the "fuzzy" nature of the post-snapshot-scalability xid horizons, that is possible, because we can end up rechecking the boundary condition and seeing that now the horizon allows us to prune x / lp2. At that point we have a redirect tuple pointing into an unused slot. Which is "illegal", because something independent can be inserted into that slot. What made this hard to understand (and likely hard to hit) is that we don't recompute the xid horizons more than once per hot pruning ([1]). At first I concluded that a change from RECENTLY_DEAD to DEAD could thus not happen - and it doesn't: We go from HEAPTUPLE_DELETE_IN_PROGRESS to DEAD, which is possible because there was no horizon test for HEAPTUPLE_DELETE_IN_PROGRESS. Note that there are several paths < 14, that cause HTSV()'s answer to change for the same xid. E.g. when the transaction inserting a tuple version aborts, we go from HEAPTUPLE_INSERT_IN_PROGRESS to DEAD. But I haven't quite found a path to trigger problems with that, because there won't be redirects to a tuple version that is HEAPTUPLE_INSERT_IN_PROGRESS (but there can be redirects to a HEAPTUPLE_DELETE_IN_PROGRESS or RECENTLY_DEAD). I hit a crash once in 13 with a slightly evolved version of the test (many connections creating / dropping the partitions as in the original scenario, using :client_id to target different tables). It's possible that my instrumentation was the cause of that. Unfortunately it took quite a few hours to hit the problem in 13... Greetings, Andres Freund [1] it's a bit more complicated than that, we only recompute the horizon when a) we've not done it before in the current xact, b) RecentXmin changed during a snapshot computation. Recomputing the horizon is expensive-ish, so we don't want to do it constantly.