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 1pUqJE-000170-9h for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2023 14:41:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pUqJD-0003kt-3p for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2023 14:41:27 +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 1pUqJC-0003kk-1b for pgsql-hackers@lists.postgresql.org; Wed, 22 Feb 2023 14:41:26 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUqJ4-0003AX-VZ for pgsql-hackers@lists.postgresql.org; Wed, 22 Feb 2023 14:41:25 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 74B335C00A9; Wed, 22 Feb 2023 09:41:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 22 Feb 2023 09:41:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1677076875; x=1677163275; bh=A BfRBJnThf4k1OmQSIn73+1W9dnTiauaJCEQgyaBbiA=; b=JvEftKLuathIUfmrH XZygNQMZ4CMyKTOO7vPk5nIZwB8MVyxUr0w3AAHYv4KvmYJ8Yh1AmUiGOZ9sBbn3 WCujU4nYN7uV5qyQRFCT/WgQ/KIm8NBpGhlr0XQN/vw+GZZBXlIF6KKhoyG9ny35 ObCVuAaTG0vPrVIzozRm4omcm+/RXnyFLLfJspzFjzl7R/oGDIxWQeTIiStXAVAy lPRgFveJVKArP+q2q8xFrvJYyrmPK6dCnh+uT8reDKlsd1XpVjH7QoDUTwZcuHPq zEWPNVYoXNOrd4FfsRdbmdAWODtUx/t0frlUKGNyW1rT++3Ba7cUcV1EfRVByDdW 6BDDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudejledgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 Feb 2023 09:41:14 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6C9209C; Wed, 22 Feb 2023 15:41:12 +0100 (CET) Date: Wed, 22 Feb 2023 15:41:12 +0100 From: Alvaro Herrera To: Tomas Vondra Cc: PostgreSQL Hackers Subject: Re: LWLock deadlock in brinRevmapDesummarizeRange Message-ID: <20230222144112.3zepouym4dbznwcr@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <31fb6cc5-45f5-777b-cb8e-b9e00b530593@enterprisedb.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Feb-22, Tomas Vondra wrote: > > ... and in there, I wrote that we would first write the brin tuple in > > the regular page, unlock that, and then lock the revmap for the update, > > without holding lock on the data page. I don't remember why we do it > > differently now, but maybe the fix is just to release the regular page > > lock before locking the revmap page? One very important change is that > > in previous versions the revmap used a separate fork, and we had to > > introduce an "evacuation protocol" when we integrated the revmap into > > the main fork, which may have changed the locking considerations. > > What would happen if two processes built the summary concurrently? How > would they find the other tuple, so that we don't end up with two BRIN > tuples for the same range? Well, the revmap can only keep track of one tuple per range; if two processes build summary tuples, and each tries to insert its tuple in a regular page, that part may succeed; but then only one of them is going to successfully register the summary tuple in the revmap: when the other goes to do the same, it would find that a CTID is already present. ... Looking at the code (brinSetHeapBlockItemptr), I think what happens here is that the second process would overwrite the TID with its own. Not sure if it would work to see whether the item is empty and bail out if it's not. But in any case, it seems to me that the update of the regular page is pretty much independent of the update of the revmap. > > Another point: to desummarize a range, just unlinking the entry from > > revmap should suffice, from the POV of other index scanners. Maybe we > > can simplify the whole procedure to: lock revmap, remove entry, remember > > page number, unlock revmap; lock regular page, delete entry, unlock. > > Then there are no two locks held at the same time during desummarize. > > Perhaps, as long as it doesn't confuse anything else. Well, I don't have the details fresh in mind, but I think it shouldn't, because the only way to reach a regular tuple is coming from the revmap; and we reuse "items" (lines) in a regular page only when they are empty (so vacuuming should also be OK). > > This comes from v16: > > I don't follow - what do you mean by v16? I don't see anything like that > anywhere in the repository. I meant the minmax-proposal file in patch v16, the one that I linked to. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "You're _really_ hosed if the person doing the hiring doesn't understand relational systems: you end up with a whole raft of programmers, none of whom has had a Date with the clue stick." (Andrew Sullivan)