XA end then join fix for WebLogic - Mailing list pgsql-jdbc

From Heikki Linnakangas
Subject XA end then join fix for WebLogic
Date
Msg-id 4520FC19.8070205@enterprisedb.com
Whole thread Raw
Responses Re: XA end then join fix for WebLogic
Re: XA end then join fix for WebLogic
List pgsql-jdbc
Jan de Visser ran into problems with our XA implementation earlier, and
traced the problem to the sequence of XADataSource method calls that
WebLogic performed. He fixed it with a simple patch that allows
start(.., TMJOIN) on a transaction that was ended earlier using the same
connection:

http://archives.postgresql.org/pgsql-jdbc/2005-12/msg00038.php

It puzzles me why WebLogic does that, but it seems valid and we should
support it, even though we can't support join in general.

Here's a more polished version of Jan's patch. I don't have WebLogic to
test this with, so I would appreciate if those that have access to
WebLogic could reproduce the original problem and confirm that this
patch fixes it.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
Index: org/postgresql/test/xa/XADataSourceTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/xa/XADataSourceTest.java,v
retrieving revision 1.6
diff -c -r1.6 XADataSourceTest.java
*** org/postgresql/test/xa/XADataSourceTest.java    26 Apr 2006 18:58:59 -0000    1.6
--- org/postgresql/test/xa/XADataSourceTest.java    2 Oct 2006 11:32:27 -0000
***************
*** 217,222 ****
--- 217,232 ----
          xaRes.rollback(xid);
      }

+     public void testEndThenJoin() throws XAException {
+         Xid xid = new CustomXid(5);
+
+         xaRes.start(xid, XAResource.TMNOFLAGS);
+         xaRes.end(xid, XAResource.TMSUCCESS);
+         xaRes.start(xid, XAResource.TMJOIN);
+         xaRes.end(xid, XAResource.TMSUCCESS);
+         xaRes.commit(xid, true);
+     }
+
      /* We don't support transaction interleaving.
      public void testInterleaving1() throws Exception {
       Xid xid1 = new CustomXid(1);
Index: org/postgresql/xa/PGXAConnection.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/xa/PGXAConnection.java,v
retrieving revision 1.7
diff -c -r1.7 PGXAConnection.java
*** org/postgresql/xa/PGXAConnection.java    26 Apr 2006 18:58:59 -0000    1.7
--- org/postgresql/xa/PGXAConnection.java    2 Oct 2006 11:32:28 -0000
***************
*** 79,86 ****
       * 4. the TM hasn't seen the xid before
       *
       * Implementation deficiency preconditions:
!      * 1. flags must be TMNOFLAGS
!      * 2. Previous transaction using the connection must be committed or prepared or rolled back
       *
       * Postconditions:
       * 1. Connection is associated with the transaction
--- 79,89 ----
       * 4. the TM hasn't seen the xid before
       *
       * Implementation deficiency preconditions:
!      * 1. TMRESUME not supported.
!      * 2. if flags is TMJOIN, we must be in ended state,
!      *    and xid must be the current transaction
!      * 3. unless flags is TMJOIN, previous transaction using the
!      *    connection must be committed or prepared or rolled back
       *
       * Postconditions:
       * 1. Connection is associated with the transaction
***************
*** 102,110 ****
          // We can't check precondition 4 easily, so we don't. Duplicate xid will be catched in prepare phase.

          // Check implementation deficiency preconditions
!         if (flags != TMNOFLAGS)
!             throw new PGXAException(GT.tr("suspend/resume and join not implemented"), XAException.XAER_RMERR);
!         if (state == STATE_ENDED)
              throw new PGXAException(GT.tr("Transaction interleaving not implemented"), XAException.XAER_RMERR);

          // Preconditions are met, Associate connection with the transaction
--- 105,122 ----
          // We can't check precondition 4 easily, so we don't. Duplicate xid will be catched in prepare phase.

          // Check implementation deficiency preconditions
!         if (flags == TMRESUME)
!             throw new PGXAException(GT.tr("suspend/resume not implemented"), XAException.XAER_RMERR);
!
!         // It's ok to join an ended transaction. WebLogic does that.
!         if (flags == TMJOIN)
!         {
!             if (state != STATE_ENDED)
!                 throw new PGXAException(GT.tr("Transaction interleaving not implemented"), XAException.XAER_RMERR);
!
!             if (!xid.equals(currentXid))
!                 throw new PGXAException(GT.tr("Transaction interleaving not implemented"), XAException.XAER_RMERR);
!         } else if(state == STATE_ENDED)
              throw new PGXAException(GT.tr("Transaction interleaving not implemented"), XAException.XAER_RMERR);

          // Preconditions are met, Associate connection with the transaction

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Bug extracting money value
Next
From: Jan de Visser
Date:
Subject: Re: XA end then join fix for WebLogic