[jboss-cvs] JBossAS SVN: r61877 - in branches/JBoss_4_0_3_SP1_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
Thu Mar 29 22:25:21 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-29 22:25:20 -0400 (Thu, 29 Mar 2007)
New Revision: 61877

Added:
   branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java
Modified:
   branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
   branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonController.java
   branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
   branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java
Log:
[ASPATCH-179] JBAS-4229 HASingletonController doesn't handle "split brain" correctly.

Copied: branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java (from rev 61864, branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java)
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	                        (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/interfaces/ClusterMergeStatus.java	2007-03-30 02:25:20 UTC (rev 61877)
@@ -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_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-03-30 01:48:45 UTC (rev 61876)
+++ branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2007-03-30 02:25:20 UTC (rev 61877)
@@ -27,6 +27,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;
@@ -877,8 +878,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,
@@ -952,6 +956,11 @@
       {
          log.error("merge failed", ex);
       }
+      finally
+      {
+         if (!isAlreadyMerging)
+            ClusterMergeStatus.endMergeProcess();
+      }
    }
 
    /**

Modified: branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonController.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonController.java	2007-03-30 01:48:45 UTC (rev 61876)
+++ branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonController.java	2007-03-30 02:25:20 UTC (rev 61877)
@@ -27,7 +27,7 @@
  */
 public class HASingletonController
    extends HASingletonSupport
-   implements HASingletonControllerMBean
+   implements RestartOnMergeHASingletonController
 {
 
    // -------------------------------------------------------------------------

Modified: branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-03-30 01:48:45 UTC (rev 61876)
+++ branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2007-03-30 02:25:20 UTC (rev 61877)
@@ -9,6 +9,7 @@
 
 import java.util.List;
 
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.ha.jmx.HAServiceMBeanSupport;
 
 /** 
@@ -25,12 +26,20 @@
    // Constants -----------------------------------------------------
 
    private boolean isMasterNode = false;
+   private boolean restartOnMerge = false;
 
+   // Constructors --------------------------------------------------
+   
+   /**
+    * Default CTOR
+    */
    public HASingletonSupport()
    {
-      // for JMX
+      // empty
    }
 
+   // Attributes ----------------------------------------------------
+   
    /**
     * 
     * @return true if this cluster node has the active mbean singleton.
@@ -43,9 +52,41 @@
       return isMasterNode;
    }
 
-   // Protected ------------------------------
+   /**
+    * 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 --------------------------------------------------------
+
+   /**
     * <p>
     * Extending classes should override this method and implement the custom
     * singleton logic. Only one node in the cluster is the active master.
@@ -67,8 +108,9 @@
     */
    public void startSingleton()
    {
-      boolean debug = log.isDebugEnabled();
-      if (debug) log.debug("startSingleton() : elected for master singleton node");
+      if (log.isDebugEnabled())
+         log.debug("startSingleton() : elected for master singleton node");
+
       // Extending classes will implement the singleton logic here
    }
 
@@ -79,12 +121,12 @@
     * method is invoked.
     * 
     * @see HASingleton
-    * 
     */
    public void stopSingleton()
    {
-      boolean debug = log.isDebugEnabled();
-      if (debug) log.debug("stopSingleton() : another node in the partition (if any) is elected for master ");
+      if (log.isDebugEnabled())
+         log.debug("stopSingleton() : another node in the partition (if any) is elected for master");
+      
       // Extending classes will implement the singleton logic here
    }
 
@@ -110,7 +152,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)
@@ -124,6 +170,22 @@
       }
    }
 
+   /**
+    * This method will be invoked twice by the local node 
+    * when it stops as well as by the remote
+    */
+   public void _stopOldMaster()
+   {
+      log.debug("_stopOldMaster, isMasterNode="+isMasterNode);
+      // since this is a cluster call, all nodes will hear it
+      // if the node is not the master, then ignore 
+      if (isMasterNode == true)
+      {
+         isMasterNode = false;
+         stopSingleton();
+      }
+   }
+
    protected void makeThisNodeMaster()
    {
       try
@@ -135,10 +197,7 @@
          //callMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
          callAsyncMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
 
-         isMasterNode = true;
-
-         // start new master
-         startSingleton();
+         startNewMaster();  
       }
       catch (Exception ex)
       {
@@ -147,21 +206,21 @@
             ex);
       }
    }
+   
+   protected void startNewMaster()
+   {
+      log.debug("startNewMaster, isMasterNode=" + isMasterNode);
+      
+      isMasterNode = true;
 
-   /**
-    * This method will be invoked twice by the local node 
-    * when it stops as well as by the remote
-    */
-   public void _stopOldMaster()
+      // start new master
+      startSingleton();
+   }
+   
+   protected void restartMaster()
    {
-      log.debug("_stopOldMaster, isMasterNode="+isMasterNode);
-      // since this is a cluster call, all nodes will hear it
-      // if the node is not the master, then ignore 
-      if (isMasterNode == true)
-      {
-         isMasterNode = false;
-         stopSingleton();
-      }
+      _stopOldMaster();
+      startNewMaster();
    }
 
    // Private -------------------------------------------------------

Modified: branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java	2007-03-30 01:48:45 UTC (rev 61876)
+++ branches/JBoss_4_0_3_SP1_CP/cluster/src/main/org/jboss/ha/singleton/RestartOnMergeHASingletonController.java	2007-03-30 02:25:20 UTC (rev 61877)
@@ -13,4 +13,30 @@
 public interface RestartOnMergeHASingletonController 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