pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Justin Bertram <jbertram@redhat.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
Date: Wed, 23 Dec 2009 10:35:57 +0200
Message-ID: <4B31D66D.8010809@enterprisedb.com> (raw)
In-Reply-To: <553112194.2096301261510459113.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
References: <553112194.2096301261510459113.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>

Justin Bertram wrote:
> I work with JBoss Transactions (JBossTS) and I noticed something recently in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) [1] when working with some transaction recovery scenarios after a database failure.  commitPrepared calls:
> 
>   throw new XAException(ex.toString());
> 
> The Java XA interface assumes that a thrown javax.transaction.xa.XAException [2] will contain one of the standard XA error codes [3] to identify exactly the nature of the error. Unfortunately Java allows an XAException to be constructed using a default constructor and a String constructor.  Using these constructors results in an errorCode value of 0 for the XAException which is not valid. 
> 
> In the latest PostgreSQL JDBC3 driver (8.4-701) this is what org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) does so the exception cannot be handled cleanly. JBossTS does not know what this error signifies so it has to assume the worst (i.e. that the resource is in an indeterminate state and it should not attempt to recover the transaction). Any reset of the database state will require manual intervention.
> 
> Can this be changed to throw an XAException with the appropriate XAER error code?

Yeah, seems like an oversight. Patch attached. We use XAER_RMERR error
code in similar places in all the other functions. Does that work for JBoss?

-- 
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

Attachments:

jdbc-commitprepared-xa-error-code-1.patch (text/x-diff, 646B) download 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); } }

view thread (12+ messages)  latest in thread

Message-ID: <4B31D66D.8010809@enterprisedb.com>
Permalink:  ../4B31D66D.8010809@enterprisedb.com/
Also on:    postgresql.org/message-id/4B31D66D.8010809@enterprisedb.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: heikki.linnakangas@enterprisedb.com, jbertram@redhat.com
  Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
  In-Reply-To: <4B31D66D.8010809@enterprisedb.com>
  References: <553112194.2096301261510459113.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> <4B31D66D.8010809@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox