Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 5C0A7633883 for ; Mon, 19 Apr 2010 05:06:20 -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 85637-04 for ; Mon, 19 Apr 2010 08:06:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail148161.authsmtp.com (outmail148161.authsmtp.com [62.13.148.161]) by mail.postgresql.org (Postfix) with ESMTP id 1C2BE6323EB for ; Mon, 19 Apr 2010 05:05:39 -0300 (ADT) Received: from mail-c193.authsmtp.com (mail-c193.authsmtp.com [62.13.128.118]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id o3J85Ywf096519; Mon, 19 Apr 2010 09:05:34 +0100 (BST) Received: from [192.168.0.2] (88-110-156-192.dynamic.dsl.as9105.com [88.110.156.192]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id o3J85WTT070215; Mon, 19 Apr 2010 09:05:33 +0100 (BST) Subject: Re: [COMMITTERS] pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop From: Simon Riggs To: Heikki Linnakangas Cc: pgsql-hackers@postgresql.org In-Reply-To: <4BCC07F1.6040405@enterprisedb.com> References: <20100418180608.16F067541D1@cvs.postgresql.org> <4BCC07F1.6040405@enterprisedb.com> Content-Type: text/plain Date: Mon, 19 Apr 2010 09:05:32 +0100 Message-Id: <1271664332.8305.17430.camel@ebony> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Content-Transfer-Encoding: 7bit X-Server-Quench: 5411b08a-4b8a-11df-97bb-002264978518 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZOTQEd DAteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQxbbElD HGQLWlREUFR7WWZ/ aAkfZQ1DY0tOQQRv VlZIS1BNEQ1vHhxP WR1kWhwVE2FGf35y ZEMsWnBcWgp/cUd8 EE5cRHACN28xdWEe BBZFfgQGIh5Kfh1H bFR2U3sIYG1JBC9q VzwYGBUUHAljBR5u d0kVIkkLRRRDIiM6 SlgtECkUG0QdXCU0 MzAvNldcXQ4dL18z N1RpeVUEeyQOAwtS FVAvSCVIb1AfQCsn DAVVFUoZFyU1 X-Authentic-SMTP: 61633235383639.1014:706/Kp X-AuthFastPath: 255 X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.024 tagged_above=-10 required=5 tests=AWL=-0.124, BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/795 X-Sequence-Number: 160907 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. -- Simon Riggs www.2ndQuadrant.com