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 1k8ZUw-00009z-OQ for pgsql-committers@arkaria.postgresql.org; Thu, 20 Aug 2020 01:36:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k8ZUv-0001N9-Lp for pgsql-committers@arkaria.postgresql.org; Thu, 20 Aug 2020 01:36:09 +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 1k8ZUt-0001N2-Ux for pgsql-committers@lists.postgresql.org; Thu, 20 Aug 2020 01:36:09 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k8ZUo-0003Vm-Hm for pgsql-committers@lists.postgresql.org; Thu, 20 Aug 2020 01:36:06 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 7314F421; Wed, 19 Aug 2020 21:36:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 19 Aug 2020 21:36:00 -0400 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=fm2; bh=AwSiXGO3re9ltyPVK2G9Sjld2Yi IIw5EbzY5M6jPQQw=; b=OVPaueN2UIVR+1rRcKovbZE+6BvjryyOnWxIYoY5eNt jzxBtqipIKhpMHTwIiaMXNQ2czX0J30+3gVq9INXfjiwDQI3Bnx1vMdTx/O12q4X Rz4qXfJ0pGuh6Onojrv9AX7dHOwVwhLLdAslWugsSheTzYrfLE5hq6KYWDpB0TEM c6cv12VyhcchgqfyIVYsX3gSbDfK70KHLuGLRsCcLzIZfZHFUOBKZed7ZEo8ctU5 oru4qoVr+92MEo9Y/lzoztRqhHdW/FNzYK6CdiT6pOx5dGHUf9k0L7TICh2K1W0o oW5JGdzp92+eaIe9UCkeelUSZgycJxldRHGKhbOf0pg== 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=fm3; bh=AwSiXG O3re9ltyPVK2G9Sjld2YiIIw5EbzY5M6jPQQw=; b=i63/JT2XHB48QAf7aPaOJJ RLs37tOAt8i2b8ISy5pASJmQN31/6xTJdAnvD1ojQEqNg3XWH90gifhfwNXvg6Wg FHzeUpnMdgqserR8vqHGGrEdvtFncNe6Rm5EgJYfDhSWqZWK4aKmEcnPXXIsCNWQ 5Of6tz4a+QS+oJX+0TcAJX22KeqfZ1wvtoYdpNoe77rPvnjHGS6BBAQUl0enF9cT lvawmNaPEqpHkvT9DLiYHX/oJQBonJTnWHYJLTQr2wA9N7Rm1c1RJ4QFcGmOuG5n 5WqW49925yEI1bKOAm+taY7o8DZiVkBJp6TXLSePI7J3qeXy4raaHRl3A38LEBHw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtledgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghn rghrrgiivghlrdguvgeqnecuggftrfgrthhtvghrnhepudekhfekleeugeevteehleffff ejgeelueduleeffeeutdelffeujeffhfeuffdunecukfhppeeijedrudeitddrvddujedr vdehtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 9B2C23280059; Wed, 19 Aug 2020 21:35:59 -0400 (EDT) Date: Wed, 19 Aug 2020 18:35:58 -0700 From: Andres Freund To: Tom Lane Cc: David Rowley , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Fix race condition in snapshot caching when 2PC is used. Message-ID: <20200820013558.nrhx77cnlwpvff7m@alap3.anarazel.de> References: <1355915.1597794204@sss.pgh.pa.us> <20200818235152.4hxyb3hrvcm7pwom@alap3.anarazel.de> <1356510.1597794950@sss.pgh.pa.us> <20200819003713.cm2dg7o7knqnxdny@alap3.anarazel.de> <1366053.1597807864@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1366053.1597807864@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2020-08-18 23:31:04 -0400, Tom Lane wrote: > David Rowley writes: > >> On 2020-08-18 19:55:50 -0400, Tom Lane wrote: > >>> On Wed, 19 Aug 2020 at 12:37, Andres Freund wrote: > >>>> I'm inclined to just make ClearTransaction take an exclusive lock - the > >>>> rest of the 2PC operations are so heavyweight that I can't imagine > >>>> making a difference. When I tested the locking changes in > >>>> ProcArrayAdd()/Remove() the more heavyweight locking wasn't at all > >>>> visible. > > >>> I was wondering if it'd be sensible to convert that counter into an > >>> atomic variable. That's not real clear, but worth thinking about. > > > Couldn't it be done by creating two inline functions, one to call to > > atomically increment and the other to just increment? Can backup that > > the correct version of the function is being called with an > > Assert(LWLockHeldByMeInMode(ProcArrayLock, ...)); > > On reflection I agree with Andres' thought that just taking the lock > exclusively in ProcArrayClearTransaction is the right solution. > It's silly to imagine that a 2PC commit (plus all the other stuff that > needs to happen around that) is fast enough that that'll be a serious > performance hit. Keeping things simple for the other code paths is > a more useful goal. Cool, pushed that way. Greetings, Andres Freund