[jboss-cvs] JBossAS SVN: r77744 - in trunk/cluster/src/main/org/jboss: invocation/jrmp/interfaces and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 1 05:57:12 EDT 2008


Author: galder.zamarreno at jboss.com
Date: 2008-09-01 05:57:12 -0400 (Mon, 01 Sep 2008)
New Revision: 77744

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java
   trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
   trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
Log:
[JBAS-5850] If a sticky target is not available any more, we fail now because failover is not allowed (transaction already active in one node).

Modified: trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java	2008-09-01 09:10:33 UTC (rev 77743)
+++ trunk/cluster/src/main/org/jboss/ha/framework/interfaces/TransactionSticky.java	2008-09-01 09:57:12 UTC (rev 77744)
@@ -49,7 +49,7 @@
       
       if (trace)
       {
-         log.trace("transaction sticky load balance policy delegates to: " + delegateLoadBalancePolicy);
+         log.trace("Transaction sticky load balance policy delegates to: " + delegateLoadBalancePolicy);
       }
    }
 
@@ -66,11 +66,11 @@
    {
       trace = log.isTraceEnabled();
       Object txStickyTarget = routingDecision.getTransientValue("TX_STICKY_TARGET");
-      if (txStickyTarget != null && clusterFamily.getTargets().contains(txStickyTarget))
+      if (txStickyTarget != null)
       {
          if (trace) 
          {
-            log.trace("transaction bound target exists: " + txStickyTarget);
+            log.trace("Transaction bound target exists: " + txStickyTarget);
          } 
          
          return txStickyTarget;
@@ -102,7 +102,7 @@
       
       if (trace) 
       {
-         log.trace("new target chosen: " + newTarget);
+         log.trace("New target chosen: " + newTarget);
       }
       
       invocation.getTransientPayload().put("TX_STICKY_TARGET", newTarget);

Modified: trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2008-09-01 09:10:33 UTC (rev 77743)
+++ trunk/cluster/src/main/org/jboss/invocation/jrmp/interfaces/JRMPInvokerProxyHA.java	2008-09-01 09:57:12 UTC (rev 77744)
@@ -155,11 +155,24 @@
          {
             if (trace)
             {
-               log.trace("checking tx failover authorisation map with tpc " + tpc);
+               log.trace("Checking tx failover authorisation map with tpc " + tpc);
             }
             
-            /* if the map contains the tpc, then we can't allow a failover */
-            return ! txFailoverAuthorizations.containsKey (tpc);               
+            /* If the map contains the tpc, then we can't allow a failover */
+            boolean failoverAuthorised = ! txFailoverAuthorizations.containsKey(tpc);
+            
+            if (failoverAuthorised)
+            {
+               if (trace) 
+               {
+                  log.trace("Failover authorised, so we remove the sticky target associated with tpc " + tpc);
+               }
+               
+               txFailoverAuthorizations.put(tpc, null);
+               invocation.getTransientPayload().put("TX_STICKY_TARGET", null);
+            }
+            
+            return failoverAuthorised;               
          }
       }
       else
@@ -424,7 +437,7 @@
     * target associated to it and add it to the invocation transient payload so 
     * that the load balance policy can choose the right target.
     */
-   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc) throws GenericClusteringException
    {
       if (tpc != null)
       {
@@ -432,19 +445,27 @@
          {
             if (trace)
             {
-               log.trace("in the proxy, transaction propagation context (tpc) is " + tpc);
+               log.trace("In the proxy, transaction propagation context (tpc) is " + tpc);
             }
 
             Object stickyTarget = txFailoverAuthorizations.get(tpc);
                
             if (stickyTarget != null)
             {
-               if (trace)
+               if (familyClusterInfo.getTargets().contains(stickyTarget))
                {
-                  log.trace("put transaction bound target [" + stickyTarget + "] into transient payload");
+                  if (trace) 
+                  {
+                     log.trace("Put transaction bound target into transient payload: " + stickyTarget);                  
+                  }
+                  
+                  invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);                  
                }
-               
-               invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
+               else
+               {
+                  throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES, 
+                     "Transaction sticky target is no longer available, so invocation needs to be halted");
+               }
             }
          }
       }

