geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r727065 - in /geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager: RecoveryImpl.java TransactionImpl.java TransactionManagerImpl.java
Date Tue, 16 Dec 2008 15:22:23 GMT
Author: linsun
Date: Tue Dec 16 07:22:22 2008
New Revision: 727065

URL: http://svn.apache.org/viewvc?rev=727065&view=rev
Log:
GERONIMO-4461 GERONIMO-4466 improve heuristic exceptions during tx manager commit

Modified:
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
    geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java?rev=727065&r1=727064&r2=727065&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/RecoveryImpl.java
Tue Dec 16 07:22:22 2008
@@ -28,6 +28,8 @@
 import java.util.HashSet;
 import java.util.Collection;
 
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
 import javax.transaction.SystemException;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
@@ -247,7 +249,7 @@
             resourceNames.remove(name);
         }
 
-        public void preparedCommit() throws SystemException {
+        public void preparedCommit() throws HeuristicRollbackException, HeuristicMixedException,
SystemException {
             if (!resourceNames.isEmpty()) {
                 throw new SystemException("This tx does not have all resource managers online,
commit not allowed yet");
             }

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java?rev=727065&r1=727064&r2=727065&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionImpl.java
Tue Dec 16 07:22:22 2008
@@ -309,7 +309,20 @@
                     synchronized (this) {
                         status = Status.STATUS_ROLLEDBACK;
                     }
-                    throw (RollbackException) new RollbackException("Error during one-phase
commit").initCause(e);
+                    
+                    if (e.errorCode == XAException.XA_HEURRB) {
+                        manager.getCommitter().forget(manager.getBranchId());
+                        throw (HeuristicRollbackException) new HeuristicRollbackException("Error
during one-phase commit").initCause(e);
+                    } else if (e.errorCode == XAException.XA_HEURMIX) {
+                        manager.getCommitter().forget(manager.getBranchId());
+                        throw (HeuristicMixedException) new HeuristicMixedException("Error
during one-phase commit").initCause(e);
+                    } else if (e.errorCode == XAException.XA_HEURCOM) {
+                        // let's not throw an exception as the transaction has been committed
+                        log.info("Transaction has been heuristically committed");
+                        manager.getCommitter().forget(manager.getBranchId());
+                    } else {
+                        throw (RollbackException) new RollbackException("Error during one-phase
commit").initCause(e);
+                    }                    
                 }
             }
 
@@ -323,6 +336,8 @@
                 rollbackResources(resourceManagers);
                 throw new RollbackException("Unable to commit");
             }
+        } catch (XAException e) {
+           throw (SystemException) new SystemException("Error during commit").initCause(e);
         } finally {
             afterCompletion();
             synchronized (this) {
@@ -375,7 +390,7 @@
     }
 
     //used from XATerminator for commit phase of non-readonly remotely controlled tx.
-    void preparedCommit() throws SystemException {
+    void preparedCommit() throws HeuristicRollbackException, HeuristicMixedException, SystemException
{
         try {
             commitResources(resourceManagers);
         } finally {
@@ -586,6 +601,7 @@
                 }
             }
         }
+
         synchronized (this) {
             status = Status.STATUS_ROLLEDBACK;
         }
@@ -593,22 +609,43 @@
             throw cause;
         }
     }
-
-    private void commitResources(List rms) throws SystemException {
-        SystemException cause = null;
+    
+    private void commitResources(List rms) throws HeuristicRollbackException, HeuristicMixedException,
SystemException {
+        XAException cause = null;
+        boolean evercommit = false;
         synchronized (this) {
             status = Status.STATUS_COMMITTING;
         }
-        for (Iterator i = rms.iterator(); i.hasNext();) {
-            TransactionBranch manager = (TransactionBranch) i.next();
-            try {
-                manager.getCommitter().commit(manager.getBranchId(), false);
-            } catch (XAException e) {
-                log.error("Unexpected exception committing" + manager.getCommitter() + ";
continuing to commit other RMs", e);
-                if (cause == null) {
-                    cause = new SystemException(e.errorCode);
+        try {
+            for (Iterator i = rms.iterator(); i.hasNext();) {
+                TransactionBranch manager = (TransactionBranch) i.next();
+                try {
+                    manager.getCommitter().commit(manager.getBranchId(), false);
+                    evercommit = true;
+                } catch (XAException e) {
+                    log.error("Unexpected exception committing " + manager.getCommitter()
+ "; continuing to commit other RMs", e);
+                    
+                    if (e.errorCode == XAException.XA_HEURRB) {
+                        log.info("Transaction has been heuristically rolled back");
+                        cause = e;
+                        manager.getCommitter().forget(manager.getBranchId());
+                    } else if (e.errorCode == XAException.XA_HEURMIX) {
+                        log.info("Transaction has been heuristically committed and rolled
back");
+                        cause = e;
+                        evercommit = true;
+                        manager.getCommitter().forget(manager.getBranchId());
+                    } else if (e.errorCode == XAException.XA_HEURCOM) {
+                        // let's not throw an exception as the transaction has been committed
+                        log.info("Transaction has been heuristically committed");
+                        evercommit = true;
+                        manager.getCommitter().forget(manager.getBranchId());
+                    } else {
+                        cause = e;
+                    }
                 }
             }
+        } catch (XAException e) {
+            throw (SystemException) new SystemException("Error during two phase commit").initCause(e);
         }
         //if all resources were read only, we didn't write a prepare record.
         if (!rms.isEmpty()) {
@@ -623,7 +660,17 @@
             status = Status.STATUS_COMMITTED;
         }
         if (cause != null) {
-            throw cause;
+            if (cause.errorCode == XAException.XA_HEURRB && !evercommit) {
+                throw (HeuristicRollbackException) new HeuristicRollbackException("Error
during two phase commit").initCause(cause);
+            } else if (cause.errorCode == XAException.XA_HEURRB && evercommit) {
+                throw (HeuristicMixedException) new HeuristicMixedException("Error during
two phase commit").initCause(cause);
+            } else if (cause.errorCode == XAException.XA_HEURMIX) {
+                throw (HeuristicMixedException) new HeuristicMixedException("Error during
two phase commit").initCause(cause);
+            } else if (cause.errorCode == XAException.XA_HEURCOM) {
+                // ignore don't need to inform the tx originator
+            } else {
+                throw (SystemException) new SystemException("Error during two phase commit").initCause(cause);
+            } 
         }
     }
 

Modified: geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java?rev=727065&r1=727064&r2=727065&view=diff
==============================================================================
--- geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
(original)
+++ geronimo/components/txmanager/branches/geronimo-txmanager-parent-2.1/geronimo-transaction/src/main/java/org/apache/geronimo/transaction/manager/TransactionManagerImpl.java
Tue Dec 16 07:22:22 2008
@@ -294,6 +294,10 @@
         } else {
             try {
                 ((TransactionImpl) tx).preparedCommit();
+            } catch (HeuristicMixedException e) {
+                throw (XAException) new XAException().initCause(e);
+            } catch (HeuristicRollbackException e) {
+                throw (XAException) new XAException().initCause(e);
             } catch (SystemException e) {
                 throw (XAException) new XAException().initCause(e);
             }



Mime
View raw message