[exo-jcr-commits] exo-jcr SVN: r1461 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/session and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 18 07:32:09 EST 2010


Author: pnedonosko
Date: 2010-01-18 07:32:09 -0500 (Mon, 18 Jan 2010)
New Revision: 1461

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
Log:
EXOJCR-405 XASession commit reworked to support one- and two-phase behaviours, for one-phase the fail will cause a rollback immediately. Heuristic rollback is possible.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java	2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java	2010-01-18 12:32:09 UTC (rev 1461)
@@ -203,7 +203,7 @@
    {
       try
       {
-         txResourceManager.commit(this);
+         txResourceManager.commit(this, onePhase);
       }
       catch (TransactionException e)
       {
@@ -213,7 +213,7 @@
             LOG.debug("Commit Error. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this, e);
          }
 
-         throw new XASessionException(e.toString(), XAException.XA_RBOTHER);
+         throw new XASessionException(e.toString(), e.getErrorCode());
       }
 
       if (LOG.isDebugEnabled())
@@ -225,14 +225,28 @@
    /**
     * {@inheritDoc}
     */
+   public void start(Xid xid, int flags) throws XAException
+   {
+      txResourceManager.start(this);
+      startFlags = flags;
+
+      if (LOG.isDebugEnabled())
+      {
+         LOG.debug("Start. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    public void end(Xid xid, int flags) throws XAException
    {
+      startFlags = flags;
+
       if (LOG.isDebugEnabled())
       {
          LOG.debug("End. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
       }
-
-      startFlags = flags;
    }
 
    /**
@@ -338,20 +352,6 @@
    /**
     * {@inheritDoc}
     */
-   public void start(Xid xid, int flags) throws XAException
-   {
-      txResourceManager.start(this);
-      startFlags = flags;
-
-      if (LOG.isDebugEnabled())
-      {
-         LOG.debug("Start. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
    @Override
    public void logout()
    {

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java	2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java	2010-01-18 12:32:09 UTC (rev 1461)
@@ -298,8 +298,9 @@
 
          try
          {
-            storageDataManager.save(transactionLog);
+            TransactionChangesLog tl = transactionLog;
             transactionLog = null;
+            storageDataManager.save(tl);
          }
          catch (InvalidItemStateException e)
          {

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java	2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java	2010-01-18 12:32:09 UTC (rev 1461)
@@ -25,9 +25,13 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
+import javax.transaction.xa.XAException;
+
 /**
  * Created by The eXo Platform SAS.
  * <p/>
@@ -142,20 +146,62 @@
     * @throws TransactionException
     *           Transaction error
     */
-   synchronized public void commit(XASessionImpl userSession) throws TransactionException
+   synchronized public void commit(XASessionImpl userSession, boolean onePhase) throws TransactionException
    {
-      List<SoftReference<XASessionImpl>> joinedList = txResources.remove(userSession.getUserID());
+      List<SoftReference<XASessionImpl>> joinedList;
+      if (onePhase)
+      {
+         joinedList = txResources.remove(userSession.getUserID());
+      }
+      else
+      {
+         // TODO keep session on commit to be able to rollback all via XASessions(XAResource) and TM lifecycle
+         joinedList = txResources.get(userSession.getUserID());
+      }
+
       if (joinedList != null)
       {
-         for (SoftReference<XASessionImpl> sr : joinedList)
+         int i = 0;
+         try
          {
-            XASessionImpl xaSession = sr.get();
-            if (xaSession != null && xaSession.isLive())
+            while (i < joinedList.size())
             {
-               TransactionableDataManager txManager = xaSession.getTransientNodesManager().getTransactManager();
-               txManager.commit();
+               SoftReference<XASessionImpl> sr = joinedList.get(i++);
+               XASessionImpl xaSession = sr.get();
+               if (xaSession != null && xaSession.isLive())
+               {
+                  xaSession.getTransientNodesManager().getTransactManager().commit();
+               }
             }
          }
+         catch (TransactionException e)
+         {
+            boolean mixedCommit = i > 0;
+            if (onePhase)
+            {
+               // rollback now
+               for (; i < joinedList.size(); i++)
+               {
+                  SoftReference<XASessionImpl> sr = joinedList.get(i);
+                  XASessionImpl xaSession = sr.get();
+                  if (xaSession != null && xaSession.isLive())
+                  {
+                     xaSession.getTransientNodesManager().getTransactManager().rollback();
+                  }
+               }
+            }
+
+            if (mixedCommit)
+            {
+               // somethings were commited already
+               throw new TransactionException(XAException.XA_HEURMIX, e);
+            }
+            else
+            {
+               // all things were rolled back
+               throw new TransactionException(XAException.XA_HEURRB, e);
+            }
+         }
       }
    }
 

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java	2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java	2010-01-18 12:32:09 UTC (rev 1461)
@@ -21,6 +21,7 @@
 import org.exoplatform.services.jcr.JcrAPIBaseTest;
 import org.exoplatform.services.jcr.core.XASession;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.XASessionImpl;
 import org.exoplatform.services.transaction.TransactionService;
 
 import java.util.ArrayList;
@@ -238,8 +239,14 @@
       Session s1 =
          repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
 
+      Session s2 =
+         repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
+      
       Node tx1 = s1.getRootNode().getNode("pretx").addNode("tx1");
       s1.save();
+      
+      Node tx2 = s2.getRootNode().getNode("pretx").addNode("tx2");
+      s2.save();
 
       s0.save(); // save that parent of tx1 removed
 



More information about the exo-jcr-commits mailing list