[jboss-cvs] JBossAS SVN: r61770 - in branches/Branch_4_2/cluster/src: main/org/jboss/ha/framework/interfaces and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 27 22:42:24 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-27 22:42:24 -0400 (Tue, 27 Mar 2007)
New Revision: 61770

Added:
   branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java
Modified:
   branches/Branch_4_2/cluster/src/etc/deploy-hasingleton-service.xml
   branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
   branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
   branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java
Log:
[JBAS-4229] Restart singleton following cluster merge

Modified: branches/Branch_4_2/cluster/src/etc/deploy-hasingleton-service.xml
===================================================================
--- branches/Branch_4_2/cluster/src/etc/deploy-hasingleton-service.xml	2007-03-28 02:39:07 UTC (rev 61769)
+++ branches/Branch_4_2/cluster/src/etc/deploy-hasingleton-service.xml	2007-03-28 02:42:24 UTC (rev 61770)
@@ -27,6 +27,19 @@
       <attribute name="TargetStartMethodArgument">${jboss.server.home.url}/deploy-hasingleton</attribute>
       <attribute name="TargetStopMethod">undeploy</attribute>
       <attribute name="TargetStopMethodArgument">${jboss.server.home.url}/deploy-hasingleton</attribute>
+      
+      <!-- Whether the singleton should be restarted (i.e. invoke the TargetStopMethod and then the
+           TargetStartMethod) if a cluster merge occurs while this node is the singleton master.
+           A cluster merge means there may have been more than one singleton masters during the period
+           when communication between some or all of the nodes in the cluster was disrupted; hence the  
+           surviving master may not be aware of state changes made by another master. Restarting the 
+           singleton gives it a signal that it should refresh its internal state from any external 
+           store.  
+           
+           By default this is set to true, as HA-JMS should re-establish state from its persistent
+           store if a cluster merge occurs.
+      -->
+      <attribute name="RestartOnMerge">true</attribute>
    </mbean>
 
    <!--

Added: branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	                        (rev 0)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	2007-03-28 02:42:24 UTC (rev 61770)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * ThreadLocal-based context information about whether the
+ * current thread is executing a cluster merge.
+ * <p/>
+ * This is really a temporary 4.x workaround for JBAS-4229. In
+ * AS 5 this will likely be replaced by adding a boolean parameter
+ * to DistributedReplicantManager.ReplicantListener.replicantsChanged().
+ * 
+ * @author Brian Stansberry
+ */
+public class ClusterMergeStatus
+{
+   private static final ThreadLocal status = new ThreadLocal();
+   
+   public static void startMergeProcess()
+   {
+      status.set(Boolean.TRUE);
+   }
+   
+   public static void endMergeProcess()
+   {
+      status.set(null);
+   }
+   
+   public static boolean isMergeInProcess()
+   {
+      return status.get() != null;
+   }
+}

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-03-28 02:39:07 UTC (rev 61769)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-03-28 02:42:24 UTC (rev 61770)
@@ -41,6 +41,7 @@
 
 import org.jboss.logging.Logger;
 
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.ha.framework.interfaces.ClusterNode;
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
 import org.jboss.ha.framework.interfaces.HAPartition;
