Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id D0ECF9FB559 for ; Wed, 1 Nov 2006 15:28:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 91175-03-2 for ; Wed, 1 Nov 2006 19:27:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id D94059FB5A6 for ; Wed, 1 Nov 2006 06:52:35 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id 30so1470916ugc for ; Wed, 01 Nov 2006 02:52:34 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=G7dxRqcOXxyGr3sbrI4qTeisaQq5tWsWSgyxYiHiE3hA5RlxZ/peaido3PP3pu4vBLjwGESQ5FgcZBF+yWUzbQQzHhGYfPU3ajdFOURNRaCfhpstY4wJoUyc+RersKryxpSWqY2kbXmZrEGI6C9AWANvlDf/DuMi33kiClTQndc= Received: by 10.66.224.19 with SMTP id w19mr7891640ugg; Wed, 01 Nov 2006 02:52:34 -0800 (PST) Received: from ?192.168.0.22? ( [62.232.55.118]) by mx.google.com with ESMTP id 24sm454924ugf.2006.11.01.02.52.33; Wed, 01 Nov 2006 02:52:33 -0800 (PST) Message-ID: <45487C70.6000604@enterprisedb.com> Date: Wed, 01 Nov 2006 10:52:32 +0000 From: Heikki Linnakangas User-Agent: Thunderbird 1.5.0.7 (X11/20060927) MIME-Version: 1.0 To: ludovic orban CC: pgsql-jdbc@postgresql.org Subject: Re: XA end then join fix for WebLogic References: <4547C128.40404@enterprisedb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/2 X-Sequence-Number: 16044 ludovic orban wrote: > Heikki, > > You wondered why Weblogic calls XAResource.start(TMJOIN) in this post: > http://archives.postgresql.org/pgsql-jdbc/2006-10/msg00011.php > > I'm going to try to explain you why that's happening in this email. > Please note that this explanation is solely based on my personal > observations of multiple transaction managers/app servers. I'm writing > this from the top of my head so I may have done a few mistakes. Thanks for the explanation. > The 'on statement creation' one, while more complex to write is more > flexible (end-user wise) and is generally more performant when used > with databases fully supporting transaction interleaving. This one > calls XAResource.start(TMNOFLAGS) when Connection.createStatement() or > prepareStatement() or prepareCall() is called and > XAResource.end(TMSUCCESS) when Connection.close() is called. Can you elaborate how 'on statement creation' is generally more performant? It seems to me that it leads to more start/end calls. At least in a straightforward implementation of start(TMJOIN), that means more round-trips to the database. Have you seen or done any performance tests on this? You might be able to get away with a slightly smaller connection pool, but that's with the cost of more "context switches" in the DBMS as a connection is repeatedly associated and disassociated with a transaction. That also makes me a bit worried about possible deadlocks. For example, imagine this simple example: 1 public void transactionalMethod() { 2 tm.begin(); 3 4 Connection c = getXADataSource().getConnection(); 5 c.createStatement().executeUpdate("UPDATE ..."); 6 c.close(); 7 8 tm.commit(); 9 } Now consider running that with a connection pool of just 1 connection: Thread A: runs begin + getConnection + update + close, down to line 7. The single Connection is now released back to the pool Thread B: runs lines 1-5, but the UPDATE blocks because of a lock held by transaction A. Thread A: Tries to commit, but blocks there's no connections available in the pool. -> deadlock. This is an extreme example, but the same scenario is possible with a larger connection pool, just harder to trigger. > For a good example of the increased flexibility you get with the 'on > statement creation' policy has been discussed by Dmitri Maximovich: > http://www.jroller.com/page/maximdim?entry=is_xa_transaction_support_broken > Basically only implementations using 'on statement creation' > enlistment policy can support this special case. Passing a Connection-object in a bean invocation just isn't sane, even if it was allowed by the spec. What if you pass a ResultSet-object, should it work in BeanB? What about updates to an updatable ResultSet? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com