Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id F0A2A632496 for ; Mon, 19 Apr 2010 05:37:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 90614-01 for ; Mon, 19 Apr 2010 08:37:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og105.obsmtp.com (exprod7og105.obsmtp.com [64.18.2.163]) by mail.postgresql.org (Postfix) with SMTP id 997D66328AB for ; Mon, 19 Apr 2010 05:37:29 -0300 (ADT) Received: from source ([74.125.78.145]) by exprod7ob105.postini.com ([64.18.6.12]) with SMTP ID DSNKS8wWR1WXjuM1qxmIsQZz9X1bpKDwSDFw@postini.com; Mon, 19 Apr 2010 01:37:29 PDT Received: by ey-out-1920.google.com with SMTP id 4so249153eyg.30 for ; Mon, 19 Apr 2010 01:37:27 -0700 (PDT) Received: by 10.213.43.3 with SMTP id u3mr2525474ebe.98.1271666246743; Mon, 19 Apr 2010 01:37:26 -0700 (PDT) Received: from [192.168.1.117] (dsl-hkibrasgw2-ff67c300-165.dhcp.inet.fi [88.195.103.165]) by mx.google.com with ESMTPS id 13sm3552915ewy.13.2010.04.19.01.37.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 19 Apr 2010 01:37:26 -0700 (PDT) Message-ID: <4BCC1644.70008@enterprisedb.com> Date: Mon, 19 Apr 2010 11:37:24 +0300 From: Heikki Linnakangas Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 To: Simon Riggs CC: pgsql-hackers@postgresql.org Subject: Re: [COMMITTERS] pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop References: <20100418180608.16F067541D1@cvs.postgresql.org> <4BCC07F1.6040405@enterprisedb.com> <1271664332.8305.17430.camel@ebony> In-Reply-To: <1271664332.8305.17430.camel@ebony> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.999 tagged_above=-10 required=5 tests=AWL=-0.099, BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/796 X-Sequence-Number: 160908 Simon Riggs wrote: > On Mon, 2010-04-19 at 10:36 +0300, Heikki Linnakangas wrote: >> Simon Riggs wrote: >>> Log Message: >>> ----------- >>> Tune GetSnapshotData() during Hot Standby by avoiding loop >>> through normal backends. Makes code clearer also, since we >>> avoid various Assert()s. Performance of snapshots taken >>> during recovery no longer depends upon number of read-only >>> backends. >> I think there's a little race condition there. >> snapshot->takenDuringRecovery is set before acquiring ProcArrayLock, so >> it's possible that by the time we acquire the lock, we're no longer in >> recovery. So this can happen: >> >> 1. Backend A starts to take a snapshot, while we're still in recovery. >> takenDuringRecovery is assigned true. >> 2. Recovery ends, and a normal transaction X begins in backend B. >> 3. A skips scanning ProcArray because takenDuringRecovery is true. >> >> The snapshot doesn't include X, so any changes done in that transaction >> will not be visible to the snapshot while the transaction is still >> running, but will be after it commits. >> >> Of course, it's highly improbable for 2. to happen, but it's there. > > The order of events is as you say, though I don't see the problem. The > new xids will be beyond xmax and would be filtered out even if we did > scan the procs, so they will be treated as running, which they are. Xmax > will not have advanced since that relies on completed transactions, not > started ones. Good point. However, it is theoretically possible that yet another transaction starts and commits in that same window, bumping xmax. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com