@@ -891,8 +892,11 @@
 
    protected void mergeMembers()
    {
+      boolean isAlreadyMerging = ClusterMergeStatus.isMergeInProcess();
       try
       {
+         ClusterMergeStatus.startMergeProcess();
+         
          log.debug("Start merging members in DRM service...");
          java.util.HashSet notifies = new java.util.HashSet ();
          ArrayList rsp = partition.callMethodOnCluster(SERVICE_NAME,
@@ -966,6 +970,11 @@
       {
          log.error("merge failed", ex);
       }
+      finally
+      {
+         if (!isAlreadyMerging)
+            ClusterMergeStatus.endMergeProcess();
+      }
    }
 
    /**

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-03-28 02:39:07 UTC (rev 61769)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-03-28 02:42:24 UTC (rev 61770)
@@ -25,6 +25,7 @@
 
 import javax.management.Notification;
 
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.ha.jmx.HAServiceMBeanSupport;
 
 /** 
@@ -36,12 +37,13 @@
  * @version $Revision$
  */
 public class HASingletonSupport extends HAServiceMBeanSupport
-   implements HASingletonMBean, HASingleton
+   implements HASingletonSupportMBean, HASingleton
 {
    // Private Data --------------------------------------------------
    
    private boolean isMasterNode = false;
    private HASingletonElectionPolicy mElectionPolicyMB = null;
+   private boolean restartOnMerge = true;
 
    // Constructors --------------------------------------------------
    
@@ -81,6 +83,38 @@
       return this.mElectionPolicyMB;
    }
 
+   /**
+    * Gets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs.
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @return <code>true</code> if a restart will occur, <code>false</code>
+    *         otherwise
+    */
+   public boolean getRestartOnMerge()
+   {
+      return restartOnMerge;
+   }
+
+   /**
+    * Sets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs?
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @param restartOnMerge <code>true</code> if a restart should occur, 
+    *                       <code>false</code> otherwise
+    */
+   public void setRestartOnMerge(boolean restartOnMerge)
+   {
+      this.restartOnMerge = restartOnMerge;
+   }
+
    // Public --------------------------------------------------------
 
    /**
@@ -121,7 +155,6 @@
       // Extending classes will implement the singleton logic here
    }
 
-
    /**
     * When topology changes, a new master is elected based on the result
     * of the isDRMMasterReplica() call.
@@ -130,7 +163,7 @@
     * @see  DistributedReplicantManager#isMasterReplica(String);
     */
    public void partitionTopologyChanged(List newReplicants, int newViewID)
-   {
+   {   
       boolean isElectedNewMaster;
       if (this.mElectionPolicyMB != null)
          isElectedNewMaster = this.mElectionPolicyMB.isElectedMaster(this.getPartition());
@@ -146,7 +179,11 @@
       // if this node is already the master, don't bother electing it again
       if (isElectedNewMaster && isMasterNode)
       {
-         return;
+         // JBAS-4229         
+         if (restartOnMerge && ClusterMergeStatus.isMergeInProcess())
+         {
+            restartMaster();
+         }
       }
       // just becoming master
       else if (isElectedNewMaster && !isMasterNode)
@@ -209,16 +246,7 @@
          //callMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
          callAsyncMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
 
-         isMasterNode = true;
-         
-         // notify starting
-         sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);
-
-         // start new master
-         startSingleton();
-         
-         // notify started
-         sendLocalNotification(HASINGLETON_STARTED_NOTIFICATION);         
+         startNewMaster();  
       }
       catch (Exception ex)
       {
@@ -226,6 +254,28 @@
       }
    }
    
+   protected void startNewMaster()
+   {
+      log.debug("startNewMaster, isMasterNode=" + isMasterNode);
+      
+      isMasterNode = true;
+      
+      // notify starting
+      sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);
+
+      // start new master
+      startSingleton();
+      
+      // notify started
+      sendLocalNotification(HASINGLETON_STARTED_NOTIFICATION);
+   }
+   
+   protected void restartMaster()
+   {
+      _stopOldMaster();
+      startNewMaster();
+   }
+   
    // Private -------------------------------------------------------
    
    private void sendLocalNotification(String type)

Modified: branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java	2007-03-28 02:39:07 UTC (rev 61769)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java	2007-03-28 02:42:24 UTC (rev 61770)
@@ -32,4 +32,30 @@
    /** The HASingleton election policy MBean */
    void setElectionPolicy(HASingletonElectionPolicy mb);
    HASingletonElectionPolicy getElectionPolicy();
+
+   /**
+    * Gets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs.
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @return <code>true</code> if a restart will occur, <code>false</code>
+    *         otherwise
+    */
+   boolean getRestartOnMerge();
+
+   /**
+    * Sets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs?
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @param restartOnMerge <code>true</code> if a restart should occur, 
+    *                       <code>false</code> otherwise
+    */
+   void setRestartOnMerge(boolean restartOnMerge);
 }




More information about the jboss-cvs-commits mailing list