You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2010/08/16 07:04:32 UTC

svn commit: r985786 - in /hbase/branches/0.90_master_rewrite: conf/ src/main/java/org/apache/hadoop/hbase/ src/main/java/org/apache/hadoop/hbase/ipc/ src/main/java/org/apache/hadoop/hbase/master/ src/main/java/org/apache/hadoop/hbase/regionserver/ src/...

Author: stack
Date: Mon Aug 16 05:04:31 2010
New Revision: 985786

URL: http://svn.apache.org/viewvc?rev=985786&view=rev
Log:
This change is mostly around cluster shutdown.  It removes the quiesce notion.
Instead, we've added a listener in regionserver on the cluster shutdown znode
up in zk.  When it disappears, all regionservers close all user regions using
handlers (but not updating zk -- is this ok?).  This means the bulk of the
HMsg stuff is gone and the only stuff that remains is the admin split, compact,
and flush -- oh and split.... Master telling regionserver to exit is still here
too.  This change is cleaning out a lot of crude, mostly the more than one
way we had of doing stuff; now region shutdown is always handled by the
expiration of a zknode over in master whether it a crash or clean shutdown or
cluster shutdown.

Change also unified how we do opens.  All use same method now instead of the
two (or three) ways we had of opening previous.

This change is not yet finished.  I've still to add to the master the closeup
of the two servers carrying root and meta.  TODO.

M src/test/java/org/apache/hadoop/hbase/TestSerialization.java
  Changed name of the message.  Should just removed HMsg from here.
M src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java
  Changed name of HMsg for split.
M src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
  Changed name of testing HMsg.
M src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java
  openHRegion params changed.
M src/test/java/org/apache/hadoop/hbase/TestHMsg.java
  Use different HMsgs other than the ones removed.
M src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java
  Removed unnecessary data member.  Jon, this class seems to be listening to
  the wrong node; its listening to root location rather than shutdown node.
M src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
  Cleaned out a bunch of HMsg and queisced state processing.
  Added new tracker on clusterStateZNode node.
  Cleanup around the end of the run method.  Moved crud out into own methods.
  The Worker thread in here is almost ready to do now handlers are doing
  nearly all it used do.
  Added Stoppable and Abortable to its API so now a client could directly
  tell a regionserver stop/abort.
M src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
  Added a constructor flag which designates whether to update zk or not (so we
  use same close region code whenever we are closing a region, rather than have
  two ways of shutting down -- I want to use handlers because they are managed
  concurrency rather than what was there before which was starting up a thread
  for each region and running all concurrently).
M src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
  Removed crud around quescing servers and the messaging around stopping
  of a regionserver (regionserver exit stuff -- not needed anymore since
  regionserver reports its exit by letting go of its znode up in zk).
  Some refactoring of the heartbeat handling.  It shrunk radically.
  (processRegionServerExit): Removed.  Let expiredServer do whatever this
  was going to do.
M src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
  Fix of comments and javadoc.
M src/main/java/org/apache/hadoop/hbase/master/HMaster.java
  Removed silly data member flag; ask servermanager; its running the shutdown
  so it knows best.
M src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
  Upped the version
M src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
  Added Stoppable and Abortable.
M src/main/java/org/apache/hadoop/hbase/util/Merge.java
M src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java
  (openHRegion) Params changed.
M src/main/java/org/apache/hadoop/hbase/HMsg.java
  Stripped most of this classes content.  The rest should probably go too..
  but for one or two messages sent from RS to Master.

Modified:
    hbase/branches/0.90_master_rewrite/conf/hbase-site.xml
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/HMsg.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseMetaHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/Merge.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestHMsg.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java

Modified: hbase/branches/0.90_master_rewrite/conf/hbase-site.xml
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/conf/hbase-site.xml?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/conf/hbase-site.xml (original)
+++ hbase/branches/0.90_master_rewrite/conf/hbase-site.xml Mon Aug 16 05:04:31 2010
@@ -2,7 +2,7 @@
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!--
 /**
- * Copyright 2009 The Apache Software Foundation
+ * Copyright 2007 The Apache Software Foundation
  *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,4 +22,116 @@
  */
 -->
 <configuration>
