Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 965D9B5D803 for ; Mon, 26 Sep 2011 13:26:55 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 33329-08 for ; Mon, 26 Sep 2011 16:26:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id DAC13B5D801 for ; Mon, 26 Sep 2011 13:26:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8QGQb1Y008245; Mon, 26 Sep 2011 12:26:37 -0400 (EDT) To: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) cc: pgsql-bugs@postgresql.org, Alvaro Herrera Subject: Re: BUG #6218: TRAP: FailedAssertion( "!(owner->nsnapshots == 0)", File: "resowner.c", Line: 365) In-reply-to: <20110926100653.4D3BC14A143@mail.netbsd.org> References: <5291.1316980809@sss.pgh.pa.us> <20110926100653.4D3BC14A143@mail.netbsd.org> Comments: In-reply-to yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) message dated "Mon, 26 Sep 2011 10:06:53 -0000" Date: Mon, 26 Sep 2011 12:26:37 -0400 Message-ID: <8244.1317054397@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/184 X-Sequence-Number: 31201 yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) writes: >> Maybe, but I'd still like to see a test case, because I can't reproduce >> any such problem by preparing ROLLBACK in an aborted transaction. > reading GetTransactionSnapshot, it seems that the problem happens > only with IsolationUsesXactSnapshot() true. Hmm. I'm inclined to think that this demonstrates a bug in snapshot management, not so much in plancache. We have plancache doing PushActiveSnapshot(GetTransactionSnapshot()); and then later PopActiveSnapshot(); and at this point surely it is not plancache's fault if there is any remaining refcount for the snapshot. There is, though, because GetTransactionSnapshot saved a refcount in TopTransactionResourceOwner. I think it's snapmgr.c's responsibility to make sure that that's cleaned up, and it's not doing so. The place where that refcount normally gets dropped is AtEarlyCommit_Snapshot, but that isn't going to be called at all in aborted-transaction cleanup. Worse, if we just transposed it over to be called in a place in AbortTransaction comparable to where it's called during commit, that still wouldn't fix the problem, because when the ROLLBACK happens, we've already aborted the transaction. I think that AtEarlyCommit_Snapshot is misdesigned, and that far from being done "early" in commit/abort, it needs to be done "late", like somewhere not very long before the ResourceOwnerDelete(TopTransactionResourceOwner) calls. There is no very good reason to think that someone might not ask for a snapshot during commit processing. Alvaro, do you happen to remember why this got designed as an "early" transaction shutdown action, rather than delaying it as long as possible? regards, tom lane