Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id AA3E763387E for ; Mon, 19 Apr 2010 04:36:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 45797-07; Mon, 19 Apr 2010 07:36:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og115.obsmtp.com (exprod7og115.obsmtp.com [64.18.2.217]) by mail.postgresql.org (Postfix) with SMTP id 145F1633857; Mon, 19 Apr 2010 04:36:39 -0300 (ADT) Received: from source ([209.85.219.211]) by exprod7ob115.postini.com ([64.18.6.12]) with SMTP ID DSNKS8wIAC4TK1IsGnDJWkmV2xD0Ih9OZ0g+@postini.com; Mon, 19 Apr 2010 00:36:40 PDT Received: by ewy3 with SMTP id 3so1035744ewy.6 for ; Mon, 19 Apr 2010 00:36:19 -0700 (PDT) Received: by 10.213.107.78 with SMTP id a14mr2392347ebp.10.1271662579782; Mon, 19 Apr 2010 00:36:19 -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 14sm3545271ewy.2.2010.04.19.00.36.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 19 Apr 2010 00:36:19 -0700 (PDT) Message-ID: <4BCC07F1.6040405@enterprisedb.com> Date: Mon, 19 Apr 2010 10:36:17 +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-committers@postgresql.org Subject: Re: pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop References: <20100418180608.16F067541D1@cvs.postgresql.org> In-Reply-To: <20100418180608.16F067541D1@cvs.postgresql.org> 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.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/166 X-Sequence-Number: 40571 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. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com