[jboss-svn-commits] JBL Code SVN: r37758 - labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 1 05:23:47 EST 2011


Author: raggz
Date: 2011-12-01 05:23:47 -0500 (Thu, 01 Dec 2011)
New Revision: 37758

Modified:
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java
   labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/XARecoveryModule.java
Log:
Back port JBTM-924. Second attempt.


Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java	2011-12-01 10:05:07 UTC (rev 37757)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java	2011-12-01 10:23:47 UTC (rev 37758)
@@ -41,7 +41,8 @@
 
     public RecoveryXids (XAResource xares)
     {
-	_xares = xares;
+    	_xares = xares;
+        _lastValidated = System.currentTimeMillis();
     }
 
     public boolean equals (Object obj)
@@ -135,6 +136,14 @@
         return _whenFirstSeen.containsKey(xidImple);
     }
 
+    public boolean isStale() {
+        long now = System.currentTimeMillis();
+        long threshold = _lastValidated+(2*safetyIntervalMillis);
+        long diff = now - threshold;
+        boolean result = diff > 0;
+        return result;
+    }
+
     /**
      * If supplied xids contains any values seen on prev scans, replace the existing
      * XAResource with the supplied one and return true. Otherwise, return false.
@@ -145,15 +154,22 @@
      */
     public boolean updateIfEquivalentRM(XAResource xaResource, Xid[] xids)
     {
-        if(xids == null || xids.length == 0) {
-            return false;
+        if(xids != null && xids.length > 0) {
+            for(int i = 0; i < xids.length; i++) {
+                if(contains(xids[i])) {
+                    _xares = xaResource;
+                    _lastValidated = System.currentTimeMillis();
+                    return true;
+                }
+            }
         }
 
-        for(int i = 0; i < xids.length; i++) {
-            if(contains(xids[i])) {
-                _xares = xaResource;
-                return true;
-            }
+        // either (or both) passes have an empty Xid set,
+        // so fallback to isSameRM as we can't use Xid matching
+        if(isSameRM(xaResource)) {
+            _xares = xaResource;
+            _lastValidated = System.currentTimeMillis();
+            return true;
         }
 
         return false;
@@ -165,6 +181,7 @@
     private final Map<XidImple,Long> _whenLastSeen = new HashMap<XidImple, Long>();
 
     private XAResource _xares;
+    private long _lastValidated;
 
     private static final int safetyIntervalMillis = 10000; // may eventually want to make this configurable?
 }
\ No newline at end of file

Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/XARecoveryModule.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/XARecoveryModule.java	2011-12-01 10:05:07 UTC (rev 37757)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP11_JBTM-842_JBTM-924/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/XARecoveryModule.java	2011-12-01 10:23:47 UTC (rev 37758)
@@ -94,7 +94,6 @@
         }
     }
 
-
     /**
 	 * @message com.arjuna.ats.internal.jta.recovery.xafirstpass {0} - first
 	 *          pass
@@ -193,13 +192,8 @@
 								+ ".transactionInitiatedRecovery completed");
 			}
 
-			/*
-			 * See the comment about this routine!!
-			 */
+            bottomUpRecovery();
 
-			resourceInitiatedRecovery();
-            resourceInitiatedRecoveryForRecoveryHelpers();
-
             if (jtaLogger.logger.isDebugEnabled())
 			{
 				jtaLogger.logger.debug(DebugLevel.FUNCTIONS,
@@ -241,8 +235,7 @@
 	public XAResource getNewXAResource(Xid xid)
 	{
 		if (_xidScans == null) {
-			resourceInitiatedRecovery();
-            resourceInitiatedRecoveryForRecoveryHelpers();
+			bottomUpRecovery();
         }
 
         if (_xidScans != null)
@@ -486,6 +479,8 @@
 								{
 									if (recoveryStatus == XARecoveryResource.WAITING_FOR_RECOVERY)
 									{
+									    // resource initiated recovery not possible (no distribution).
+
 										problem = false;
 
 										if (jtaLogger.loggerI18N
@@ -613,6 +608,25 @@
 		return true;
 	}
 
+    private void bottomUpRecovery() {
+
+        // scan using statically configured plugins;
+        resourceInitiatedRecovery();
+        // scan using dynamically configured plugins:
+        resourceInitiatedRecoveryForRecoveryHelpers();
+
+        // garbage collection:
+        if (_xidScans != null) {
+            Set<XAResource> keys = new HashSet<XAResource>(_xidScans.keySet());
+            for(XAResource theKey : keys) {
+                RecoveryXids recoveryXids = (RecoveryXids) _xidScans.get(theKey);
+                if(recoveryXids.isStale()) {
+                    _xidScans.remove(theKey);
+                }
+            }
+        }
+    }
+
 	/**
 	 * Now check for any outstanding transactions. If we didn't fail to recover
 	 * them, then roll them back - if they'd got through prepare we would have



More information about the jboss-svn-commits mailing list