Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DC313B5DBEC for ; Wed, 29 Jun 2011 13:10:00 -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 01716-09 for ; Wed, 29 Jun 2011 16:09:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og109.obsmtp.com (exprod7og109.obsmtp.com [64.18.2.171]) by mail.postgresql.org (Postfix) with ESMTP id 76CD2B5DBEE for ; Wed, 29 Jun 2011 13:09:52 -0300 (ADT) Received: from mail-bw0-f50.google.com ([209.85.214.50]) (using TLSv1) by exprod7ob109.postini.com ([64.18.6.12]) with SMTP ID DSNKTgtOTy6CQye9Tw2WHrFT9rmO3PI2Sc80@postini.com; Wed, 29 Jun 2011 09:09:53 PDT Received: by bwb11 with SMTP id 11so1599624bwb.37 for ; Wed, 29 Jun 2011 09:09:50 -0700 (PDT) Received: by 10.204.130.19 with SMTP id q19mr983071bks.0.1309363790225; Wed, 29 Jun 2011 09:09:50 -0700 (PDT) Received: from [90.190.247.247] (247.247.190.90.dyn.estpak.ee [90.190.247.247]) by mx.google.com with ESMTPS id m6sm33076fac.3.2011.06.29.09.09.46 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Jun 2011 09:09:47 -0700 (PDT) Message-ID: <4E0B4E48.9030909@enterprisedb.com> Date: Wed, 29 Jun 2011 19:09:44 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.17) Gecko/20110606 Icedove/3.1.10 MIME-Version: 1.0 To: Jesper Pedersen CC: "pgsql-jdbc@postgresql.org" Subject: Re: Possible oversight in org.postgresql.xa.PGXAConnection.commitPrepared(Xid xid) References: <500446595.828372.1309301560262.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> <4E0AEFDB.30701@enterprisedb.com> <201106290904.58581.jesper.pedersen@jboss.org> In-Reply-To: <201106290904.58581.jesper.pedersen@jboss.org> Content-Type: multipart/mixed; boundary="------------020608060203080506000605" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/77 X-Sequence-Number: 22001 This is a multi-part message in MIME format. --------------020608060203080506000605 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit On 29.06.2011 16:04, Jesper Pedersen wrote: > Hey Heikki, > > On Wednesday, June 29, 2011 05:26:51 AM Heikki Linnakangas wrote: >> Attached patch implements that. I don't have a transaction manager >> environment for this at hand right now, so this is completely untested. >> Do you have a setup ready where you could test this? > > You forgot to update the actual exception with 'xaerrcode'. Oops. Here's a patch with that fixed. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com --------------020608060203080506000605 Content-Type: text/x-diff; name="xaer_rmerr-only-if-xact-does-not-exist-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xaer_rmerr-only-if-xact-does-not-exist-2.patch" ? xaer_rmerr-only-if-xact-does-not-exist-1.patch ? xaer_rmerr-only-if-xact-does-not-exist-2.patch Index: org/postgresql/util/PSQLState.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/util/PSQLState.java,v retrieving revision 1.14 diff -c -r1.14 PSQLState.java *** org/postgresql/util/PSQLState.java 31 Mar 2011 03:06:39 -0000 1.14 --- org/postgresql/util/PSQLState.java 29 Jun 2011 16:07:57 -0000 *************** *** 88,93 **** --- 88,94 ---- 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 -c -r1.17 PGXAConnection.java *** org/postgresql/xa/PGXAConnection.java 31 Mar 2011 06:25:42 -0000 1.17 --- org/postgresql/xa/PGXAConnection.java 29 Jun 2011 16:07:57 -0000 *************** *** 498,504 **** } catch (SQLException ex) { ! throw new PGXAException(GT.tr("Error committing prepared transaction"), ex, XAException.XAER_RMERR); } } --- 498,525 ---- } catch (SQLException ex) { ! // Per JTA spec, we should return XAER_RMERR only if the ! // prepared transaction has permanently failed and can never be ! // committed. In that case the fundamental contract of two-phase ! // commit that if a transaction has been prepared, it can ! // eventually be committed, has been broken. In all other cases, ! // where the commit fails but the transaction stays in prepared ! // state, we should return XA_RETRY. ! // ! // If the prepared transaction exists, but commit fails for any ! // other reason, we assume that the commit might succeed if ! // retried later. The server uses sqlstate UNDEFINED_OBJECT ! // (42704) if the prepared transcation doesn't exist, so we ! // check for that. The same sqlstate is used for all kinds of ! // missing object errors, but in case of COMMIT PREPARED, it's ! // reasonable to assume that if you get that error code, it's the ! // prepared transaction that's missing. ! int xaerrcode; ! if (ex.getSQLState().equals(PSQLState.UNDEFINED_OBJECT)) ! xaerrcode = XAException.XAER_RMERR; ! else ! xaerrcode = XAException.XA_RETRY; ! throw new PGXAException(GT.tr("Error committing prepared transaction"), ex, xaerrcode); } } --------------020608060203080506000605--