Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A335CB5D91F for ; Tue, 28 Jun 2011 20:36:23 -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 91892-02 for ; Tue, 28 Jun 2011 23:36:17 +0000 (UTC) X-Greylist: delayed 00:43:34.335589 by SQLgrey-1.7.6 Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.postgresql.org (Postfix) with ESMTP id F19CCB5D803 for ; Tue, 28 Jun 2011 20:36:16 -0300 (ADT) Received: from mail06.corp.redhat.com (zmail06.collab.prod.int.phx2.redhat.com [10.5.5.45]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5SMqeNM023955; Tue, 28 Jun 2011 18:52:40 -0400 Date: Tue, 28 Jun 2011 18:52:40 -0400 (EDT) From: Justin Bertram To: Heikki Linnakangas Cc: pgsql-jdbc@postgresql.org Message-ID: <500446595.828372.1309301560262.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> In-Reply-To: <4B31D66D.8010809@enterprisedb.com> Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_828371_1613960066.1309301560261" X-Originating-IP: [10.5.5.72] X-Mailer: Zimbra 6.0.9_GA_2686 (ZimbraWebClient - SAF3 (Linux)/6.0.9_GA_2686) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/75 X-Sequence-Number: 21999 ------=_Part_828371_1613960066.1309301560261 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I'm bringing this back up because, while the XAER_RMERR works in most cases= it fails in at least one. =20 Consider the scenario where the database is shutdown administratively durin= g org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid). The driver wil= l throw an XAException with an errorCode of XAER_RMERR back to the transact= ion manager. However, the pg_prepared_xacts table will still contain a row= for the transaction. =20 The method org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) is invo= ked by the transaction manager as part of its call to javax.transaction.xa.= XAResource.commit(..) [1]. This is the JTA mapping of the xa_commit() func= tion from the XA specification [2]. According to this document, a return o= f XAER_RMERR means: An error occurred in committing the work performed on behalf of the trans= action branch and the branch=E2=80=99s work has been rolled back. Note that retu= rning this error signals a catastrophic event to a transaction manager since other resourc= e managers may successfully commit their work on behalf of this branch. Thi= s error should be returned only when a resource manager concludes that it can nev= er commit the branch and that it cannot hold the branch=E2=80=99s resources = in a prepared state. Otherwise, [XA_RETRY] should be returned. However, since the pg_prepared_xacts table still contains a row for the tra= nsaction the XAER_RMERR is not accurate. A "catastrophic" failure has not = occurred. It would be possible for the transaction manager to recover this= transaction once the database is available again if XA_RETRY was returned = instead. I think it would be better if commitPrepared could differentiate between er= rors and return either XAER_RMERR or XA_RETRY as appropriate. Otherwise ju= st about any failure during commitPrepared will result in unrecoverable tra= nsactions and require manual intervention to clean up the pg_prepared_xacts= table. [1] http://download.oracle.com/javaee/5/api/javax/transaction/xa/XAResource= .html#commit(javax.transaction.xa.Xid, boolean) [2] http://pubs.opengroup.org/onlinepubs/009680699/toc.pdf ------=_Part_828371_1613960066.1309301560261 Content-Type: text/x-diff; charset=utf-8 Content-Transfer-Encoding: 7bit Index: org/postgresql/xa/PGXAConnection.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/xa/PGXAConnection.java,v retrieving revision 1.13 diff -u -r1.13 PGXAConnection.java --- org/postgresql/xa/PGXAConnection.java 14 Nov 2007 22:03:36 -0000 1.13 +++ org/postgresql/xa/PGXAConnection.java 23 Dec 2009 08:34:19 -0000 @@ -441,7 +441,7 @@ } catch (SQLException ex) { - throw new XAException(ex.toString()); + throw new PGXAException(GT.tr("Error committing prepared transaction"), ex, XAException.XAER_RMERR); } } ------=_Part_828371_1613960066.1309301560261--