+  <property>
+    <name>hbase.regionserver.msginterval</name>
+    <value>1000</value>
+    <description>Interval between messages from the RegionServer to HMaster
+    in milliseconds.  Default is 15. Set this value low if you want unit
+    tests to be responsive.
+    </description>
+  </property>
+  <property>
+    <name>hbase.client.pause</name>
+    <value>5000</value>
+    <description>General client pause value.  Used mostly as value to wait
+    before running a retry of a failed get, region lookup, etc.</description>
+  </property>
+  <property>
+    <name>hbase.client.retries.number</name>
+    <value>4</value>
+    <description>Maximum retries.  Used as maximum for all retryable
+    operations such as fetching of the root region from root region
+    server, getting a cell's value, starting a row update, etc.
+    Default: 10.
+    </description>
+  </property>
+  <property>
+    <name>hbase.master.meta.thread.rescanfrequency</name>
+    <value>10000</value>
+    <description>How long the HMaster sleeps (in milliseconds) between scans of
+    the root and meta tables.
+    </description>
+  </property>
+  <property>
+    <name>hbase.server.thread.wakefrequency</name>
+    <value>1000</value>
+    <description>Time to sleep in between searches for work (in milliseconds).
+    Used as sleep interval by service threads such as META scanner and log roller.
+    </description>
+  </property>
+  <property>
+    <name>hbase.regionserver.handler.count</name>
+    <value>5</value>
+    <description>Count of RPC Server instances spun up on RegionServers
+    Same property is used by the HMaster for count of master handlers.
+    Default is 10.
+    </description>
+  </property>
+  <property>
+    <name>hbase.master.info.port</name>
+    <value>-1</value>
+    <description>The port for the hbase master web UI
+    Set to -1 if you do not want the info server to run.
+    </description>
+  </property>
+  <property>
+    <name>hbase.regionserver.info.port</name>
+    <value>-1</value>
+    <description>The port for the hbase regionserver web UI
+    Set to -1 if you do not want the info server to run.
+    </description>
+  </property>
+  <property>
+    <name>hbase.regionserver.info.port.auto</name>
+    <value>true</value>
+    <description>Info server auto port bind. Enables automatic port
+    search if hbase.regionserver.info.port is already in use.
+    Enabled for testing to run multiple tests on one machine.
+    </description>
+  </property>
+  <property>
+    <name>hbase.master.lease.thread.wakefrequency</name>
+    <value>3000</value>
+    <description>The interval between checks for expired region server leases.
+    This value has been reduced due to the other reduced values above so that
+    the master will notice a dead region server sooner. The default is 15 seconds.
+    </description>
+  </property>
+  <property>
+    <name>hbase.regionserver.optionalcacheflushinterval</name>
+    <value>1000</value>
+    <description>
+    Amount of time to wait since the last time a region was flushed before
+    invoking an optional cache flush. Default 60,000.
+    </description>
+  </property>
+  <property>
+    <name>hbase.regionserver.safemode</name>
+    <value>false</value>
+    <description>
+    Turn on/off safe mode in region server. Always on for production, always off
+    for tests.
+    </description>
+  </property>
+  <property>
+    <name>hbase.hregion.max.filesize</name>
+    <value>67108864</value>
+    <description>
+    Maximum desired file size for an HRegion.  If filesize exceeds
+    value + (value / 2), the HRegion is split in two.  Default: 256M.
+
+    Keep the maximum filesize small so we split more often in tests.
+    </description>
+  </property>
+  <property>
+    <name>hadoop.log.dir</name>
+    <value>${user.dir}/../logs</value>
+  </property>
+  <property>
+    <name>hbase.zookeeper.property.clientPort</name>
+    <value>21810</value>
+    <description>Property from ZooKeeper's config zoo.cfg.
+    The port at which the clients will connect.
+    </description>
+  </property>
 </configuration>

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/HMsg.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/HMsg.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/HMsg.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/HMsg.java Mon Aug 16 05:04:31 2010
@@ -27,106 +27,53 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.io.Writable;
 
 /**
- * HMsg is for communicating instructions between the HMaster and the
- * HRegionServers.
+ * HMsg is used to send messages between master and regionservers.  Messages are
+ * sent as payload on the regionserver-to-master heartbeats.  Region assignment
+ * does not use this mechanism.  It goes via zookeeper.
  *
- * Most of the time the messages are simple but some messages are accompanied
- * by the region affected.  HMsg may also carry optional message.
+ * <p>Most of the time the messages are simple but some messages are accompanied
+ * by the region affected.  HMsg may also carry an optional message.
+ * 
+ * <p>TODO: Clean out all messages that go from master to regionserver; by
+ * design, these are to go via zk from here on out.
  */
 public class HMsg implements Writable {
-  public static final HMsg REGIONSERVER_QUIESCE =
-    new HMsg(Type.MSG_REGIONSERVER_QUIESCE);
-  public static final HMsg REGIONSERVER_STOP =
-    new HMsg(Type.MSG_REGIONSERVER_STOP);
+  public static final HMsg [] STOP_REGIONSERVER_ARRAY =
+    new HMsg [] {new HMsg(Type.STOP_REGIONSERVER)};
   public static final HMsg [] EMPTY_HMSG_ARRAY = new HMsg[0];
 
-  /**
-   * Message types sent between master and regionservers
-   */
   public static enum Type {
-    /** null message */
-    MSG_NONE,
-
-    // Message types sent from master to region server
-    /** Start serving the specified region */
-    MSG_REGION_OPEN,
-
-    /** Stop serving the specified region */
-    MSG_REGION_CLOSE,
-
     /** Split the specified region */
-    MSG_REGION_SPLIT,
+    SPLIT_REGION,
 
     /** Compact the specified region */
-    MSG_REGION_COMPACT,
-
-    /** Master tells region server to stop */
-    MSG_REGIONSERVER_STOP,
-
-    /** Stop serving the specified region and don't report back that it's
-     * closed
-     */
-    MSG_REGION_CLOSE_WITHOUT_REPORT,
-
-    /** Stop serving user regions */
-    MSG_REGIONSERVER_QUIESCE,
-
-    // Message types sent from the region server to the master
-    /** region server is now serving the specified region */
-    MSG_REPORT_OPEN,
-
-    /** region server is no longer serving the specified region */
-    MSG_REPORT_CLOSE,
-
-    /** region server is processing open request */
-    MSG_REPORT_PROCESS_OPEN,
+    COMPACT_REGION,
 
     /**
-     * Region server split the region associated with this message.
-     *
-     * Note that this message is immediately followed by two MSG_REPORT_OPEN
-     * messages, one for each of the new regions resulting from the split
-     * @deprecated See MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS
+     * Flush region.
      */
-    MSG_REPORT_SPLIT,
+    FLUSH_REGION,
 
     /**
-     * Region server is shutting down
-     *
-     * Note that this message is followed by MSG_REPORT_CLOSE messages for each
-     * region the region server was serving, unless it was told to quiesce.
-     */
-    MSG_REPORT_EXITING,
-
-    /** Region server has closed all user regions but is still serving meta
-     * regions
-     */
-    MSG_REPORT_QUIESCED,
-
-    /**
-     * Flush
+     * Run Major Compaction
      */
-    MSG_REGION_FLUSH,
+    MAJOR_COMPACTION,
 
-    /**
-     * Run Major Compaction
+    /** Master tells region server to stop.
      */
-    MSG_REGION_MAJOR_COMPACT,
+    STOP_REGIONSERVER,
 
     /**
      * Region server split the region associated with this message.
-     *
-     * Its like MSG_REPORT_SPLIT only it carries the daughters in the message
-     * rather than send them individually in MSG_REPORT_OPEN messages.
      */
-    MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS,
+    REGION_SPLIT,
 
     /**
      * When RegionServer receives this message, it goes into a sleep that only
      * an exit will cure.  This message is sent by unit tests simulating
      * pathological states.
      */
-    TESTING_MSG_BLOCK_RS,
+    TESTING_BLOCK_REGIONSERVER,
   }
 
   private Type type = null;
@@ -137,7 +84,7 @@ public class HMsg implements Writable {
 
   /** Default constructor. Used during deserialization */
   public HMsg() {
-    this(Type.MSG_NONE);
+    this(null);
   }
 
   /**
@@ -181,9 +128,6 @@ public class HMsg implements Writable {
    */
   public HMsg(final HMsg.Type type, final HRegionInfo hri,
       final HRegionInfo daughterA, final HRegionInfo daughterB, final byte[] msg) {
-    if (type == null) {
-      throw new NullPointerException("Message type cannot be null");
-    }
     this.type = type;
     if (hri == null) {
       throw new NullPointerException("Region cannot be null");
@@ -301,7 +245,7 @@ public class HMsg implements Writable {
        out.writeBoolean(true);
        Bytes.writeByteArray(out, this.message);
      }
-     if (this.type.equals(Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS)) {
+     if (this.type.equals(Type.REGION_SPLIT)) {
        this.daughterA.write(out);
        this.daughterB.write(out);
      }
@@ -318,7 +262,7 @@ public class HMsg implements Writable {
      if (hasMessage) {
        this.message = Bytes.readByteArray(in);
      }
-     if (this.type.equals(Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS)) {
+     if (this.type.equals(Type.REGION_SPLIT)) {
        this.daughterA = new HRegionInfo();
        this.daughterB = new HRegionInfo();
        this.daughterA.readFields(in);

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java Mon Aug 16 05:04:31 2010
@@ -76,7 +76,8 @@ public interface HBaseRPCProtocolVersion
    * <li>Version 22: HBASE-2209. Added List support to RPC</li>
    * <li>Version 23: HBASE-2066, multi-put.</li>
    * <li>Version 24: HBASE-2473, create table with regions.</li>
+   * <li>Version 25: Added openRegion and Stoppable/Abortable to API.</li>
    * </ul>
    */
-  public static final long versionID = 24L;
+  public static final long versionID = 25L;
 }

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java Mon Aug 16 05:04:31 2010
@@ -22,9 +22,11 @@ package org.apache.hadoop.hbase.ipc;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.hadoop.hbase.Abortable;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.NotServingRegionException;
+import org.apache.hadoop.hbase.Stoppable;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.MultiPut;
@@ -40,7 +42,7 @@ import org.apache.hadoop.hbase.regionser
  * <p>NOTE: if you change the interface, you must change the RPC version
  * number in HBaseRPCProtocolVersion
  */
-public interface HRegionInterface extends HBaseRPCProtocolVersion {
+public interface HRegionInterface extends HBaseRPCProtocolVersion, Stoppable, Abortable {
   /**
    * Get metainfo about an HRegion
    *

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java Mon Aug 16 05:04:31 2010
@@ -234,7 +234,7 @@ public class AssignmentManager extends Z
         return;
       }
       String encodedName = HRegionInfo.encodeRegionName(data.getRegionName());
-      LOG.debug("Attempting to handle region transition for server " +
+      LOG.debug("Handling region transition for server " +
           data.getServerName() + " and region " + encodedName);
       RegionState regionState = regionsInTransition.get(encodedName);
       switch(data.getEventType()) {
@@ -561,7 +561,7 @@ public class AssignmentManager extends Z
   /**
    * Unassigns the specified region.
    * <p>
-   * Updates the RegionState and sends the OPEN RPC.
+   * Updates the RegionState and sends the CLOSE RPC.
    * <p>
    * If a RegionPlan is already set, it will remain.  If this is being used
    * to disable a table, be sure to use {@link #disableTable(String)} to ensure
@@ -591,7 +591,7 @@ public class AssignmentManager extends Z
         return;
       }
     }
-    // Send OPEN RPC
+    // Send CLOSE RPC
     try {
       serverManager.sendRegionClose(regions.get(region), state.getRegion());
     } catch (NotServingRegionException e) {

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Mon Aug 16 05:04:31 2010
@@ -154,8 +154,6 @@ implements HMasterInterface, HMasterRegi
   private boolean stopped = false;
   // Set on abort -- usually failure of our zk session
   private volatile boolean abort = false;
-  // Gets set to the time a cluster shutdown was initiated.
-  private volatile boolean runningClusterShutdown;
 
   /**
    * Initializes the HMaster. The steps are as follows:
@@ -307,7 +305,7 @@ implements HMasterInterface, HMasterRegi
       while (!this.stopped  && !this.abort) {
         // Master has nothing to do
         sleeper.sleep();
-        if (this.runningClusterShutdown) {
+        if (this.serverManager.isClusterShutdown()) {
           int count = this.serverManager.numServers();
           if (count != countOfServersStillRunning) {
             countOfServersStillRunning = count;
@@ -322,7 +320,7 @@ implements HMasterInterface, HMasterRegi
 
     // Wait for all the remaining region servers to report in IFF we were
     // running a cluster shutdown AND we were NOT aborting.
-    if (!this.abort && this.runningClusterShutdown) {
+    if (!this.abort && this.serverManager.isClusterShutdown()) {
       this.serverManager.letRegionServersShutdown();
     }
 
@@ -736,7 +734,6 @@ implements HMasterInterface, HMasterRegi
   @Override
   public void shutdown() {
     this.serverManager.shutdownCluster();
-    this.runningClusterShutdown = true;
     try {
       this.clusterStatusTracker.setClusterDown();
     } catch (KeeperException e) {

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java Mon Aug 16 05:04:31 2010
@@ -67,8 +67,8 @@ import org.apache.hadoop.hbase.util.Thre
 public class ServerManager {
   private static final Log LOG = LogFactory.getLog(ServerManager.class);
 
-  private final AtomicInteger quiescedServers = new AtomicInteger(0);
   private final AtomicInteger availableServers = new AtomicInteger(0);
+
   // Set if we are to shutdown the cluster.
   private volatile boolean clusterShutdown = false;
 
@@ -272,127 +272,46 @@ public class ServerManager {
   HMsg [] regionServerReport(final HServerInfo serverInfo,
     final HMsg msgs[], final HRegionInfo[] mostLoadedRegions)
   throws IOException {
+    // Be careful. This method does returns in the middle.
     HServerInfo info = new HServerInfo(serverInfo);
+
+    // Check if dead.  If it is, it'll get a 'You Are Dead!' exception.
     checkIsDead(info.getServerName(), "REPORT");
-    if (msgs.length > 0) {
-      if (msgs[0].isType(HMsg.Type.MSG_REPORT_EXITING)) {
-        processRegionServerExit(info, msgs);
-        return HMsg.EMPTY_HMSG_ARRAY;
-      } else if (msgs[0].isType(HMsg.Type.MSG_REPORT_QUIESCED)) {
-        LOG.info("Region server " + info.getServerName() + " quiesced");
-        this.quiescedServers.incrementAndGet();
-      }
-    }
-    if (this.clusterShutdown) {
-      if (quiescedServers.get() >= availableServers.get()) {
-        this.master.stop("All user tables quiesced. Proceeding with shutdown");
-        notifyOnlineServers();
-      } else if (!this.master.isStopped()) {
-        if (msgs.length > 0 &&
-            msgs[0].isType(HMsg.Type.MSG_REPORT_QUIESCED)) {
-          // Server is already quiesced, but we aren't ready to shut down
-          // return empty response
-          return HMsg.EMPTY_HMSG_ARRAY;
-        }
-        // Tell the server to stop serving any user regions
-        return new HMsg [] {HMsg.REGIONSERVER_QUIESCE};
-      }
-    }
-    if (this.master.isStopped()) {
-      // Tell server to shut down if we are shutting down.  This should
-      // happen after check of MSG_REPORT_EXITING above, since region server
-      // will send us one of these messages after it gets MSG_REGIONSERVER_STOP
-      return new HMsg [] {HMsg.REGIONSERVER_STOP};
-    }
 
+    // If we don't know this server, tell it shutdown.
     HServerInfo storedInfo = this.onlineServers.get(info.getServerName());
     if (storedInfo == null) {
       LOG.warn("Received report from unknown server -- telling it " +
-        "to " + HMsg.REGIONSERVER_STOP + ": " + info.getServerName());
-      // The HBaseMaster may have been restarted.
-      // Tell the RegionServer to abort!
-      return new HMsg[] {HMsg.REGIONSERVER_STOP};
-    } else if (storedInfo.getStartCode() != info.getStartCode()) {
+        "to " + HMsg.Type.STOP_REGIONSERVER + ": " + info.getServerName());
+      return HMsg.STOP_REGIONSERVER_ARRAY;
+    }
+
+    // Check startcodes
+    if (raceThatShouldNotHappenAnymore(storedInfo, info)) {
+      return HMsg.STOP_REGIONSERVER_ARRAY;
+    }
+
+    return processRegionServerAllsWell(info, mostLoadedRegions, HMsg.EMPTY_HMSG_ARRAY);
+  }
+
+  private boolean raceThatShouldNotHappenAnymore(final HServerInfo storedInfo,
+      final HServerInfo reportedInfo) {
+    if (storedInfo.getStartCode() != reportedInfo.getStartCode()) {
+      // TODO: I don't think this possible any more.  We check startcodes when
+      // server comes in on regionServerStartup -- St.Ack
       // This state is reachable if:
-      //
       // 1) RegionServer A started
-      // 2) RegionServer B started on the same machine, then
-      //    clobbered A in regionServerStartup.
+      // 2) RegionServer B started on the same machine, then clobbered A in regionServerStartup.
       // 3) RegionServer A returns, expecting to work as usual.
-      //
       // The answer is to ask A to shut down for good.
-
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("region server race condition detected: " +
-            info.getServerName());
-      }
-
+      LOG.warn("Race condition detected: " + reportedInfo.getServerName());
       synchronized (this.onlineServers) {
-        removeServerInfo(info.getServerName());
+        removeServerInfo(reportedInfo.getServerName());
         notifyOnlineServers();
       }
-
-      return new HMsg[] {HMsg.REGIONSERVER_STOP};
-    } else {
-      return processRegionServerAllsWell(info, mostLoadedRegions, msgs);
-    }
-  }
-
-  /**
-   * Region server is exiting with a clean shutdown.
-   *
-   * In this case, the server sends MSG_REPORT_EXITING in msgs[0] followed by
-   * a MSG_REPORT_CLOSE for each region it was serving.
-   * @param serverInfo
-   * @param msgs
-   */
-  private void processRegionServerExit(HServerInfo serverInfo, HMsg[] msgs) {
-    // TODO: won't send MSG_REPORT_CLOSE for each region
-    // TODO: Change structure/naming of removeServerInfo (does much more)
-    // TODO: should we keep this?  seems like master could issue closes
-    //       and then rs would stagger rather than closing all before
-    //       reporting back to master they are closed?
-    synchronized (this.onlineServers) {
-      // This method removes ROOT/META from the list and marks them to be
-      // reassigned in addition to other housework.
-      if (removeServerInfo(serverInfo.getServerName())) {
-        // Only process the exit message if the server still has registered info.
-        // Otherwise we could end up processing the server exit twice.
-        LOG.info("Region server " + serverInfo.getServerName() +
-          ": MSG_REPORT_EXITING");
-        // Get all the regions the server was serving reassigned
-        // (if we are not shutting down).
-        if (!master.isStopped()) {
-          for (int i = 1; i < msgs.length; i++) {
-            LOG.info("Processing " + msgs[i] + " from " +
-              serverInfo.getServerName());
-            assert msgs[i].getType() == HMsg.Type.MSG_REGION_CLOSE;
-            HRegionInfo info = msgs[i].getRegionInfo();
-            // Meta/root region offlining is handed in removeServerInfo above.
-            if (!info.isMetaRegion()) {
-//              synchronized (masterStatus.getRegionManager()) {
-//                if (!masterStatus.getRegionManager().isOfflined(info.getRegionNameAsString())) {
-//                  masterStatus.getRegionManager().setUnassigned(info, true);
-//                } else {
-//                  masterStatus.getRegionManager().removeRegion(info);
-//                }
-//              }
-            }
-          }
-        }
-        // There should not be any regions in transition for this server - the
-        // server should finish transitions itself before closing
-//        Map<String, RegionState> inTransition = masterStatus.getRegionManager()
-//            .getRegionsInTransitionOnServer(serverInfo.getServerName());
-//        for (Map.Entry<String, RegionState> entry : inTransition.entrySet()) {
-//          LOG.warn("Region server " + serverInfo.getServerName()
-//              + " shut down with region " + entry.getKey() + " in transition "
-//              + "state " + entry.getValue());
-//          masterStatus.getRegionManager().setUnassigned(entry.getValue().getRegionInfo(),
-//              true);
-//        }
-      }
+      return true;
     }
+    return false;
   }
 
   /**
@@ -523,7 +442,7 @@ public class ServerManager {
     HServerInfo info = this.onlineServers.get(serverName);
     if (info == null) {
       LOG.warn("Received expiration of " + hsi.getServerName() +
-      " but server is not currently online");
+        " but server is not currently online");
       return;
     }
     if (this.deadServers.contains(serverName)) {
@@ -536,6 +455,13 @@ public class ServerManager {
     this.onlineServers.remove(serverName);
     this.availableServers.decrementAndGet();
     this.serverConnections.remove(serverName);
+    // If cluster is going down, yes, servers are going to be expiring; don't
+    // process as a dead server
+    if (this.clusterShutdown) {
+      LOG.info("Cluster shutdown in progress; " + hsi.getServerName() +
+        " is down");
+      return;
+    }
     // Add to dead servers and queue a shutdown processing.
     this.deadServers.add(serverName);
     new ServerShutdownHandler(master).submit();
@@ -673,7 +599,11 @@ public class ServerManager {
   }
 
   public void shutdownCluster() {
-    LOG.info("Cluster shutdown requested. Starting to quiesce servers");
+    LOG.info("Cluster shutdown requested");
     this.clusterShutdown = true;
   }
+
+  public boolean isClusterShutdown() {
+    return this.clusterShutdown;
+  }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Mon Aug 16 05:04:31 2010
@@ -58,9 +58,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.Chore;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HConstants.OperationStatusCode;
 import org.apache.hadoop.hbase.HMsg;
-import org.apache.hadoop.hbase.HMsg.Type;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.HServerAddress;
@@ -75,6 +73,8 @@ import org.apache.hadoop.hbase.Stoppable
 import org.apache.hadoop.hbase.UnknownRowLockException;
 import org.apache.hadoop.hbase.UnknownScannerException;
 import org.apache.hadoop.hbase.YouAreDeadException;
+import org.apache.hadoop.hbase.HConstants.OperationStatusCode;
+import org.apache.hadoop.hbase.HMsg.Type;
 import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
@@ -110,6 +110,7 @@ import org.apache.hadoop.hbase.util.Pair
 import org.apache.hadoop.hbase.util.Sleeper;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.hadoop.io.MapWritable;
 import org.apache.hadoop.io.Writable;
@@ -124,17 +125,12 @@ import org.apache.zookeeper.KeeperExcept
 public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
     Runnable, RegionServer {
   public static final Log LOG = LogFactory.getLog(HRegionServer.class);
-  private static final HMsg REPORT_EXITING = new HMsg(Type.MSG_REPORT_EXITING);
-  private static final HMsg REPORT_QUIESCED = new HMsg(Type.MSG_REPORT_QUIESCED);
-  private static final HMsg[] EMPTY_HMSG_ARRAY = new HMsg[] {};
 
   // Set when a report to the master comes back with a message asking us to
   // shutdown. Also set by call to stop when debugging or running unit tests
   // of HRegionServer in isolation.
   protected volatile boolean stopped = false;
 
-  protected final AtomicBoolean quiesced = new AtomicBoolean(false);
-
   // Go down hard. Used if file system becomes unavailable and also in
   // debugging and unit tests.
   protected volatile boolean abortRequested;
@@ -231,6 +227,9 @@ public class HRegionServer implements HR
   // catalog tracker
   private CatalogTracker catalogTracker;
 
+  // Cluster Status Tracker
+  private ZooKeeperNodeTracker clusterShutdownTracker;
+
   // A sleeper that sleeps for msgInterval.
   private final Sleeper sleeper;
 
@@ -350,6 +349,31 @@ public class HRegionServer implements HR
     this.catalogTracker = new CatalogTracker(zooKeeper, connection, this,
         conf.getInt("hbase.regionserver.catalog.timeout", -1));
     catalogTracker.start();
+
+    this.clusterShutdownTracker = new ZooKeeperNodeTracker(this.zooKeeper,
+        this.zooKeeper.clusterStateZNode, this) {
+      @Override
+      public synchronized void nodeDeleted(String path) {
+        super.nodeDeleted(path);
+        if (getData() == null) {
+          // Cluster was just marked for shutdown.
+          LOG.info("Received cluster shutdown message");
+          closeUserRegions();
+          TODO: QUEUE UP THE CLOSEREGIONHANDLERSS FOR USER REGIONS
+          if (onlineRegions.isEmpty()) {
+            // We closed all user regions and there is nothing else left
+            // on this server; just go down.
+            HRegionServer.this.stop("All user regions closed; not " +
+              "carrying catalog regions -- so stopping");
+          } else {
+            LOG.info("Closed all user regions; still carrying " +
+              onlineRegions.values());
+          }
+        }
+      }
+    };
+    this.zooKeeper.registerListener(this.clusterShutdownTracker);
+    this.clusterShutdownTracker.start();
   }
 
   private void initializeThreads() throws IOException {
@@ -405,7 +429,6 @@ public class HRegionServer implements HR
    */
   public void run() {
     regionServerThread = Thread.currentThread();
-    boolean quiesceRequested = false;
     try {
       MapWritable w = null;
       while (!this.stopped) {
@@ -441,11 +464,11 @@ public class HRegionServer implements HR
         if ((now - lastMsg) >= msgInterval || !outboundMessages.isEmpty()) {
           try {
             doMetrics();
-            MemoryUsage memory = ManagementFactory.getMemoryMXBean()
-                .getHeapMemoryUsage();
-            HServerLoad hsl = new HServerLoad(requestCount.get(), (int) (memory
-                .getUsed() / 1024 / 1024),
-                (int) (memory.getMax() / 1024 / 1024));
+            MemoryUsage memory =
+              ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
+            HServerLoad hsl = new HServerLoad(requestCount.get(),
+              (int)(memory.getUsed() / 1024 / 1024),
+              (int) (memory.getMax() / 1024 / 1024));
             for (HRegion r : onlineRegions.values()) {
               hsl.addRegionInfo(createRegionLoad(r));
             }
@@ -453,19 +476,11 @@ public class HRegionServer implements HR
             this.requestCount.set(0);
             addOutboundMsgs(outboundMessages);
             HMsg msgs[] = this.hbaseMaster.regionServerReport(serverInfo,
-                outboundMessages.toArray(EMPTY_HMSG_ARRAY),
-                getMostLoadedRegions());
+              outboundMessages.toArray(HMsg.EMPTY_HMSG_ARRAY),
+              getMostLoadedRegions());
             lastMsg = System.currentTimeMillis();
             updateOutboundMsgs(outboundMessages);
             outboundMessages.clear();
-            if (this.quiesced.get() && onlineRegions.size() == 0) {
-              // We've just told the master we're exiting because we aren't
-              // serving any regions. So set the stop bit and exit.
-              stop("Server quiesced and not serving any regions. " +
-                "Starting shutdown");
-              this.outboundMsgs.clear();
-              continue;
-            }
 
             // Queue up the HMaster's instruction stream for processing
             boolean restart = false;
@@ -474,22 +489,6 @@ public class HRegionServer implements HR
               this.connection.unsetRootRegionLocation();
               switch (msgs[i].getType()) {
 
-                case MSG_REGIONSERVER_STOP:
-                  stop("MSG_REGIONSERVER_STOP");
-                  break;
-
-                case MSG_REGIONSERVER_QUIESCE:
-                  if (!quiesceRequested) {
-                    try {
-                      toDo.put(new ToDoEntry(msgs[i]));
-                    } catch (InterruptedException e) {
-                      throw new RuntimeException("Putting into msgQueue was "
-                          + "interrupted.", e);
-                    }
-                    quiesceRequested = true;
-                  }
-                  break;
-
                 default:
                   if (fsOk) {
                     try {
@@ -575,47 +574,14 @@ public class HRegionServer implements HR
       // Just skip out w/o closing regions.
     } else if (abortRequested) {
       if (this.fsOk) {
-        // Only try to clean up if the file system is available
-        try {
-          if (this.hlog != null) {
-            this.hlog.close();
-            LOG.info("On abort, closed hlog");
-          }
-        } catch (Throwable e) {
-          LOG.error("Unable to close log in abort", RemoteExceptionHandler
-              .checkThrowable(e));
-        }
+        closeWAL(false);
         closeAllRegions(); // Don't leave any open file handles
       }
       LOG.info("aborting server at: " + this.serverInfo.getServerName());
     } else {
-      ArrayList<HRegion> closedRegions = closeAllRegions();
-      try {
-        if (this.hlog != null) {
-          hlog.closeAndDelete();
-        }
-      } catch (Throwable e) {
-        LOG.error("Close and delete failed", RemoteExceptionHandler
-            .checkThrowable(e));
-      }
-      try {
-        HMsg[] exitMsg = new HMsg[closedRegions.size() + 1];
-        exitMsg[0] = REPORT_EXITING;
-        // Tell the master what regions we are/were serving
-        int i = 1;
-        for (HRegion region : closedRegions) {
-          exitMsg[i++] = new HMsg(HMsg.Type.MSG_REPORT_CLOSE, region
-              .getRegionInfo());
-        }
-
-        LOG.info("telling master that region server is shutting down at: "
-            + serverInfo.getServerName());
-        hbaseMaster.regionServerReport(serverInfo, exitMsg,
-            (HRegionInfo[]) null);
-      } catch (Throwable e) {
-        LOG.warn("Failed to send exiting message to master: ",
-            RemoteExceptionHandler.checkThrowable(e));
-      }
+      closeAllRegions();
+      closeWAL(true);
+      closeAllScanners();
       LOG.info("stopping server at: " + this.serverInfo.getServerName());
     }
 
@@ -633,6 +599,32 @@ public class HRegionServer implements HR
     LOG.info(Thread.currentThread().getName() + " exiting");
   }
 
+  private void closeWAL(final boolean delete) {
+    try {
+      if (this.hlog != null) {
+        if (delete) {
+          hlog.closeAndDelete();
+        } else {
+          hlog.close();
+        }
+      }
+    } catch (Throwable e) {
+      LOG.error("Close and delete failed", RemoteExceptionHandler.checkThrowable(e));
+    }
+  }
+
+  private void closeAllScanners() {
+    // Close any outstanding scanners. Means they'll get an UnknownScanner
+    // exception next time they come in.
+    for (Map.Entry<String, InternalScanner> e : this.scanners.entrySet()) {
+      try {
+        e.getValue().close();
+      } catch (IOException ioe) {
+        LOG.warn("Closing scanner " + e.getKey(), ioe);
+      }
+    }
+  }
+
   /*
    * Add to the passed <code>msgs</code> messages to pass to the master.
    *
@@ -1229,7 +1221,7 @@ public class HRegionServer implements HR
   void reportSplit(HRegionInfo oldRegion, HRegionInfo newRegionA,
       HRegionInfo newRegionB) {
     this.outboundMsgs.add(new HMsg(
-        HMsg.Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS, oldRegion, newRegionA,
+        HMsg.Type.REGION_SPLIT, oldRegion, newRegionA,
         newRegionB, Bytes.toBytes("Daughters; "
             + newRegionA.getRegionNameAsString() + ", "
             + newRegionB.getRegionNameAsString())));
@@ -1277,11 +1269,7 @@ public class HRegionServer implements HR
             HRegionInfo info = e.msg.getRegionInfo();
             switch (e.msg.getType()) {
 
-              case MSG_REGIONSERVER_QUIESCE:
-                closeUserRegions();
-                break;
-
-              case MSG_REGION_SPLIT:
+              case SPLIT_REGION:
                 region = getRegion(info.getRegionName());
                 region.flushcache();
                 region.shouldSplit(true);
@@ -1290,25 +1278,25 @@ public class HRegionServer implements HR
                     .name());
                 break;
 
-              case MSG_REGION_MAJOR_COMPACT:
-              case MSG_REGION_COMPACT:
+              case MAJOR_COMPACTION:
+              case COMPACT_REGION:
                 // Compact a region
                 region = getRegion(info.getRegionName());
                 compactSplitThread.requestCompaction(region, e.msg
-                    .isType(Type.MSG_REGION_MAJOR_COMPACT), e.msg.getType()
+                    .isType(Type.MAJOR_COMPACTION), e.msg.getType()
                     .name());
                 break;
 
-              case MSG_REGION_FLUSH:
+              case FLUSH_REGION:
                 region = getRegion(info.getRegionName());
                 region.flushcache();
                 break;
 
-              case TESTING_MSG_BLOCK_RS:
+              case TESTING_BLOCK_REGIONSERVER:
                 while (!stopped) {
                   Threads.sleep(1000);
                   LOG.info("Regionserver blocked by "
-                      + HMsg.Type.TESTING_MSG_BLOCK_RS + "; " + stopped);
+                      + HMsg.Type.TESTING_BLOCK_REGIONSERVER + "; " + stopped);
                 }
                 break;
 
@@ -1353,31 +1341,20 @@ public class HRegionServer implements HR
 
   /** Called either when the master tells us to restart or from stop() */
   ArrayList<HRegion> closeAllRegions() {
-    ArrayList<HRegion> regionsToClose = new ArrayList<HRegion>();
+    List<HRegion> closedRegions = new ArrayList<HRegion>();
+    closedRegions.addAll(closeUserRegions());
+    ArrayList<HRegion> remainingRegionsToClose = new ArrayList<HRegion>();
     this.lock.writeLock().lock();
     try {
-      regionsToClose.addAll(onlineRegions.values());
-      onlineRegions.clear();
+      remainingRegionsToClose.addAll(onlineRegions.values());
     } finally {
       this.lock.writeLock().unlock();
     }
-    // Close any outstanding scanners. Means they'll get an UnknownScanner
-    // exception next time they come in.
-    for (Map.Entry<String, InternalScanner> e : this.scanners.entrySet()) {
-      try {
-        e.getValue().close();
-      } catch (IOException ioe) {
-        LOG.warn("Closing scanner " + e.getKey(), ioe);
-      }
+    closeRegions(remainingRegionsToClose);
+    if (!this.onlineRegions.isEmpty()) {
+      LOG.warn("Online regions is not empty: " + this.onlineRegions);
     }
-    for (HRegion region : regionsToClose) {
-      try {
-        new CloseRegionHandler(this, region.getRegionInfo(), abortRequested).execute();
-      } catch (Throwable e) {
-        cleanup(e, "Error closing " + Bytes.toString(region.getRegionName()));
-      }
-    }
-    return regionsToClose;
+    return remainingRegionsToClose;
   }
 
   /*
@@ -1406,13 +1383,13 @@ public class HRegionServer implements HR
   }
 
   /** Called as the first stage of cluster shutdown. */
-  void closeUserRegions() {
+  List<HRegion> closeUserRegions() {
     ArrayList<HRegion> regionsToClose = new ArrayList<HRegion>();
     this.lock.writeLock().lock();
     try {
       synchronized (onlineRegions) {
-        for (Iterator<Map.Entry<String, HRegion>> i = onlineRegions.entrySet()
-            .iterator(); i.hasNext();) {
+        for (Iterator<Map.Entry<String, HRegion>> i = onlineRegions.entrySet().iterator();
+            i.hasNext();) {
           Map.Entry<String, HRegion> e = i.next();
           HRegion r = e.getValue();
           if (!r.getRegionInfo().isMetaRegion()) {
@@ -1424,10 +1401,14 @@ public class HRegionServer implements HR
     } finally {
       this.lock.writeLock().unlock();
     }
+    return closeRegions(regionsToClose);
+  }
+
+  List<HRegion> closeRegions(final List<HRegion> regions) {
     // Run region closes in parallel.
     Set<Thread> threads = new HashSet<Thread>();
     try {
-      for (final HRegion r : regionsToClose) {
+      for (final HRegion r : regions) {
         RegionCloserThread t = new RegionCloserThread(r);
         t.start();
         threads.add(t);
@@ -1443,12 +1424,7 @@ public class HRegionServer implements HR
         }
       }
     }
-    this.quiesced.set(true);
-    if (onlineRegions.size() == 0) {
-      outboundMsgs.add(REPORT_EXITING);
-    } else {
-      outboundMsgs.add(REPORT_QUIESCED);
-    }
+    return regions;
   }
 
   //
@@ -1928,7 +1904,7 @@ public class HRegionServer implements HR
   @Override
   public boolean closeRegion(HRegionInfo region)
       throws NotServingRegionException {
-    LOG.info("Received request to close region: "
+    LOG.info("Received close region: "
         + region.getRegionNameAsString());
     // TODO: Need to check if this is being served here but currently undergoing
     // a split (so master needs to retry close after split is complete)

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseMetaHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseMetaHandler.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseMetaHandler.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseMetaHandler.java Mon Aug 16 05:04:31 2010
@@ -30,6 +30,6 @@ import org.apache.hadoop.hbase.regionser
 public class CloseMetaHandler extends CloseRegionHandler {
   public CloseMetaHandler(RegionServer server,
       HRegionInfo regionInfo) {
-    super(server, regionInfo, false, EventType.M2RS_CLOSE_META);
+    super(server, regionInfo, false, true, EventType.M2RS_CLOSE_META);
   }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java Mon Aug 16 05:04:31 2010
@@ -38,28 +38,47 @@ import org.apache.zookeeper.KeeperExcept
 public class CloseRegionHandler extends EventHandler {
   private static final Log LOG = LogFactory.getLog(CloseRegionHandler.class);
 
+  private final int FAILED = -1;
+
   private final RegionServer server;
 
   private final HRegionInfo regionInfo;
 
+  // If true, the hosting server is aborting.  Region close process is different
+  // when we are aborting.
   private final boolean abort;
 
+  // Update zk on closing transitions. Usually true.  Its false if cluster
+  // is going down.  In this case, its the rs that initiates the region
+  // close -- not the master process so state up in zk will unlikely be
+  // CLOSING.
+  private final boolean zk;
+
   public CloseRegionHandler(RegionServer server,
       HRegionInfo regionInfo) {
-    this(server, regionInfo, false);
+    this(server, regionInfo, false, true);
   }
 
-  public CloseRegionHandler(RegionServer server,
-      HRegionInfo regionInfo, boolean abort) {
-    this(server, regionInfo, abort, EventType.M2RS_CLOSE_REGION);
+  /**
+   * This method used internally by the RegionServer to close out regions.
+   * @param server
+   * @param regionInfo
+   * @param abort If the regionserver is aborting.
+   * @param zk If the close should be noted out in zookeeper.
+   */
+  public CloseRegionHandler(final RegionServer server,
+      final HRegionInfo regionInfo, final boolean abort, final boolean zk) {
+    this(server, regionInfo, abort, zk, EventType.M2RS_CLOSE_REGION);
   }
 
   protected CloseRegionHandler(RegionServer server,
-      HRegionInfo regionInfo, boolean abort, EventType eventType) {
+      HRegionInfo regionInfo, boolean abort, final boolean zk,
+      EventType eventType) {
     super(server, eventType);
     this.server = server;
     this.regionInfo = regionInfo;
     this.abort = abort;
+    this.zk = zk;
   }
 
   public HRegionInfo getRegionInfo() {
@@ -73,24 +92,15 @@ public class CloseRegionHandler extends 
     String encodedRegionName = regionInfo.getEncodedName();
     // Check that this region is being served here
     HRegion region = server.getFromOnlineRegions(encodedRegionName);
-    if(region == null) {
+    if (region == null) {
       LOG.warn("Received CLOSE for region " + name + " but currently not serving");
       return;
     }
 
-    // Create ZK node in CLOSING state
-    int expectedVersion;
-    try {
-      if((expectedVersion = ZKAssign.createNodeClosing(server.getZooKeeper(),
-          regionInfo, server.getServerName())) == -1) {
-        LOG.warn("Error creating node in CLOSING state, aborting close of " +
-            regionInfo.getRegionNameAsString());
-        return;
-      }
-    } catch (KeeperException e) {
-      LOG.warn("Error creating node in CLOSING state, aborting close of " +
-          regionInfo.getRegionNameAsString());
-      return;
+    int expectedVersion = FAILED;
+    if (this.zk) {
+      expectedVersion = setClosingState();
+      if (expectedVersion == FAILED) return;
     }
 
     // Close the region
@@ -100,21 +110,24 @@ public class CloseRegionHandler extends 
       server.removeFromOnlineRegions(regionInfo.getEncodedName());
       region.close(abort);
     } catch (IOException e) {
-      LOG.error("IOException closing region for " + regionInfo +
-        "; deleting transition node that was in CLOSING");
-      try {
-        ZKAssign.deleteClosingNode(server.getZooKeeper(), encodedRegionName);
-      } catch (KeeperException e1) {
-        LOG.error("Error deleting CLOSING node");
-        return;
-      }
-      return;
+      LOG.error("IOException closing region for " + regionInfo);
+      if (this.zk) deleteClosingState();
     }
 
-    // Transition ZK node to CLOSED
+    if (this.zk) setClosedState(expectedVersion, region);
+
+    // Done!  Successful region open
+    LOG.debug("Closed region " + region.getRegionNameAsString());
+  }
+
+  /**
+   * Transition ZK node to CLOSED
+   * @param expectedVersion
+   */
+  private void setClosedState(final int expectedVersion, final HRegion region) {
     try {
       if(ZKAssign.transitionNodeClosed(server.getZooKeeper(), regionInfo,
-          server.getServerName(), expectedVersion) == -1) {
+          server.getServerName(), expectedVersion) == FAILED) {
         LOG.warn("Completed the CLOSE of a region but when transitioning from " +
             " CLOSING to CLOSED got a version mismatch, someone else clashed " +
             "so now unassigning");
@@ -128,8 +141,36 @@ public class CloseRegionHandler extends 
       LOG.error("Failed to close region after failing to transition", e);
       return;
     }
+  }
 
-    // Done!  Successful region open
-    LOG.debug("Closed region " + region.getRegionNameAsString());
+  /**
+   * @return True if succeeded, false otherwise.
+   */
+  private void deleteClosingState() {
+    try {
+      ZKAssign.deleteClosingNode(server.getZooKeeper(),
+          this.regionInfo.getEncodedName()); 
+    } catch (KeeperException e1) {
+      LOG.error("Error deleting CLOSING node");
+    }
+  }
+
+  /**
+   * Create ZK node in CLOSING state.
+   * @return The expectedVersion.  If -1, we failed setting CLOSING.
+   */
+  private int setClosingState() {
+    int expectedVersion = FAILED;
+    try {
+      if ((expectedVersion = ZKAssign.createNodeClosing(
+          server.getZooKeeper(), regionInfo, server.getServerName())) == FAILED) {
+        LOG.warn("Error creating node in CLOSING state, aborting close of "
+            + regionInfo.getRegionNameAsString());
+      }
+    } catch (KeeperException e) {
+      LOG.warn("Error creating node in CLOSING state, aborting close of "
+          + regionInfo.getRegionNameAsString());
+    }
+    return expectedVersion;
   }
-}
+}
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRootHandler.java Mon Aug 16 05:04:31 2010
@@ -30,6 +30,6 @@ import org.apache.hadoop.hbase.regionser
 public class CloseRootHandler extends CloseRegionHandler {
   public CloseRootHandler(RegionServer server,
       HRegionInfo regionInfo) {
-    super(server, regionInfo, false, EventType.M2RS_CLOSE_ROOT);
+    super(server, regionInfo, false, true, EventType.M2RS_CLOSE_ROOT);
   }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/Merge.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/Merge.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/Merge.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/Merge.java Mon Aug 16 05:04:31 2010
@@ -277,9 +277,9 @@ public class Merge extends Configured im
     }
     HRegion merged = null;
     HLog log = utils.getLog();
-    HRegion r1 = HRegion.openHRegion(info1, this.rootdir, log, getConf());
+    HRegion r1 = HRegion.openHRegion(info1, log, getConf());
     try {
-      HRegion r2 = HRegion.openHRegion(info2, this.rootdir, log, getConf());
+      HRegion r2 = HRegion.openHRegion(info2, log, getConf());
       try {
         merged = HRegion.merge(r1, r2);
       } finally {

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/util/MetaUtils.java Mon Aug 16 05:04:31 2010
@@ -266,15 +266,14 @@ public class MetaUtils {
     if (this.rootRegion != null) {
       return this.rootRegion;
     }
-    this.rootRegion = HRegion.openHRegion(HRegionInfo.ROOT_REGIONINFO,
-      this.rootdir, getLog(), this.conf);
+    this.rootRegion = HRegion.openHRegion(HRegionInfo.ROOT_REGIONINFO, getLog(),
+      this.conf);
     this.rootRegion.compactStores();
     return this.rootRegion;
   }
 
   private HRegion openMetaRegion(HRegionInfo metaInfo) throws IOException {
-    HRegion meta =
-      HRegion.openHRegion(metaInfo, this.rootdir, getLog(), this.conf);
+    HRegion meta = HRegion.openHRegion(metaInfo, getLog(), this.conf);
     meta.compactStores();
     return meta;
   }

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java Mon Aug 16 05:04:31 2010
@@ -28,8 +28,6 @@ import org.apache.zookeeper.KeeperExcept
 public class ClusterStatusTracker extends ZooKeeperNodeTracker {
   private static final Log LOG = LogFactory.getLog(ClusterStatusTracker.class);
 
-  public static final byte [] upData = Bytes.toBytes("up");
-
   /**
    * Creates a cluster status tracker.
    *
@@ -56,6 +54,7 @@ public class ClusterStatusTracker extend
    */
   public void setClusterUp()
   throws KeeperException {
+    byte [] upData = Bytes.toBytes(new java.util.Date().toString());
     try {
       ZKUtil.createAndWatch(watcher, watcher.clusterStateZNode, upData);
     } catch(KeeperException.NodeExistsException nee) {
@@ -64,7 +63,7 @@ public class ClusterStatusTracker extend
   }
 
   /**
-   * Sets the cluster as down.
+   * Sets the cluster as down by deleting the znode.
    * @throws KeeperException unexpected zk exception
    */
   public void setClusterDown()
@@ -76,4 +75,4 @@ public class ClusterStatusTracker extend
           "state node (" + watcher.clusterStateZNode + ") not found");
     }
   }
-}
+}
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionServerTracker.java Mon Aug 16 05:04:31 2010
@@ -51,6 +51,7 @@ public class RegionServerTracker extends
     this.abortable = abortable;
     this.serverManager = serverManager;
   }
+
   /**
    * Starts the tracking of online RegionServers.
    *

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestHMsg.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestHMsg.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestHMsg.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestHMsg.java Mon Aug 16 05:04:31 2010
@@ -35,7 +35,7 @@ public class TestHMsg extends TestCase {
     final int size = 10;
     for (int i = 0; i < size; i++) {
       byte [] b = Bytes.toBytes(i);
-      hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+      hmsg = new HMsg(HMsg.Type.FLUSH_REGION,
         new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
       msgs.add(hmsg);
     }
@@ -45,12 +45,12 @@ public class TestHMsg extends TestCase {
     msgs.remove(index);
     assertEquals(size - 1, msgs.size());
     byte [] other = Bytes.toBytes("other");
-    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+    hmsg = new HMsg(HMsg.Type.FLUSH_REGION,
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), other, other));
     assertEquals(-1, msgs.indexOf(hmsg));
     // Assert that two HMsgs are same if same content.
     byte [] b = Bytes.toBytes(1);
-    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+    hmsg = new HMsg(HMsg.Type.FLUSH_REGION,
      new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
     assertNotSame(-1, msgs.indexOf(hmsg));
   }
@@ -64,7 +64,7 @@ public class TestHMsg extends TestCase {
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("parent")),
       parentbytes, parentbytes);
     // Assert simple HMsg serializes
-    HMsg hmsg = new HMsg(HMsg.Type.MSG_REGION_CLOSE, parent);
+    HMsg hmsg = new HMsg(HMsg.Type.CLOSE_ALL_USER_REGIONS, parent);
     byte [] bytes = Writables.getBytes(hmsg);
     HMsg close = (HMsg)Writables.getWritable(bytes, new HMsg());
     assertTrue(close.equals(hmsg));
@@ -73,7 +73,7 @@ public class TestHMsg extends TestCase {
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("a")), abytes, abytes);
     HRegionInfo daughterb =
       new HRegionInfo(new HTableDescriptor(Bytes.toBytes("b")), bbytes, bbytes);
-    HMsg splithmsg = new HMsg(HMsg.Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS,
+    HMsg splithmsg = new HMsg(HMsg.Type.SPLIT_REGION,
       parent, daughtera, daughterb, Bytes.toBytes("split"));
     bytes = Writables.getBytes(splithmsg);
     hmsg = (HMsg)Writables.getWritable(bytes, new HMsg());

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestSerialization.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestSerialization.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestSerialization.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestSerialization.java Mon Aug 16 05:04:31 2010
@@ -91,11 +91,11 @@ public class TestSerialization extends H
   }
 
   public void testHMsg() throws Exception {
-    HMsg  m = new HMsg(HMsg.Type.MSG_REGIONSERVER_QUIESCE);
+    HMsg  m = new HMsg(HMsg.Type.CLOSE_ALL_USER_REGIONS);
     byte [] mb = Writables.getBytes(m);
     HMsg deserializedHMsg = (HMsg)Writables.getWritable(mb, new HMsg());
     assertTrue(m.equals(deserializedHMsg));
-    m = new HMsg(HMsg.Type.MSG_REGIONSERVER_QUIESCE,
+    m = new HMsg(HMsg.Type.CLOSE_ALL_USER_REGIONS,
       new HRegionInfo(new HTableDescriptor(getName()),
         HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY),
         "Some message".getBytes());

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java Mon Aug 16 05:04:31 2010
@@ -413,7 +413,7 @@ public class TestMasterTransitions {
       // After all closes, add blocking message before the region opens start to
       // come in.
       cluster.addMessageToSendRegionServer(hrs,
-        new HMsg(HMsg.Type.TESTING_MSG_BLOCK_RS));
+        new HMsg(HMsg.Type.TESTING_BLOCK_REGIONSERVER));
       // Wait till one of the above close messages has an effect before we start
       // wait on all regions back online.
       while (!listener.closed) Threads.sleep(100);

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestMasterWithDisabling.java Mon Aug 16 05:04:31 2010
@@ -98,7 +98,7 @@ public class TestMasterWithDisabling {
 
     @Override
     public boolean process(HServerInfo serverInfo, HMsg incomingMsg) {
-      if (!incomingMsg.isType(HMsg.Type.MSG_REPORT_SPLIT_INCLUDES_DAUGHTERS)) {
+      if (!incomingMsg.isType(HMsg.Type.SPLIT)) {
         return true;
       }
       try {

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java?rev=985786&r1=985785&r2=985786&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java Mon Aug 16 05:04:31 2010
@@ -181,8 +181,7 @@ public class TestMergeTool extends HBase
 
     // Now verify that we can read all the rows from regions 0, 1
     // in the new merged region.
-    HRegion merged =
-      HRegion.openHRegion(mergedInfo, this.testDir, log, this.conf);
+    HRegion merged = HRegion.openHRegion(mergedInfo, log, this.conf);
     verifyMerge(merged, upperbound);
     merged.close();
     LOG.info("Verified " + msg);