From: Justin Bertram <jbertram@redhat.com>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
Date: Tue, 28 Jun 2011 18:52:40 -0400 (EDT)
Message-ID: <500446595.828372.1309301560262.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <4B31D66D.8010809@enterprisedb.com>
I'm bringing this back up because, while the XAER_RMERR works in most cases it fails in at least one.
Consider the scenario where the database is shutdown administratively during org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid). The driver will throw an XAException with an errorCode of XAER_RMERR back to the transaction manager. However, the pg_prepared_xacts table will still contain a row for the transaction.
The method org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) is invoked 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() function from the XA specification [2]. According to this document, a return of XAER_RMERR means:
An error occurred in committing the work performed on behalf of the transaction
branch and the branch’s work has been rolled back. Note that returning this error
signals a catastrophic event to a transaction manager since other resource
managers may successfully commit their work on behalf of this branch. This error
should be returned only when a resource manager concludes that it can never
commit the branch and that it cannot hold the branch’s resources in a prepared
state. Otherwise, [XA_RETRY] should be returned.
However, since the pg_prepared_xacts table still contains a row for the transaction 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 errors and return either XAER_RMERR or XA_RETRY as appropriate. Otherwise just about any failure during commitPrepared will result in unrecoverable transactions 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.transactio..., boolean)
[2] http://pubs.opengroup.org/onlinepubs/009680699/toc.pdf
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: jbertram@redhat.com, heikki.linnakangas@enterprisedb.com
Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
In-Reply-To: <500446595.828372.1309301560262.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
References: <4B31D66D.8010809@enterprisedb.com> <500446595.828372.1309301560262.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.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