[jboss-cvs] JBossAS SVN: r62671 - in branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha: framework/server and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 30 18:33:00 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-04-30 18:32:59 -0400 (Mon, 30 Apr 2007)
New Revision: 62671

Added:
   branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java
   branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java
   branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonControllerMBean.java
Modified:
   branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
   branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
Log:
[ASPATCH-209] Support restart of HASingleton on cluster merge

Copied: branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java (from rev 62660, branches/Branch_4_0/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java)
===================================================================
--- branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	                        (rev 0)
+++ branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	2007-04-30 22:32:59 UTC (rev 62671)
@@ -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/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-04-30 22:04:02 UTC (rev 62670)
+++ branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-04-30 22:32:59 UTC (rev 62671)
@@ -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;
@@ -890,8 +891,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,
@@ -965,6 +969,11 @@
       {
          log.error("merge failed", ex);
       }
+      finally
+      {
+         if (!isAlreadyMerging)
+            ClusterMergeStatus.endMergeProcess();
+      }
    }
 
    /**

Modified: branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-04-30 22:04:02 UTC (rev 62670)
+++ branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-04-30 22:32:59 UTC (rev 62671)
@@ -1,8 +1,8 @@
 /*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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
@@ -25,6 +25,7 @@
 
 import javax.management.Notification;
 
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.ha.jmx.HAServiceMBeanSupport;
 
 /** 
@@ -41,6 +42,7 @@
    // Private Data --------------------------------------------------
    
    private boolean isMasterNode = false;
+   private boolean restartOnMerge = false;
 
    // Constructors --------------------------------------------------
    
@@ -64,6 +66,38 @@
       return isMasterNode;
    }
 
+   /**
+    * 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 --------------------------------------------------------
 
    /**
@@ -125,7 +159,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)
@@ -188,16 +226,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)
       {
@@ -205,6 +234,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)

Copied: branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java (from rev 62669, branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java)
===================================================================
--- branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java	                        (rev 0)
+++ branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java	2007-04-30 22:32:59 UTC (rev 62671)
@@ -0,0 +1,40 @@
+/*
+ * 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.singleton;
+
+/**
+ * {@link HASingletonController} subclass that exposes the
+ * {@link #getRestartOnMerge() restartOnMerge}
+ * property via its MBean interface.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ * 
+ * @deprecated This class will be removed in 4.2.0 and later as
+ *             the restartOnMerge property is exposed in HASingletonControllerMBean
+ */
+public class RestartOnMergeHASingletonController extends HASingletonController
+      implements
+         RestartOnMergeHASingletonControllerMBean
+{
+
+}

Copied: branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonControllerMBean.java (from rev 62669, branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonControllerMBean.java)
===================================================================
--- branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonControllerMBean.java	                        (rev 0)
+++ branches/JBoss_4_0_4_GA_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonControllerMBean.java	2007-04-30 22:32:59 UTC (rev 62671)
@@ -0,0 +1,45 @@
+/**
+ * 
+ */
+package org.jboss.ha.singleton;
+
+/**
+ * Extends HASingletonControllerMBean to expose configuration of the
+ * <code>restartOnMerge</code> property.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ * 
+ * @deprecated This interface will be removed in 4.2.0 and later as
+ *             the restartOnMerge property is exposed in HASingletonControllerMBean
+ */
+public interface RestartOnMergeHASingletonControllerMBean extends HASingletonControllerMBean
+{
+
+   /**
+    * 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