Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAtDP-00039U-B4 for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Nov 2017 07:50:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eAtDN-00048f-Mx for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Nov 2017 07:50:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eAtDM-00047N-6U for pgsql-hackers@postgresql.org; Sat, 04 Nov 2017 07:50:00 +0000 Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eAtDE-00033B-9v for pgsql-hackers@postgresql.org; Sat, 04 Nov 2017 07:49:58 +0000 Received: by mail-pf0-x233.google.com with SMTP id t188so3880061pfd.10 for ; Sat, 04 Nov 2017 00:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zwaYVTBnY3N/onCkfjNm29mDJzaD1qPoycMWKvRQufg=; b=HVbzxevAdE7oBsv0DDL0K9M0WB1+S0pLgBKE7qtR4WxIEpV9y4aP+GuoYNyhuk62kP +AbZyfNPcY+vTrxcMkorbFndtxuU9f2jyjL+yKb0b179GwMaOTzw9hg/f75BWexsrn+D VamowtsVMErppmCSW+E5TEhixZaQwUnIEbLWE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zwaYVTBnY3N/onCkfjNm29mDJzaD1qPoycMWKvRQufg=; b=UiUF5x8lA7pQLZFhyEIflb2OKMJkdx2fQ1IDdg+AT7plRzQFTwOomI9yNIJVqxftN8 Hd8ua1Ixk3L2KQRMT6xTD72kPpSycUK/G2je/460jUc1PDZNKwmL6UYDqdL39buNm/Ob ktHz7bQJ6JNJA0xSPooDpyK9geFBvpe3NoDSU2/7aWDVOFapuebqxnHX1kPiZ0lUt6yL 30HBUFFbqhDJSSMFhzdsojovyAGhBfpcUJ99XcxJAbAtaylmBmNlMbfHZEMZlPpwPG84 rQvlSMUarAN5eVDzyHNoMMm51VY+OUzoNaBk2b3S2H6xspv6RFfjUw93VJJqSh1tI6OI NdaA== X-Gm-Message-State: AMCzsaWm9NESDu5mqhmHs4clMRD3lJmF+MC0HiIe36Tfz82EWGPMyH+g XChBmslsDiUy5rhEMfFowWxvUw== X-Google-Smtp-Source: ABhQp+Sq2126IrdNfoufn02BhMs3Gfb/qjukkN3uSNLhyJQafOXyQaue7qHBvY8yesKrV+OHXoISWw== X-Received: by 10.84.217.206 with SMTP id d14mr8968386plj.62.1509781790856; Sat, 04 Nov 2017 00:49:50 -0700 (PDT) Received: from rfd.leadboat.com (c-73-158-248-138.hsd1.ca.comcast.net. [73.158.248.138]) by smtp.gmail.com with ESMTPSA id 21sm13624966pfr.132.2017.11.04.00.49.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Nov 2017 00:49:49 -0700 (PDT) Date: Sat, 4 Nov 2017 00:49:46 -0700 From: Noah Misch To: Simon Riggs Cc: Robert Haas , Tom Lane , "pgsql-hackers@postgresql.org" Subject: Re: [COMMITTERS] pgsql: Account for catalog snapshot in PGXACT->xmin updates. Message-ID: <20171104074946.GB779790@rfd.leadboat.com> References: <22872.1481049369@sss.pgh.pa.us> <20170819195408.GA4025245@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wac7ysb48OaltWcw" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --wac7ysb48OaltWcw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Aug 21, 2017 at 07:41:52AM +0100, Simon Riggs wrote: > On 19 August 2017 at 20:54, Noah Misch wrote: > > On Tue, Dec 06, 2016 at 01:59:18PM -0500, Robert Haas wrote: > >> On Tue, Dec 6, 2016 at 1:36 PM, Tom Lane wrote: > >> > Robert Haas writes: > >> >> On Tue, Nov 15, 2016 at 3:55 PM, Tom Lane wrote: > >> >>> Account for catalog snapshot in PGXACT->xmin updates. > >> > > >> >> It seems to me that this makes it possible for > >> >> ThereAreNoPriorRegisteredSnapshots() to fail spuriously. The only > >> >> core code that calls that function is in copy.c, and apparently we > >> >> never reach that point with the catalog snapshot set. But that seems > >> >> fragile. > > > > I recently noticed this by way of the copy2 regression test failing, in 9.4 > > and later, under REPEATABLE READ and SERIALIZABLE. That failure started with > > $SUBJECT. > > Fair summary. ThereAreNoPriorRegisteredSnapshots() has functioned that way > > since an early submission[1], and I don't see that we ever discussed it > > explicitly. Adding Simon for his recollection. > > The intention, IIRC, was to allow the current snapshot (i.e. 1) but no > earlier (i.e. prior) snapshots (so not >=2) > > The name was chosen so it was (hopefully) clear what it did -- > ThereAreNoPriorRegisteredSnapshots I now understand the function name, so I added a comment but didn't rename it. I plan to use the attached patch after the minor release tags land. If there's significant support, I could instead push before the wrap. --wac7ysb48OaltWcw Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ThereAreNoPriorRegisteredSnapshots-CatalogSnapshot-v1.patch" commit d68eed7 (HEAD, ThereAreNoPriorRegisteredSnapshots-CatalogSnapshot) Author: Noah Misch AuthorDate: Sat Nov 4 00:08:04 2017 -0700 Commit: Noah Misch CommitDate: Sat Nov 4 00:33:37 2017 -0700 Ignore CatalogSnapshot when checking COPY FREEZE prerequisites. This restores the ability, essentially lost in commit ffaa44cb559db332baeee7d25dedd74a61974203, to use COPY FREEZE under REPEATABLE READ isolation. Back-patch to 9.4, like that commit. Discussion: https://postgr.es/m/CA+TgmoahWDm-7fperBxzU9uZ99LPMUmEpSXLTw9TmrOgzwnORw@mail.gmail.com diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 8006df3..1bdd492 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2394,13 +2394,25 @@ CopyFrom(CopyState cstate) /* * Optimize if new relfilenode was created in this subxact or one of its * committed children and we won't see those rows later as part of an - * earlier scan or command. This ensures that if this subtransaction - * aborts then the frozen rows won't be visible after xact cleanup. Note + * earlier scan or command. The subxact test ensures that if this subxact + * aborts then the frozen rows won't be visible after xact cleanup. Note * that the stronger test of exactly which subtransaction created it is - * crucial for correctness of this optimization. + * crucial for correctness of this optimization. The test for an earlier + * scan or command tolerates false negatives. FREEZE causes other sessions + * to see rows they would not see under MVCC, and a false negative merely + * spreads that anomaly to the current session. */ if (cstate->freeze) { + /* + * Tolerate one registration for the benefit of FirstXactSnapshot. + * Scan-bearing queries generally create at least two registrations, + * though relying on that is fragile, as is ignoring ActiveSnapshot. + * Clear CatalogSnapshot to avoid counting its registration. We'll + * still detect ongoing catalog scans, each of which separately + * registers the snapshot it uses. + */ + InvalidateCatalogSnapshot(); if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals()) ereport(ERROR, (errcode(ERRCODE_INVALID_TRANSACTION_STATE), diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 294ab70..addf87d 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1645,6 +1645,14 @@ DeleteAllExportedSnapshotFiles(void) FreeDir(s_dir); } +/* + * ThereAreNoPriorRegisteredSnapshots + * Is the registered snapshot count less than or equal to one? + * + * Don't use this to settle important decisions. While zero registrations and + * no ActiveSnapshot would confirm a certain idleness, the system makes no + * guarantees about the significance of one registered snapshot. + */ bool ThereAreNoPriorRegisteredSnapshots(void) { --wac7ysb48OaltWcw Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --wac7ysb48OaltWcw--