From: Johann 'Myrkraverk' Oskarsson <johann@2ndquadrant.com>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
Date: Mon, 04 Jul 2011 22:02:38 +0000
Message-ID: <x6hb713ds1.fsf@2ndquadrant.com> (raw)
In-Reply-To: <4E0C655E.8000307@enterprisedb.com>
References: <4E0AEFDB.30701@enterprisedb.com>
<147817721.851047.1309377089469.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
<BANLkTinLfz4fa1sOFjiNXapjG_zU76HeYg@mail.gmail.com>
<4E0C655E.8000307@enterprisedb.com>
> Well, if the transaction has been rolled back, it's clearly not in
> prepared state anymore, so XAER_RMERR seems appropriate and the TM
> shouldn't get upset about that. However, the situation is more
> ambiguous if the TM issues COMMIT PREPARED and the connection is
> broken before receiving a reply. It will retry, and if the the
> COMMIT succeeded the first time, the TM will get XAER_RMERR on the
> second call. That's more serious.
There is no reason to return an error on rollback if the transaction
is unknown. If the DBMS server does not remember the transaction the
transaction manager can assume it has already been rolled back. That
is why it is appropriate to silently ignore 42704 or rollback. The
following patch does this.
This patch fixes a failure in a testsuite from Atomikos.
>
> I believe some (all?) other databases have yet another transaction
> state to handle that. After committing a transaction, the database
> still remembers the transaction ID and the fact that it was
> successfully committed. If the TM doesn't receive a reply to commit,
> it can reconnect and check the status to see if the commit
> succeeded. The transaction is forgotten about only after the TM
> sends another 'forget' command. Maybe we need to implement that in
> PostgreSQL, too.
Yes, this is needed for heuristics. That is, if a transaction manager
goes down and a system administrator commits the transaction before it
comes up again the server should not report `Undefined Object' but an
error on the lines of `Transaction Already Committed.' This is a
feature for the server and there is nothing[*] in the JDBC driver we
can do to implement this.
[*] Nothing is a strong word, it is always possible to implement a way
to store the Xids in a table. The driver should not do that without
some sort of confirmation from the application though.
--
Johann Oskarsson http://www.2ndquadrant.com/ |[]
PostgreSQL Development, 24x7 Support, Training and Services --+--
|
Blog: http://my.opera.com/myrkraverk/blog/Attachments:postgresql-jdbc-ignore-undefined-object-on-xa-rollback.diff (text/x-patch, 1.6K) download
Index: org/postgresql/util/PSQLState.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/util/PSQLState.java,v
retrieving revision 1.14
diff -u -r1.14 PSQLState.java
--- org/postgresql/util/PSQLState.java 31 Mar 2011 03:06:39 -0000 1.14+++ org/postgresql/util/PSQLState.java 4 Jul 2011 21:38:33 -0000@@ -88,6 +88,7 @@
public final static PSQLState SYNTAX_ERROR = new PSQLState("42601");
public final static PSQLState UNDEFINED_COLUMN = new PSQLState("42703");
+ public final static PSQLState UNDEFINED_OBJECT = new PSQLState("42704");
public final static PSQLState WRONG_OBJECT_TYPE = new PSQLState("42809");
public final static PSQLState NUMERIC_CONSTANT_OUT_OF_RANGE = new PSQLState("42820");
public final static PSQLState DATA_TYPE_MISMATCH = new PSQLState("42821");
Index: org/postgresql/xa/PGXAConnection.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/xa/PGXAConnection.java,v
retrieving revision 1.17
diff -u -r1.17 PGXAConnection.java
--- org/postgresql/xa/PGXAConnection.java 31 Mar 2011 06:25:42 -0000 1.17+++ org/postgresql/xa/PGXAConnection.java 4 Jul 2011 21:38:34 -0000@@ -407,7 +407,8 @@
}
catch (SQLException ex)
{
- throw new PGXAException(GT.tr("Error rolling back prepared transaction"), ex, XAException.XAER_RMERR);+ if (!ex.getSQLState().equals(PSQLState.UNDEFINED_OBJECT))+ throw new PGXAException(GT.tr("Error rolling back prepared transaction"), ex, XAException.XAER_RMERR);
}
}
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: johann@2ndquadrant.com
Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid)
In-Reply-To: <x6hb713ds1.fsf@2ndquadrant.com>
References: <4E0AEFDB.30701@enterprisedb.com> <147817721.851047.1309377089469.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> <BANLkTinLfz4fa1sOFjiNXapjG_zU76HeYg@mail.gmail.com> <4E0C655E.8000307@enterprisedb.com> <x6hb713ds1.fsf@2ndquadrant.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