Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id CC9A1633CA4 for ; Wed, 20 Jan 2010 07:59:56 -0400 (AST) 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 94984-06 for ; Wed, 20 Jan 2010 11:59:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail136036.authsmtp.net (outmail136036.authsmtp.net [62.13.136.36]) by mail.postgresql.org (Postfix) with ESMTP id BC0AF633A60 for ; Wed, 20 Jan 2010 07:59:45 -0400 (AST) Received: from mail-c187.authsmtp.com (mail-c187.authsmtp.com [62.13.128.33]) by punt3.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id o0KBxgjL019241; Wed, 20 Jan 2010 11:59:42 GMT Received: from [192.168.0.3] (88-110-172-79.dynamic.dsl.as9105.com [88.110.172.79]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id o0KBxeT9029261; Wed, 20 Jan 2010 11:59:41 GMT Subject: Re: Small locking bugs in hs From: Simon Riggs To: Andres Freund Cc: pgsql-hackers@postgresql.org, Robert Haas In-Reply-To: <201001200447.47382.andres@anarazel.de> References: <200912272012.32556.andres@anarazel.de> <603c8f071001071016h211ff0e2x41fea95835f74fb4@mail.gmail.com> <1263641555.26654.49468.camel@ebony> <201001200447.47382.andres@anarazel.de> Content-Type: text/plain Date: Wed, 20 Jan 2010 11:59:40 +0000 Message-Id: <1263988780.4043.2046.camel@ebony> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Content-Transfer-Encoding: 7bit X-Server-Quench: 4a9a6b9c-05bb-11df-ab46-001185d377ca X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZOTQEd DAteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFagVbZ1hf HGQLWlREUVx7XGp/ bwsfZQ1DY0tOQQRt UlZOS01XHAJ3AVJe BmVsGkwWfgVEcXx2 ZAhrV3ReEkArfBd7 EEcHCG0DNzV9aWFL Bl0JJQdSbQNKfx5N bwR8U3ReMCtlM3Bw LC8aFBMcBw5qYB9Q SwUJZVYVSkUKGDF0 TQ0NBn0uGwUFXE0A X-Authentic-SMTP: 61633235383639.1000:706/Kp X-AuthFastPath: 255 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.41 tagged_above=-10 required=5 tests=AWL=0.189, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/1960 X-Sequence-Number: 155181 On Wed, 2010-01-20 at 04:47 +0100, Andres Freund wrote: > On Saturday 16 January 2010 12:32:35 Simon Riggs wrote: > > > > No. As mentioned upthread, this is not a bug. > Could you also mention in a little bit more detail why not? When a cleanup record arrives without a latestRemovedXid we are forced to assume that the xid could be as late as latestCompletedXid. Regrettably we aren't certain which of the xids are still there since it is possible that earlier xids in KnownAssignedXids are actually FATAL errors that did not write abort records. So we need to conflict with all current snapshots whose xmin is less than latestCompletedXid to be safe. This can cause false positives in our assessment of which vxids conflict. By using exclusive lock we prevent new snapshots from being taken while we work out which snapshots to conflict with. This protects those new snapshots from also being included in our conflict list. After the lock is released, we allow snapshots again. It is possible that we arrive at a snapshot that is identical to one that we just decided we should conflict with. This a case of false positives, not an actual problem. There are two cases: (1) if we were correct in using latestCompletedXid then that means that all xids in the snapshot lower than that are FATAL errors, so not xids that ever commit. We can make no visibility errors if we allow such xids into the snapshot. (2) if we erred on the side of caution and in fact the latestRemovedXid should have been earlier than latestCompletedXid then we conflicted with a snapshot needlessly. Taking another identical snapshot is OK, because the earlier conflicted snapshot was a false positive. In either case, a snapshot taken after conflict assessment will still be valid and non-conflicting even if an identical snapshot that existed before conflict assessment was assessed as conflicting. If we allowed concurrent snapshots while we were deciding who to conflict with we would need to include all concurrent snapshotters in the conflict list as well. We'd have difficulty in working out exactly who that was, so it is happier for all concerned if we take an exclusive lock. It also means that users waiting for a snapshot is a good thing, since it is more likely that they will live longer after having waited. So its not a bug for us to use exclusive lock and is actually desirable. We could reduce false positives by having the master calculate the exact xmin each time it issues an XLOG_BTREE_DELETE record. That would introduce more contention since that happens during btree split operations, so might be counter productive. -- Simon Riggs www.2ndQuadrant.com