Modified: trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java
===================================================================
--- trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2008-09-01 09:10:33 UTC (rev 77743)
+++ trunk/cluster/src/main/org/jboss/invocation/unified/interfaces/UnifiedInvokerHAProxy.java	2008-09-01 09:57:12 UTC (rev 77744)
@@ -106,11 +106,24 @@
          {
             if (trace)
             {
-               log.trace("checking tx failover authorisation map with tpc " + tpc);
+               log.trace("Checking tx failover authorisation map with tpc " + tpc);
             }
-
-            /* if the map contains the tpc, then we can't allow a failover */
-            return ! txFailoverAuthorizations.containsKey(tpc);
+            
+            /* If the map contains the tpc, then we can't allow a failover */
+            boolean failoverAuthorised = ! txFailoverAuthorizations.containsKey(tpc);
+            
+            if (failoverAuthorised)
+            {
+               if (trace) 
+               {
+                  log.trace("Failover authorised, so we remove the sticky target associated with tpc " + tpc);
+               }
+               
+               txFailoverAuthorizations.put(tpc, null);
+               invocation.getTransientPayload().put("TX_STICKY_TARGET", null);
+            }
+            
+            return failoverAuthorised;
          }
       }
       
@@ -126,14 +139,14 @@
          {
             if (trace)
             {
-               log.trace("after reaching the server, transaction propagation context (tpc) is " + tpc);
+               log.trace("After reaching the server, transaction propagation context (tpc) is " + tpc);
             }
             
             Object stickyTarget = invocation.getTransientValue("TX_STICKY_TARGET");
             
             if (trace && stickyTarget != null)
             {
-               log.trace("remember transaction bound target[" + stickyTarget + "] for tpc[" + tpc + "]");
+               log.trace("Remember transaction bound target[" + stickyTarget + "] for tpc " + tpc);
             }
             
             txFailoverAuthorizations.put(tpc, stickyTarget);
@@ -199,9 +212,6 @@
       int failoverCounter = 0;
       invocation.setValue("FAILOVER_COUNTER", new Integer(failoverCounter), PayloadKey.AS_IS);
       
-      // If transaction sticky, put chosen target
-      putIfExistsTransactionTarget(invocation, getTransactionPropagationContext());
-
       Object response = null;
       Exception lastException = null;
 
@@ -220,6 +230,9 @@
                log.trace(printPossibleTargets());
             }
 
+            // If transaction sticky, put chosen target
+            putIfExistsTransactionTarget(invocation, getTransactionPropagationContext());
+
             Client clientInstance = getClient(invocation);
 
             if (trace)
@@ -535,9 +548,12 @@
     * Called at the beginning of the invocation to check whether the current tpc
     * is already present in the tx failover map. If it is, get the chosen 
     * target associated to it and add it to the invocation transient payload so 
-    * that the load balance policy can choose the right target.
-    */
-   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+    * that the load balance policy can choose the right target as long as the 
+    * target is available in the cluster family. Otherwise, invocation needs to 
+    * be halted because a previous invocation within the transaction succeeded 
+    * (tx sticky target was set), so we can't failover to a different node.
+    */   
+   protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc) throws GenericClusteringException
    {
       if (tpc != null)
       {
@@ -545,19 +561,27 @@
          {
             if (trace)
             {
-               log.trace("in the proxy, transaction propagation context (tpc) is " + tpc);
+               log.trace("In the proxy, transaction propagation context (tpc) is " + tpc);
             }
 
             Object stickyTarget = txFailoverAuthorizations.get(tpc);
                
             if (stickyTarget != null)
             {
-               if (trace)
+               if (familyClusterInfo.getTargets().contains(stickyTarget))
                {
-                  log.trace("put transaction bound target [" + stickyTarget + "] into transient payload");
+                  if (trace) 
+                  {
+                     log.trace("Put transaction bound target into transient payload: " + stickyTarget);                  
+                  }
+                  
+                  invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);                  
                }
-               
-               invocation.getTransientPayload().put("TX_STICKY_TARGET", stickyTarget);
+               else
+               {
+                  throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES, 
+                     "Transaction sticky target is no longer available, so invocation needs to be halted");
+               }
             }
          }
       }




More information about the jboss-cvs-commits mailing list