Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 026F6B5DBC8 for ; Mon, 4 Jul 2011 19:02:56 -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 52418-07 for ; Mon, 4 Jul 2011 22:02:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail148109.authsmtp.co.uk (outmail148109.authsmtp.co.uk [62.13.148.109]) by mail.postgresql.org (Postfix) with ESMTP id 0ED82B5D80A for ; Mon, 4 Jul 2011 19:02:47 -0300 (ADT) Received: from mail-c193.authsmtp.com (mail-c193.authsmtp.com [62.13.128.118]) by punt12.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id p64M2loQ061416 for ; Mon, 4 Jul 2011 23:02:47 +0100 (BST) Received: from asuka.2ndquadrant.com (157-157-195-141.dsl.dynamic.simnet.is [157.157.195.141]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id p64M2dug037558 for ; Mon, 4 Jul 2011 23:02:41 +0100 (BST) To: PostgreSQL JDBC Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) References: <4E0AEFDB.30701@enterprisedb.com> <147817721.851047.1309377089469.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> <4E0C655E.8000307@enterprisedb.com> From: "Johann 'Myrkraverk' Oskarsson" Date: Mon, 04 Jul 2011 22:02:38 +0000 In-Reply-To: <4E0C655E.8000307@enterprisedb.com> (Heikki Linnakangas's message of "Thu, 30 Jun 2011 15:00:30 +0300") Message-ID: User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.19 (usg-unix-v) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Server-Quench: 57a3d767-a689-11e0-97bb-002264978518 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZXSwQT DCUsVilMUBgsKgdF BwNFJgxfNkIGTh1V d0RWJFF7KFoHWV5D ViVKB0oLEgo/WWdq EU8NcgddY0teXQZg UEpDRlEcFQBvHx0E AQAfWxxsdgFHZ3x1 Z0N9Xj4bWkAHdxI4 FU5XEmgDbSlkb2Ub HkVfJgAAdwVNY05D YlliVXJYYXgOYSgy WldrZWpvYWQAeHkM Ehc3IABacmQnNBUJ DygFBi4uF0kIDyIt IgY9K1EcAA4QNA01 K1RnQVUDLxAIBxZH GwddCWlhCGkobC0t Cw5RQU8ZFntWRiJZ AwEQOBJQCyZfVmpo BUcNWxADSksA X-Authentic-SMTP: 61633235383639.1014:706 X-AuthFastPath: 0 (Was 255) X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.89 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_TVD_MIME_NO_HEADERS=0.01 X-Spam-Level: X-Archive-Number: 201107/2 X-Sequence-Number: 22006 --=-=-= Heikki Linnakangas writes: > 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/ --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=postgresql-jdbc-ignore-undefined-object-on-xa-rollback.diff 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); } } --=-=-=--