hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject svn commit: r1366438 [2/3] - in /hbase/trunk/hbase-server/src: main/jamon/org/apache/hadoop/hbase/tmpl/master/ main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/h...
Date Fri, 27 Jul 2012 16:34:34 GMT
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri Jul 27 16:34:32 2012
@@ -29,7 +29,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -55,10 +54,14 @@ import org.apache.hadoop.hbase.HColumnDe
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MasterAdminProtocol;
+import org.apache.hadoop.hbase.MasterMonitorProtocol;
 import org.apache.hadoop.hbase.MasterNotRunningException;
 import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
 import org.apache.hadoop.hbase.PleaseHoldException;
+import org.apache.hadoop.hbase.RegionServerStatusProtocol;
 import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.ServerLoad;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableDescriptors;
 import org.apache.hadoop.hbase.TableNotDisabledException;
@@ -77,12 +80,6 @@ import org.apache.hadoop.hbase.executor.
 import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType;
 import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.ipc.HBaseServer;
-import org.apache.hadoop.hbase.MasterMonitorProtocol;
-import org.apache.hadoop.hbase.MasterAdminProtocol;
-import org.apache.hadoop.hbase.RegionServerStatusProtocol;
-import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.RequestConverter;
-import org.apache.hadoop.hbase.protobuf.ResponseConverter;
 import org.apache.hadoop.hbase.ipc.ProtocolSignature;
 import org.apache.hadoop.hbase.ipc.RpcServer;
 import org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory;
@@ -102,40 +99,17 @@ import org.apache.hadoop.hbase.master.me
 import org.apache.hadoop.hbase.monitoring.MemoryBoundedLogMessageBuffer;
 import org.apache.hadoop.hbase.monitoring.MonitoredTask;
 import org.apache.hadoop.hbase.monitoring.TaskMonitor;
-import org.apache.hadoop.hbase.replication.regionserver.Replication;
-import org.apache.hadoop.hbase.security.User;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.CompressionTest;
-import org.apache.hadoop.hbase.util.FSTableDescriptors;
-import org.apache.hadoop.hbase.util.FSUtils;
-import org.apache.hadoop.hbase.util.HFileArchiveUtil;
-import org.apache.hadoop.hbase.util.HasThread;
-import org.apache.hadoop.hbase.util.InfoServer;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.hbase.util.Sleeper;
-import org.apache.hadoop.hbase.util.Strings;
-import org.apache.hadoop.hbase.util.Threads;
-import org.apache.hadoop.hbase.util.VersionInfo;
-import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
-import org.apache.hadoop.hbase.zookeeper.ClusterStatusTracker;
-import org.apache.hadoop.hbase.zookeeper.DrainingServerTracker;
-import org.apache.hadoop.hbase.zookeeper.RegionServerTracker;
-import org.apache.hadoop.hbase.zookeeper.ZKUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
-import org.apache.hadoop.metrics.util.MBeanUtil;
-import org.apache.hadoop.net.DNS;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.Watcher;
-import org.apache.hadoop.hbase.ServerLoad;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.ResponseConverter;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
-import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
-import com.google.protobuf.RpcController;
-
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AddColumnRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AddColumnResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AssignRegionRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AssignRegionResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.BalanceRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.BalanceResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.CatalogScanRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.CatalogScanResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.CreateTableRequest;
@@ -152,10 +126,6 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.EnableTableResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.IsCatalogJanitorEnabledRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.IsCatalogJanitorEnabledResponse;
-import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetSchemaAlterStatusRequest;
-import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetSchemaAlterStatusResponse;
-import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsRequest;
-import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.ModifyColumnRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.ModifyColumnResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.ModifyTableRequest;
@@ -164,26 +134,53 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.MoveRegionResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.OfflineRegionRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.OfflineRegionResponse;
-import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.UnassignRegionRequest;
-import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.UnassignRegionResponse;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerReportResponse;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorRequest;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorResponse;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;
-import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse;
-import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.BalanceRequest;
-import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.BalanceResponse;
-import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
-import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.SetBalancerRunningRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.SetBalancerRunningResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.ShutdownRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.ShutdownResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.StopMasterRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.StopMasterResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.UnassignRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.UnassignRegionResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetClusterStatusRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetClusterStatusResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetSchemaAlterStatusRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetSchemaAlterStatusResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningResponse;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerReportResponse;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorRequest;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.ReportRSFatalErrorResponse;
+import org.apache.hadoop.hbase.replication.regionserver.Replication;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CompressionTest;
+import org.apache.hadoop.hbase.util.FSTableDescriptors;
+import org.apache.hadoop.hbase.util.HFileArchiveUtil;
+import org.apache.hadoop.hbase.util.HasThread;
+import org.apache.hadoop.hbase.util.InfoServer;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.Sleeper;
+import org.apache.hadoop.hbase.util.Strings;
+import org.apache.hadoop.hbase.util.Threads;
+import org.apache.hadoop.hbase.util.VersionInfo;
+import org.apache.hadoop.hbase.zookeeper.ClusterStatusTracker;
+import org.apache.hadoop.hbase.zookeeper.DrainingServerTracker;
+import org.apache.hadoop.hbase.zookeeper.RegionServerTracker;
+import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.metrics.util.MBeanUtil;
+import org.apache.hadoop.net.DNS;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Watcher;
+
+import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
 
 /**
@@ -205,6 +202,7 @@ import com.google.protobuf.ServiceExcept
  * @see Watcher
  */
 @InterfaceAudience.Private
+@SuppressWarnings("deprecation")
 public class HMaster extends HasThread
 implements MasterMonitorProtocol, MasterAdminProtocol, RegionServerStatusProtocol, MasterServices,
 Server {
@@ -505,7 +503,7 @@ Server {
 
     this.balancer = LoadBalancerFactory.getLoadBalancer(conf);
     this.assignmentManager = new AssignmentManager(this, serverManager,
-        this.catalogTracker, this.balancer, this.executorService, this.metrics);
+      this.catalogTracker, this.balancer, this.executorService, this.metrics);
     zooKeeper.registerListenerFirst(assignmentManager);
 
     this.regionServerTracker = new RegionServerTracker(zooKeeper, this,
@@ -649,7 +647,7 @@ Server {
       }
     }
 
-    if (!masterRecovery) {      
+    if (!masterRecovery) {
       this.assignmentManager.startTimeOutMonitor();
     }
     // TODO: Should do this in background rather than block master startup
@@ -768,6 +766,8 @@ Server {
 
     // Work on ROOT region.  Is it in zk in transition?
     status.setStatus("Assigning ROOT region");
+    assignmentManager.getRegionStates().createRegionState(
+      HRegionInfo.ROOT_REGIONINFO);
     boolean rit = this.assignmentManager.
       processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.ROOT_REGIONINFO);
     ServerName currentRootServer = null;
@@ -802,6 +802,8 @@ Server {
 
     // Work on meta region
     status.setStatus("Assigning META region");
+    assignmentManager.getRegionStates().createRegionState(
+      HRegionInfo.FIRST_META_REGIONINFO);
     rit = this.assignmentManager.
       processRegionInTransitionAndBlockUntilAssigned(HRegionInfo.FIRST_META_REGIONINFO);
     boolean metaRegionLocation = this.catalogTracker.verifyMetaRegionLocation(timeout);
@@ -1228,12 +1230,12 @@ Server {
     boolean balancerRan;
     synchronized (this.balancer) {
       // Only allow one balance run at at time.
-      if (this.assignmentManager.isRegionsInTransition()) {
-        LOG.debug("Not running balancer because " +
-          this.assignmentManager.getRegionsInTransition().size() +
-          " region(s) in transition: " +
-          org.apache.commons.lang.StringUtils.
-            abbreviate(this.assignmentManager.getRegionsInTransition().toString(), 256));
+      if (this.assignmentManager.getRegionStates().isRegionsInTransition()) {
+        Map<String, RegionState> regionsInTransition =
+          this.assignmentManager.getRegionStates().getRegionsInTransition();
+        LOG.debug("Not running balancer because " + regionsInTransition.size() +
+          " region(s) in transition: " + org.apache.commons.lang.StringUtils.
+            abbreviate(regionsInTransition.toString(), 256));
         return false;
       }
       if (this.serverManager.areDeadServersInProgress()) {
@@ -1255,7 +1257,7 @@ Server {
       }
 
       Map<String, Map<ServerName, List<HRegionInfo>>> assignmentsByTable =
-        this.assignmentManager.getAssignmentsByTable();
+        this.assignmentManager.getRegionStates().getAssignmentsByTable();
 
       List<RegionPlan> plans = new ArrayList<RegionPlan>();
       //Give the balancer the current cluster state.
@@ -1373,23 +1375,24 @@ Server {
       LOG.warn("moveRegion specifier type: expected: " + RegionSpecifierType.ENCODED_REGION_NAME
         + " actual: " + type);
     }
-    Pair<HRegionInfo, ServerName> p =
-	  this.assignmentManager.getAssignment(encodedRegionName);
-    if (p == null) {
-	  throw new ServiceException(
+    RegionState regionState = assignmentManager.getRegionStates().
+      getRegionState(Bytes.toString(encodedRegionName));
+    if (regionState == null) {
+      throw new ServiceException(
         new UnknownRegionException(Bytes.toStringBinary(encodedRegionName)));
     }
-    HRegionInfo hri = p.getFirst();
+
+    HRegionInfo hri = regionState.getRegion();
     ServerName dest;
     if (destServerName == null || destServerName.length == 0) {
       LOG.info("Passed destination servername is null/empty so " +
         "choosing a server at random");
       final List<ServerName> destServers = this.serverManager.createDestinationServersList(
-        p.getSecond());
+        regionState.getServerName());
       dest = balancer.randomAssignment(hri, destServers);
     } else {
       dest = new ServerName(Bytes.toString(destServerName));
-      if (dest.equals(p.getSecond())) {
+      if (dest.equals(regionState.getServerName())) {
         LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
           + " because region already assigned to the same server " + dest + ".");
         return mrr;
@@ -1397,7 +1400,7 @@ Server {
     }
 
     // Now we can do the move
-    RegionPlan rp = new RegionPlan(p.getFirst(), p.getSecond(), dest);
+    RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);
 
     try {
       if (this.cpHost != null) {
@@ -1729,12 +1732,6 @@ Server {
     }
   }
 
-  public void clearFromTransition(HRegionInfo hri) {
-    if (this.assignmentManager.isRegionInTransition(hri) != null) {
-      this.assignmentManager.regionOffline(hri);
-    }
-  }
-
   @Override
   public GetClusterStatusResponse getClusterStatus(RpcController controller, GetClusterStatusRequest req)
   throws ServiceException {
@@ -1787,7 +1784,7 @@ Server {
       this.serverManager.getDeadServers(),
       this.serverName,
       backupMasters,
-      this.assignmentManager.copyRegionsInTransition(),
+      this.assignmentManager.getRegionStates().getRegionsInTransition(),
       this.getCoprocessors(), this.balanceSwitch);
   }
 
@@ -1952,12 +1949,11 @@ Server {
   public AssignmentManager getAssignmentManager() {
     return this.assignmentManager;
   }
-  
+
   public MemoryBoundedLogMessageBuffer getRegionServerFatalLogBuffer() {
     return rsFatals;
   }
 
-  @SuppressWarnings("deprecation")
   public void shutdown() {
     if (cpHost != null) {
       try {
@@ -2082,17 +2078,16 @@ Server {
         LOG.warn("assignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME
           + " actual: " + type);
       }
-      Pair<HRegionInfo, ServerName> pair =
-        MetaReader.getRegion(this.catalogTracker, regionName);
-      if (pair == null) throw new UnknownRegionException(Bytes.toString(regionName));
+      HRegionInfo regionInfo = assignmentManager.getRegionStates().getRegionInfo(regionName);
+      if (regionInfo == null) throw new UnknownRegionException(Bytes.toString(regionName));
       if (cpHost != null) {
-        if (cpHost.preAssign(pair.getFirst())) {
+        if (cpHost.preAssign(regionInfo)) {
           return arr;
         }
       }
-      assignRegion(pair.getFirst());
+      assignRegion(regionInfo);
      if (cpHost != null) {
-       cpHost.postAssign(pair.getFirst());
+       cpHost.postAssign(regionInfo);
      }
 
      return arr;
@@ -2191,7 +2186,7 @@ Server {
    * @return the average load
    */
   public double getAverageLoad() {
-    return this.assignmentManager.getAverageLoad();
+    return this.assignmentManager.getRegionStates().getAverageLoad();
   }
 
   /**
@@ -2255,7 +2250,6 @@ Server {
   /**
    * Register bean with platform management server
    */
-  @SuppressWarnings("deprecation")
   void registerMBean() {
     MXBeanImpl mxBeanInfo = MXBeanImpl.init(this);
     MBeanUtil.registerMBean("Master", "Master", mxBeanInfo);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java Fri Jul 27 16:34:32 2012
@@ -25,7 +25,6 @@ import java.util.Map.Entry;
 
 import org.apache.hadoop.hbase.ServerLoad;
 import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
 
 /**
  * Impl for exposing HMaster Information through JMX
@@ -99,8 +98,8 @@ public class MXBeanImpl implements MXBea
   public RegionsInTransitionInfo[] getRegionsInTransition() {
     List<RegionsInTransitionInfo> info =
         new ArrayList<RegionsInTransitionInfo>();
-    for (final Entry<String, RegionState> entry :
-      master.getAssignmentManager().copyRegionsInTransition().entrySet()) {
+    for (final Entry<String, RegionState> entry : master.getAssignmentManager()
+        .getRegionStates().getRegionsInTransition().entrySet()) {
       RegionsInTransitionInfo innerinfo = new RegionsInTransitionInfo() {
 
         @Override

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterDumpServlet.java Fri Jul 27 16:34:32 2012
@@ -24,17 +24,14 @@ import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.Date;
 import java.util.Map;
-import java.util.NavigableMap;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HServerInfo;
-import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.ServerLoad;
-import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.monitoring.LogMonitoring;
 import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
 import org.apache.hadoop.hbase.monitoring.TaskMonitor;
@@ -104,8 +101,8 @@ public class MasterDumpServlet extends S
   
 
   private void dumpRIT(HMaster master, PrintWriter out) {
-    NavigableMap<String, RegionState> regionsInTransition =
-      master.getAssignmentManager().copyRegionsInTransition();
+    Map<String, RegionState> regionsInTransition =
+      master.getAssignmentManager().getRegionStates().getRegionsInTransition();
     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
       String rid = e.getKey();
       RegionState rs = e.getValue();

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java Fri Jul 27 16:34:32 2012
@@ -25,9 +25,7 @@ import org.apache.hadoop.classification.
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.TableDescriptors;
-import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.executor.ExecutorService;
-import org.apache.hadoop.hbase.zookeeper.RegionServerTracker;
 
 /**
  * Services Master supplies

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionState.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionState.java?rev=1366438&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionState.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionState.java Fri Jul 27 16:34:32 2012
@@ -0,0 +1,259 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos;
+
+/**
+ * State of a Region while undergoing transitions.
+ * Region state cannot be modified except the stamp field.
+ * So it is almost immutable.
+ */
+@InterfaceAudience.Private
+public class RegionState implements org.apache.hadoop.io.Writable {
+  public enum State {
+    OFFLINE,        // region is in an offline state
+    PENDING_OPEN,   // sent rpc to server to open but has not begun
+    OPENING,        // server has begun to open but not yet done
+    OPEN,           // server opened region and updated meta
+    PENDING_CLOSE,  // sent rpc to server to close but has not begun
+    CLOSING,        // server has begun to close but not yet done
+    CLOSED,         // server closed region and updated meta
+    SPLITTING,      // server started split of a region
+    SPLIT           // server completed split of a region
+  }
+
+  // Many threads can update the state at the stamp at the same time
+  private final AtomicLong stamp;
+  private HRegionInfo region;
+
+  private volatile ServerName serverName;
+  private volatile State state;
+
+  public RegionState() {
+    this.stamp = new AtomicLong(System.currentTimeMillis());
+  }
+
+  public RegionState(HRegionInfo region, State state) {
+    this(region, state, System.currentTimeMillis(), null);
+  }
+
+  public RegionState(HRegionInfo region,
+      State state, long stamp, ServerName serverName) {
+    this.region = region;
+    this.state = state;
+    this.stamp = new AtomicLong(stamp);
+    this.serverName = serverName;
+  }
+
+  public void updateTimestampToNow() {
+    this.stamp.set(System.currentTimeMillis());
+  }
+
+  public State getState() {
+    return state;
+  }
+
+  public long getStamp() {
+    return stamp.get();
+  }
+
+  public HRegionInfo getRegion() {
+    return region;
+  }
+
+  public ServerName getServerName() {
+    return serverName;
+  }
+
+  public boolean isClosing() {
+    return state == State.CLOSING;
+  }
+
+  public boolean isClosed() {
+    return state == State.CLOSED;
+  }
+
+  public boolean isPendingClose() {
+    return state == State.PENDING_CLOSE;
+  }
+
+  public boolean isOpening() {
+    return state == State.OPENING;
+  }
+
+  public boolean isOpened() {
+    return state == State.OPEN;
+  }
+
+  public boolean isPendingOpen() {
+    return state == State.PENDING_OPEN;
+  }
+
+  public boolean isOffline() {
+    return state == State.OFFLINE;
+  }
+
+  public boolean isSplitting() {
+    return state == State.SPLITTING;
+  }
+
+  public boolean isSplit() {
+    return state == State.SPLIT;
+  }
+
+  @Override
+  public String toString() {
+    return "{" + region.getRegionNameAsString()
+      + " state=" + state
+      + ", ts=" + stamp
+      + ", server=" + serverName + "}";
+  }
+
+  /**
+   * A slower (but more easy-to-read) stringification 
+   */
+  public String toDescriptiveString() {
+    long lstamp = stamp.get();
+    long relTime = System.currentTimeMillis() - lstamp;
+    
+    return region.getRegionNameAsString()
+      + " state=" + state
+      + ", ts=" + new Date(lstamp) + " (" + (relTime/1000) + "s ago)"
+      + ", server=" + serverName;
+  }
+
+  /**
+   * Convert a RegionState to an HBaseProtos.RegionState
+   *
+   * @return the converted HBaseProtos.RegionState
+   */
+  public ClusterStatusProtos.RegionState convert() {
+    ClusterStatusProtos.RegionState.Builder regionState = ClusterStatusProtos.RegionState.newBuilder();
+    ClusterStatusProtos.RegionState.State rs;
+    switch (regionState.getState()) {
+    case OFFLINE:
+      rs = ClusterStatusProtos.RegionState.State.OFFLINE;
+      break;
+    case PENDING_OPEN:
+      rs = ClusterStatusProtos.RegionState.State.PENDING_OPEN;
+      break;
+    case OPENING:
+      rs = ClusterStatusProtos.RegionState.State.OPENING;
+      break;
+    case OPEN:
+      rs = ClusterStatusProtos.RegionState.State.OPEN;
+      break;
+    case PENDING_CLOSE:
+      rs = ClusterStatusProtos.RegionState.State.PENDING_CLOSE;
+      break;
+    case CLOSING:
+      rs = ClusterStatusProtos.RegionState.State.CLOSING;
+      break;
+    case CLOSED:
+      rs = ClusterStatusProtos.RegionState.State.CLOSED;
+      break;
+    case SPLITTING:
+      rs = ClusterStatusProtos.RegionState.State.SPLITTING;
+      break;
+    case SPLIT:
+      rs = ClusterStatusProtos.RegionState.State.SPLIT;
+      break;
+    default:
+      throw new IllegalStateException("");
+    }
+    regionState.setRegionInfo(HRegionInfo.convert(region));
+    regionState.setState(rs);
+    regionState.setStamp(getStamp());
+    return regionState.build();
+  }
+
+  /**
+   * Convert a protobuf HBaseProtos.RegionState to a RegionState
+   *
+   * @return the RegionState
+   */
+  public static RegionState convert(ClusterStatusProtos.RegionState proto) {
+    RegionState.State state;
+    switch (proto.getState()) {
+    case OFFLINE:
+      state = State.OFFLINE;
+      break;
+    case PENDING_OPEN:
+      state = State.PENDING_OPEN;
+      break;
+    case OPENING:
+      state = State.OPENING;
+      break;
+    case OPEN:
+      state = State.OPEN;
+      break;
+    case PENDING_CLOSE:
+      state = State.PENDING_CLOSE;
+      break;
+    case CLOSING:
+      state = State.CLOSING;
+      break;
+    case CLOSED:
+      state = State.CLOSED;
+      break;
+    case SPLITTING:
+      state = State.SPLITTING;
+      break;
+    case SPLIT:
+      state = State.SPLIT;
+      break;
+    default:
+      throw new IllegalStateException("");
+    }
+
+    return new RegionState(HRegionInfo.convert(proto.getRegionInfo()),state,proto.getStamp(),null);
+  }
+
+  /**
+   * @deprecated Writables are going away
+   */
+  @Deprecated
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    region = new HRegionInfo();
+    region.readFields(in);
+    state = State.valueOf(in.readUTF());
+    stamp.set(in.readLong());
+  }
+
+  /**
+   * @deprecated Writables are going away
+   */
+  @Deprecated
+  @Override
+  public void write(DataOutput out) throws IOException {
+    region.write(out);
+    out.writeUTF(state.name());
+    out.writeLong(stamp.get());
+  }
+}

Propchange: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java?rev=1366438&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java (added)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java Fri Jul 27 16:34:32 2012
@@ -0,0 +1,529 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.RegionTransition;
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.ServerLoad;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.catalog.MetaReader;
+import org.apache.hadoop.hbase.master.RegionState.State;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+
+/**
+ * Region state accountant. It holds the states of all regions in the memory.
+ * In normal scenario, it should match the meta table and the true region states.
+ *
+ * This map is used by AssignmentManager to track region states.
+ */
+@InterfaceAudience.Private
+public class RegionStates {
+  private static final Log LOG = LogFactory.getLog(RegionStates.class);
+
+  /**
+   * Regions currently in transition.
+   */
+  final HashMap<String, RegionState> regionsInTransition;
+
+  /**
+   * Region encoded name to state map.
+   * All the regions should be in this map.
+   */
+  private final Map<String, RegionState> regionStates;
+
+  /**
+   * Server to regions assignment map.
+   * Contains the set of regions currently assigned to a given server.
+   */
+  private final Map<ServerName, Set<HRegionInfo>> serverHoldings;
+
+  /**
+   * Region to server assignment map.
+   * Contains the server a given region is currently assigned to.
+   */
+  private final TreeMap<HRegionInfo, ServerName> regionAssignments;
+
+  private final ServerManager serverManager;
+  private final Server server;
+
+  RegionStates(final Server master, final ServerManager serverManager) {
+    regionStates = new HashMap<String, RegionState>();
+    regionsInTransition = new HashMap<String, RegionState>();
+    serverHoldings = new HashMap<ServerName, Set<HRegionInfo>>();
+    regionAssignments = new TreeMap<HRegionInfo, ServerName>();
+    this.serverManager = serverManager;
+    this.server = master;
+  }
+
+  /**
+   * @return an unmodifiable the region assignment map
+   */
+  @SuppressWarnings("unchecked")
+  public synchronized Map<HRegionInfo, ServerName> getRegionAssignments() {
+    return (Map<HRegionInfo, ServerName>)regionAssignments.clone();
+  }
+
+  public synchronized ServerName getRegionServerOfRegion(HRegionInfo hri) {
+    return regionAssignments.get(hri);
+  }
+
+  /**
+   * Get regions in transition and their states
+   */
+  @SuppressWarnings("unchecked")
+  public synchronized Map<String, RegionState> getRegionsInTransition() {
+    return (Map<String, RegionState>)regionsInTransition.clone();
+  }
+
+  /**
+   * @return True if specified region in transition.
+   */
+  public synchronized boolean isRegionInTransition(final HRegionInfo hri) {
+    return regionsInTransition.containsKey(hri.getEncodedName());
+  }
+
+  /**
+   * @return True if specified region in transition.
+   */
+  public synchronized boolean isRegionInTransition(final String regionName) {
+    return regionsInTransition.containsKey(regionName);
+  }
+
+  /**
+   * @return True if any region in transition.
+   */
+  public synchronized boolean isRegionsInTransition() {
+    return !regionsInTransition.isEmpty();
+  }
+
+  /**
+   * @return True if specified region assigned.
+   */
+  public synchronized boolean isRegionAssigned(final HRegionInfo hri) {
+    return regionAssignments.containsKey(hri);
+  }
+
+  /**
+   * Wait for the state map to be updated by assignment manager.
+   */
+  public synchronized void waitForUpdate(
+      final long timeout) throws InterruptedException {
+    this.wait(timeout);
+  }
+
+  /**
+   * Get region transition state
+   */
+  public synchronized RegionState
+      getRegionTransitionState(final HRegionInfo hri) {
+    return regionsInTransition.get(hri.getEncodedName());
+  }
+
+  /**
+   * Get region transition state
+   */
+  public synchronized RegionState
+      getRegionTransitionState(final String regionName) {
+    return regionsInTransition.get(regionName);
+  }
+
+  /**
+   * Add a list of regions to RegionStates. The initial state is OFFLINE.
+   * If any region is already in RegionStates, that region will be skipped.
+   */
+  public synchronized void createRegionStates(
+      final List<HRegionInfo> hris) {
+    for (HRegionInfo hri: hris) {
+      createRegionState(hri);
+    }
+  }
+
+  /**
+   * Add a region to RegionStates. The initial state is OFFLINE.
+   * If it is already in RegionStates, this call has no effect,
+   * and the original state is returned.
+   */
+  public synchronized RegionState createRegionState(final HRegionInfo hri) {
+    String regionName = hri.getEncodedName();
+    RegionState regionState = regionStates.get(regionName);
+    if (regionState != null) {
+      LOG.warn("Tried to create a state of a region already in RegionStates "
+        + hri + ", used existing state: " + regionState
+        + ", ignored new state: state=OFFLINE, server=null");
+    } else {
+      regionState = new RegionState(hri, State.OFFLINE);
+      regionStates.put(regionName, regionState);
+    }
+    return regionState;
+  }
+
+  /**
+   * Update a region state. If it is not splitting,
+   * it will be put in transition if not already there.
+   */
+  public synchronized RegionState updateRegionState(
+      final HRegionInfo hri, final State state) {
+    RegionState regionState = regionStates.get(hri.getEncodedName());
+    ServerName serverName = (regionState == null || state == State.CLOSED
+      || state == State.OFFLINE) ? null : regionState.getServerName();
+    return updateRegionState(hri, state, serverName);
+  }
+
+  /**
+   * Update a region state. If it is not splitting,
+   * it will be put in transition if not already there.
+   */
+  public synchronized RegionState updateRegionState(
+      final HRegionInfo hri, final State state, final ServerName serverName) {
+    return updateRegionState(hri, state, System.currentTimeMillis(), serverName);
+  }
+
+  /**
+   * Update a region state. If it is not splitting,
+   * it will be put in transition if not already there.
+   *
+   * If we can't find the region info based on the region name in
+   * the transition, log a warning and return null.
+   */
+  public synchronized RegionState updateRegionState(
+      final RegionTransition transition, final State state) {
+    byte[] regionName = transition.getRegionName();
+    HRegionInfo regionInfo = getRegionInfo(regionName);
+    if (regionInfo == null) {
+      String prettyRegionName = HRegionInfo.prettyPrint(
+        HRegionInfo.encodeRegionName(regionName));
+      LOG.warn("Failed to find region " + prettyRegionName
+        + " in updating its state to " + state
+        + " based on region transition " + transition);
+      return null;
+    }
+    return updateRegionState(regionInfo, state,
+      transition.getCreateTime(), transition.getServerName());
+  }
+
+  /**
+   * Update a region state. If it is not splitting,
+   * it will be put in transition if not already there.
+   */
+  public synchronized RegionState updateRegionState(final HRegionInfo hri,
+      final State state, final long stamp, final ServerName serverName) {
+    ServerName newServerName = serverName;
+    if (serverName != null &&
+        (state == State.CLOSED || state == State.OFFLINE)) {
+      LOG.warn("Closed region " + hri + " still on "
+        + serverName + "? Ignored, reset it to null");
+      newServerName = null;
+    }
+
+    String regionName = hri.getEncodedName();
+    RegionState regionState = new RegionState(hri, state, stamp, newServerName);
+    RegionState oldState = regionStates.put(regionName, regionState);
+    LOG.info("Region " + hri + " transitioned from " + oldState + " to " + regionState);
+    if (state != State.SPLITTING && (newServerName != null
+        || (state != State.PENDING_CLOSE && state != State.CLOSING))) {
+      regionsInTransition.put(regionName, regionState);
+    }
+
+    // notify the change
+    this.notifyAll();
+    return regionState;
+  }
+
+  /**
+   * A region is online, won't be in transition any more.
+   * We can't confirm it is really online on specified region server
+   * because it hasn't been put in region server's online region list yet.
+   */
+  public synchronized void regionOnline(
+      final HRegionInfo hri, final ServerName serverName) {
+    String regionName = hri.getEncodedName();
+    RegionState oldState = regionStates.get(regionName);
+    if (oldState == null) {
+      LOG.warn("Online a region not in RegionStates: " + hri);
+    } else {
+      State state = oldState.getState();
+      ServerName sn = oldState.getServerName();
+      if (state != State.OPEN || sn == null || !sn.equals(serverName)) {
+        LOG.debug("Online a region with current state=" + state + ", expected state=OPEN"
+          + ", assigned to server: " + sn + " expected " + serverName);
+      }
+    }
+    updateRegionState(hri, State.OPEN, serverName);
+    regionsInTransition.remove(regionName);
+
+    ServerName oldServerName = regionAssignments.put(hri, serverName);
+    if (!serverName.equals(oldServerName)) {
+      LOG.info("Onlined region " + hri + " on " + serverName);
+      Set<HRegionInfo> regions = serverHoldings.get(serverName);
+      if (regions == null) {
+        regions = new HashSet<HRegionInfo>();
+        serverHoldings.put(serverName, regions);
+      }
+      regions.add(hri);
+      if (oldServerName != null) {
+        LOG.info("Offlined region " + hri + " from " + oldServerName);
+        serverHoldings.get(oldServerName).remove(hri);
+      }
+    }
+  }
+
+  /**
+   * A region is offline, won't be in transition any more.
+   */
+  public synchronized void regionOffline(final HRegionInfo hri) {
+    String regionName = hri.getEncodedName();
+    RegionState oldState = regionStates.get(regionName);
+    if (oldState == null) {
+      LOG.warn("Offline a region not in RegionStates: " + hri);
+    } else {
+      State state = oldState.getState();
+      ServerName sn = oldState.getServerName();
+      if (state != State.OFFLINE || sn != null) {
+        LOG.debug("Online a region with current state=" + state + ", expected state=OFFLINE"
+          + ", assigned to server: " + sn + ", expected null");
+      }
+    }
+    updateRegionState(hri, State.OFFLINE);
+    regionsInTransition.remove(regionName);
+
+    ServerName oldServerName = regionAssignments.remove(hri);
+    if (oldServerName != null) {
+      LOG.info("Offlined region " + hri + " from " + oldServerName);
+      serverHoldings.get(oldServerName).remove(hri);
+    }
+  }
+
+  /**
+   * A server is offline, all regions on it are dead.
+   */
+  public synchronized List<RegionState> serverOffline(final ServerName sn) {
+    // Clean up this server from map of servers to regions, and remove all regions
+    // of this server from online map of regions.
+    List<RegionState> rits = new ArrayList<RegionState>();
+    Set<HRegionInfo> assignedRegions = serverHoldings.get(sn);
+    if (assignedRegions == null || assignedRegions.isEmpty()) {
+      // No regions on this server, we are done, return empty list of RITs
+      return rits;
+    }
+
+    for (HRegionInfo region : assignedRegions) {
+      regionAssignments.remove(region);
+    }
+
+    // See if any of the regions that were online on this server were in RIT
+    // If they are, normal timeouts will deal with them appropriately so
+    // let's skip a manual re-assignment.
+    for (RegionState state : regionsInTransition.values()) {
+      if (assignedRegions.contains(state.getRegion())) {
+        rits.add(state);
+      }
+    }
+    assignedRegions.clear();
+    this.notifyAll();
+    return rits;
+  }
+
+  /**
+   * Gets the online regions of the specified table.
+   * This method looks at the in-memory state.  It does not go to <code>.META.</code>.
+   * Only returns <em>online</em> regions.  If a region on this table has been
+   * closed during a disable, etc., it will be included in the returned list.
+   * So, the returned list may not necessarily be ALL regions in this table, its
+   * all the ONLINE regions in the table.
+   * @param tableName
+   * @return Online regions from <code>tableName</code>
+   */
+  public synchronized List<HRegionInfo> getRegionsOfTable(byte[] tableName) {
+    List<HRegionInfo> tableRegions = new ArrayList<HRegionInfo>();
+    // boundary needs to have table's name but regionID 0 so that it is sorted
+    // before all table's regions.
+    HRegionInfo boundary = new HRegionInfo(tableName, null, null, false, 0L);
+    for (HRegionInfo hri: regionAssignments.tailMap(boundary).keySet()) {
+      if(Bytes.equals(hri.getTableName(), tableName)) {
+        tableRegions.add(hri);
+      } else {
+        break;
+      }
+    }
+    return tableRegions;
+  }
+
+
+  /**
+   * Wait on region to clear regions-in-transition.
+   * <p>
+   * If the region isn't in transition, returns immediately.  Otherwise, method
+   * blocks until the region is out of transition.
+   */
+  public synchronized void waitOnRegionToClearRegionsInTransition(
+      final HRegionInfo hri) throws InterruptedException {
+    if (!isRegionInTransition(hri)) return;
+
+    while(!server.isStopped() && isRegionInTransition(hri)) {
+      RegionState rs = getRegionState(hri);
+      LOG.info("Waiting on " + rs + " to clear regions-in-transition");
+      waitForUpdate(100);
+    }
+
+    if (server.isStopped()) {
+      LOG.info("Giving up wait on region in " +
+        "transition because stoppable.isStopped is set");
+    }
+  }
+
+  /**
+   * Waits until the specified region has completed assignment.
+   * <p>
+   * If the region is already assigned, returns immediately.  Otherwise, method
+   * blocks until the region is assigned.
+   */
+  public synchronized void waitForAssignment(
+      final HRegionInfo hri) throws InterruptedException {
+    if (!isRegionAssigned(hri)) return;
+
+    while(!server.isStopped() && !isRegionAssigned(hri)) {
+      RegionState rs = getRegionState(hri);
+      LOG.info("Waiting on " + rs + " to be assigned");
+      waitForUpdate(100);
+    }
+
+    if (server.isStopped()) {
+      LOG.info("Giving up wait on region " +
+        "assignment because stoppable.isStopped is set");
+    }
+  }
+
+  /**
+   * Compute the average load across all region servers.
+   * Currently, this uses a very naive computation - just uses the number of
+   * regions being served, ignoring stats about number of requests.
+   * @return the average load
+   */
+  protected synchronized double getAverageLoad() {
+    int numServers = 0, totalLoad = 0;
+    for (Map.Entry<ServerName, Set<HRegionInfo>> e: serverHoldings.entrySet()) {
+      Set<HRegionInfo> regions = e.getValue();
+      ServerName serverName = e.getKey();
+      int regionCount = regions.size();
+      if (regionCount > 0 || serverManager.isServerOnline(serverName)) {
+        totalLoad += regionCount;
+        numServers++;
+      }
+    }
+    return numServers == 0 ? 0.0 :
+      (double)totalLoad / (double)numServers;
+  }
+
+  /**
+   * This is an EXPENSIVE clone.  Cloning though is the safest thing to do.
+   * Can't let out original since it can change and at least the load balancer
+   * wants to iterate this exported list.  We need to synchronize on regions
+   * since all access to this.servers is under a lock on this.regions.
+   *
+   * @return A clone of current assignments by table.
+   */
+  protected Map<String, Map<ServerName, List<HRegionInfo>>> getAssignmentsByTable() {
+    Map<String, Map<ServerName, List<HRegionInfo>>> result =
+      new HashMap<String, Map<ServerName,List<HRegionInfo>>>();
+    synchronized (this) {
+      if (!server.getConfiguration().getBoolean("hbase.master.loadbalance.bytable", true)) {
+        Map<ServerName, List<HRegionInfo>> svrToRegions =
+          new HashMap<ServerName, List<HRegionInfo>>(serverHoldings.size());
+        for (Map.Entry<ServerName, Set<HRegionInfo>> e: serverHoldings.entrySet()) {
+          svrToRegions.put(e.getKey(), new ArrayList<HRegionInfo>(e.getValue()));
+        }
+        result.put("ensemble", svrToRegions);
+      } else {
+        for (Map.Entry<ServerName, Set<HRegionInfo>> e: serverHoldings.entrySet()) {
+          for (HRegionInfo hri: e.getValue()) {
+            if (hri.isMetaRegion() || hri.isRootRegion()) continue;
+            String tablename = hri.getTableNameAsString();
+            Map<ServerName, List<HRegionInfo>> svrToRegions = result.get(tablename);
+            if (svrToRegions == null) {
+              svrToRegions = new HashMap<ServerName, List<HRegionInfo>>(serverHoldings.size());
+              result.put(tablename, svrToRegions);
+            }
+            List<HRegionInfo> regions = svrToRegions.get(e.getKey());
+            if (regions == null) {
+              regions = new ArrayList<HRegionInfo>();
+              svrToRegions.put(e.getKey(), regions);
+            }
+            regions.add(hri);
+          }
+        }
+      }
+    }
+
+    Map<ServerName, ServerLoad>
+      onlineSvrs = serverManager.getOnlineServers();
+    // Take care of servers w/o assignments.
+    for (Map<ServerName, List<HRegionInfo>> map: result.values()) {
+      for (ServerName svr: onlineSvrs.keySet()) {
+        if (!map.containsKey(svr)) {
+          map.put(svr, new ArrayList<HRegionInfo>());
+        }
+      }
+    }
+    return result;
+  }
+
+  protected synchronized RegionState getRegionState(final HRegionInfo hri) {
+    return regionStates.get(hri.getEncodedName());
+  }
+
+  protected synchronized RegionState getRegionState(final String regionName) {
+    return regionStates.get(regionName);
+  }
+
+  /**
+   * Get the HRegionInfo from cache, if not there, from the META table
+   * @param  regionName
+   * @return HRegionInfo for the region
+   */
+  protected HRegionInfo getRegionInfo(final byte [] regionName) {
+    String encodedName = HRegionInfo.encodeRegionName(regionName);
+    RegionState regionState = regionStates.get(encodedName);
+    if (regionState != null) {
+      return regionState.getRegion();
+    }
+
+    try {
+      Pair<HRegionInfo, ServerName> p =
+        MetaReader.getRegion(server.getCatalogTracker(), regionName);
+      return p == null ? null : p.getFirst();
+    } catch (IOException e) {
+      server.abort("Aborting because error occoured while reading " +
+        Bytes.toStringBinary(regionName) + " from .META.", e);
+      return null;
+    }
+  }
+}

Propchange: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java Fri Jul 27 16:34:32 2012
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.master.AssignmentManager;
+import org.apache.hadoop.hbase.master.RegionState;
 
 /**
  * Handles CLOSED region event on Master.
@@ -99,9 +100,8 @@ public class ClosedRegionHandler extends
       return;
     }
     // ZK Node is in CLOSED state, assign it.
-    // TODO: Should we remove the region from RIT too?  We don't?  Makes for
-    // a 'forcing' log message when we go to update state from CLOSED to OFFLINE
-    assignmentManager.setOffline(regionInfo);
+    assignmentManager.getRegionStates().updateRegionState(
+      regionInfo, RegionState.State.CLOSED, null);
     // This below has to do w/ online enable/disable of a table
     assignmentManager.removeClosedRegion(regionInfo);
     assignmentManager.assign(regionInfo, true);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java Fri Jul 27 16:34:32 2012
@@ -176,8 +176,9 @@ public class CreateTableHandler extends 
     // 4. Trigger immediate assignment of the regions in round-robin fashion
     List<ServerName> servers = serverManager.createDestinationServersList();
     try {
-      this.assignmentManager.assignUserRegions(Arrays.asList(newRegions),
-        servers);
+      List<HRegionInfo> regions = Arrays.asList(newRegions);
+      assignmentManager.getRegionStates().createRegionStates(regions);
+      assignmentManager.assignUserRegions(regions, servers);
     } catch (InterruptedException ie) {
       LOG.error("Caught " + ie + " during round-robin assignment");
       throw new IOException(ie);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java Fri Jul 27 16:34:32 2012
@@ -62,12 +62,12 @@ public class DeleteTableHandler extends 
     for (HRegionInfo region : regions) {
       long done = System.currentTimeMillis() + waitTime;
       while (System.currentTimeMillis() < done) {
-        AssignmentManager.RegionState rs = am.isRegionInTransition(region);
-        if (rs == null) break;
+        if (!am.getRegionStates().isRegionInTransition(region)) break;
         Threads.sleep(waitingTimeForEvents);
-        LOG.debug("Waiting on  region to clear regions in transition; " + rs);
+        LOG.debug("Waiting on region to clear regions in transition; "
+          + am.getRegionStates().getRegionTransitionState(region));
       }
-      if (am.isRegionInTransition(region) != null) {
+      if (am.getRegionStates().isRegionInTransition(region)) {
         throw new IOException("Waited hbase.master.wait.on.region (" +
           waitTime + "ms) for region to leave region " +
           region.getRegionNameAsString() + " in transitions");

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java Fri Jul 27 16:34:32 2012
@@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.master.As
 import org.apache.hadoop.hbase.master.BulkAssigner;
 import org.apache.hadoop.hbase.master.HMaster;
 import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
+import org.apache.hadoop.hbase.master.RegionStates;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.zookeeper.KeeperException;
 
@@ -124,8 +125,8 @@ public class DisableTableHandler extends
       // already closed will not be included in this list; i.e. the returned
       // list is not ALL regions in a table, its all online regions according
       // to the in-memory state on this master.
-      final List<HRegionInfo> regions =
-        this.assignmentManager.getRegionsOfTable(tableName);
+      final List<HRegionInfo> regions = this.assignmentManager
+        .getRegionStates().getRegionsOfTable(tableName);
       if (regions.size() == 0) {
         done = true;
         break;
@@ -162,8 +163,9 @@ public class DisableTableHandler extends
 
     @Override
     protected void populatePool(ExecutorService pool) {
+      RegionStates regionStates = assignmentManager.getRegionStates();
       for (HRegionInfo region: regions) {
-        if (assignmentManager.isRegionInTransition(region) != null) continue;
+        if (regionStates.isRegionInTransition(region)) continue;
         final HRegionInfo hri = region;
         pool.execute(new Runnable() {
           public void run() {
@@ -181,7 +183,7 @@ public class DisableTableHandler extends
       List<HRegionInfo> regions = null;
       while (!server.isStopped() && remaining > 0) {
         Thread.sleep(waitingTimeForEvents);
-        regions = assignmentManager.getRegionsOfTable(tableName);
+        regions = assignmentManager.getRegionStates().getRegionsOfTable(tableName);
         if (regions.isEmpty()) break;
         remaining = timeout - (System.currentTimeMillis() - startTime);
       }

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java Fri Jul 27 16:34:32 2012
@@ -167,7 +167,8 @@ public class EnableTableHandler extends 
     final List<HRegionInfo> regionsInMeta)
   throws IOException {
     final List<HRegionInfo> onlineRegions =
-      this.assignmentManager.getRegionsOfTable(tableName);
+      this.assignmentManager.getRegionStates()
+        .getRegionsOfTable(tableName);
     regionsInMeta.removeAll(onlineRegions);
     return regionsInMeta;
   }
@@ -194,7 +195,8 @@ public class EnableTableHandler extends 
 
       if (!roundRobinAssignment) {
         for (HRegionInfo region : regions) {
-          if (assignmentManager.isRegionInTransition(region) != null) {
+          if (assignmentManager.getRegionStates()
+              .isRegionInTransition(region)) {
             continue;
           }
           final HRegionInfo hri = region;
@@ -223,7 +225,8 @@ public class EnableTableHandler extends 
       int lastNumberOfRegions = 0;
       while (!server.isStopped() && remaining > 0) {
         Thread.sleep(waitingTimeForEvents);
-        regions = assignmentManager.getRegionsOfTable(tableName);
+        regions = assignmentManager.getRegionStates()
+          .getRegionsOfTable(tableName);
         if (isDone(regions)) break;
 
         // Punt on the timeout as long we make progress

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java Fri Jul 27 16:34:32 2012
@@ -28,7 +28,7 @@ import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.master.AssignmentManager;
-import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
+import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
 import org.apache.zookeeper.KeeperException;
 
@@ -98,7 +98,8 @@ public class OpenedRegionHandler extends
   public void process() {
     // Code to defend against case where we get SPLIT before region open
     // processing completes; temporary till we make SPLITs go via zk -- 0.92.
-    RegionState regionState = this.assignmentManager.isRegionInTransition(regionInfo);
+    RegionState regionState = this.assignmentManager.getRegionStates()
+      .getRegionTransitionState(regionInfo.getEncodedName());
     boolean openedNodeDeleted = false;
     if (regionState != null
         && regionState.getState().equals(RegionState.State.OPEN)) {

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java Fri Jul 27 16:34:32 2012
@@ -38,9 +38,9 @@ import org.apache.hadoop.hbase.catalog.M
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.master.AssignmentManager;
-import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
 import org.apache.hadoop.hbase.master.DeadServer;
 import org.apache.hadoop.hbase.master.MasterServices;
+import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.master.ServerManager;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
@@ -289,12 +289,13 @@ public class ServerShutdownHandler exten
       if (hris != null) {
         List<HRegionInfo> toAssignRegions = new ArrayList<HRegionInfo>();
         for (Map.Entry<HRegionInfo, Result> e: hris.entrySet()) {
-          RegionState rit = this.services.getAssignmentManager().isRegionInTransition(e.getKey());
+          RegionState rit = services.getAssignmentManager()
+            .getRegionStates().getRegionTransitionState(e.getKey());
           if (processDeadRegion(e.getKey(), e.getValue(),
               this.services.getAssignmentManager(),
               this.server.getCatalogTracker())) {
             ServerName addressFromAM = this.services.getAssignmentManager()
-                .getRegionServerOfRegion(e.getKey());
+              .getRegionStates().getRegionServerOfRegion(e.getKey());
             if (rit != null && !rit.isClosing() && !rit.isPendingClose() && !rit.isSplitting()) {
               // Skip regions that were in transition unless CLOSING or
               // PENDING_CLOSE

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java Fri Jul 27 16:34:32 2012
@@ -105,7 +105,6 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionLoad;
-import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.TableSchema;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.CreateTableRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Fri Jul 27 16:34:32 2012
@@ -3366,8 +3366,8 @@ public class  HRegionServer implements C
       checkOpen();
       requestCount.incrementAndGet();
       List<HRegionInfo> list = new ArrayList<HRegionInfo>(onlineRegions.size());
-      for (Map.Entry<String,HRegion> e: this.onlineRegions.entrySet()) {
-        list.add(e.getValue().getRegionInfo());
+      for (HRegion region: this.onlineRegions.values()) {
+        list.add(region.getRegionInfo());
       }
       Collections.sort(list);
       return ResponseConverter.buildGetOnlineRegionResponse(list);

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OnlineRegions.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OnlineRegions.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OnlineRegions.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/OnlineRegions.java Fri Jul 27 16:34:32 2012
@@ -23,7 +23,6 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java Fri Jul 27 16:34:32 2012
@@ -39,7 +39,7 @@ import org.apache.hadoop.hbase.client.HB
 import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
+import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java Fri Jul 27 16:34:32 2012
@@ -20,6 +20,7 @@
 package org.apache.hadoop.hbase;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.IOException;
@@ -2109,6 +2110,27 @@ public class HBaseTestingUtility {
     return hloc.getPort();
   }
 
+  /**
+   *  Due to async racing issue, a region may not be in
+   *  the online region list of a region server yet, after
+   *  the assignment znode is deleted and the new assignment
+   *  is recorded in master.
+   */
+  public void assertRegionOnServer(
+      final HRegionInfo hri, final ServerName server,
+      final long timeout) throws IOException, InterruptedException {
+    long timeoutTime = System.currentTimeMillis() + timeout;
+    while (true) {
+      List<HRegionInfo> regions = getHBaseAdmin().getOnlineRegions(server);
+      if (regions.contains(hri)) return;
+      long now = System.currentTimeMillis();
+      if (now > timeoutTime) break;
+      Thread.sleep(10);
+    }
+    fail("Could not find region " + hri.getRegionNameAsString()
+      + " on server " + server);
+  }
+
   public HRegion createTestRegion(String tableName, HColumnDescriptor hcd)
       throws IOException {
     HTableDescriptor htd = new HTableDescriptor(tableName);

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java Fri Jul 27 16:34:32 2012
@@ -29,7 +29,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.HMaster;
 import org.apache.hadoop.hbase.protobuf.RequestConverter;
 import org.apache.hadoop.hbase.master.ServerManager;
@@ -223,8 +222,8 @@ public class TestDrainingServer {
       Assert.assertEquals("Nothing should have happened here.", regionsOnDrainingServer,
         drainingServer.getNumberOfOnlineRegions());
       Assert.assertFalse("We should not have regions in transition here. List is: "+
-        master.getAssignmentManager().copyRegionsInTransition(),
-        master.getAssignmentManager().isRegionsInTransition() );
+        master.getAssignmentManager().getRegionStates().getRegionsInTransition(),
+        master.getAssignmentManager().getRegionStates().isRegionsInTransition());
 
       // Kill a few regionservers.
       for (int aborted = 0; aborted <= 2; aborted++) {
@@ -274,7 +273,7 @@ public class TestDrainingServer {
     }
 
     while (TEST_UTIL.getMiniHBaseCluster().getMaster().
-        getAssignmentManager().isRegionsInTransition()) {
+      getAssignmentManager().getRegionStates().isRegionsInTransition()) {
     }
   }
 

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java Fri Jul 27 16:34:32 2012
@@ -39,9 +39,7 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.JVMClusterUtil;
 import org.junit.After;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Fri Jul 27 16:34:32 2012
@@ -1456,10 +1456,10 @@ public class TestAdmin {
     List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
     HRegionInfo hri = tableRegions.get(0);
     AssignmentManager am = master.getAssignmentManager();
-    ServerName server = am.getRegionServerOfRegion(hri);
+    ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
     localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
     assertEquals("Current region server and region server before move should be same.", server,
-        am.getRegionServerOfRegion(hri));
+      am.getRegionStates().getRegionServerOfRegion(hri));
   }
 
 

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java Fri Jul 27 16:34:32 2012
@@ -159,7 +159,7 @@ public class TestHCM {
 
     // We can wait for all regions to be onlines, that makes log reading easier when debugging
     while (TEST_UTIL.getMiniHBaseCluster().getMaster().
-      getAssignmentManager().isRegionsInTransition()) {
+      getAssignmentManager().getRegionStates().isRegionsInTransition()) {
     }
 
     // Now moving the region to the second server

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java Fri Jul 27 16:34:32 2012
@@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.client.HT
 import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.HMaster;
 import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
+import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.protobuf.RequestConverter;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
@@ -963,10 +964,10 @@ public class TestMasterObserver {
   
       // wait for assignments to finish, if any
       AssignmentManager mgr = master.getAssignmentManager();
-      Collection<AssignmentManager.RegionState> transRegions =
-          mgr.copyRegionsInTransition().values();
-      for (AssignmentManager.RegionState state : transRegions) {
-        mgr.waitOnRegionToClearRegionsInTransition(state.getRegion());
+      Collection<RegionState> transRegions =
+        mgr.getRegionStates().getRegionsInTransition().values();
+      for (RegionState state : transRegions) {
+        mgr.getRegionStates().waitOnRegionToClearRegionsInTransition(state.getRegion());
       }
   
       // move half the open regions from RS 0 to RS 1
@@ -983,9 +984,9 @@ public class TestMasterObserver {
       }
   
       // wait for assignments to finish
-      transRegions = mgr.copyRegionsInTransition().values();
-      for (AssignmentManager.RegionState state : transRegions) {
-        mgr.waitOnRegionToClearRegionsInTransition(state.getRegion());
+      transRegions = mgr.getRegionStates().getRegionsInTransition().values();
+      for (RegionState state : transRegions) {
+        mgr.getRegionStates().waitOnRegionToClearRegionsInTransition(state.getRegion());
       }
   
       // now trigger a balance

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java Fri Jul 27 16:34:32 2012
@@ -414,7 +414,7 @@ public class TestHFileOutputFormat  {
         LOG.info("Changing regions in table");
         admin.disableTable(table.getTableName());
         while(util.getMiniHBaseCluster().getMaster().getAssignmentManager().
-            isRegionsInTransition()) {
+            getRegionStates().isRegionsInTransition()) {
           Threads.sleep(200);
           LOG.info("Waiting on table to finish disabling");
         }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java?rev=1366438&r1=1366437&r2=1366438&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java Fri Jul 27 16:34:32 2012
@@ -32,7 +32,6 @@ import org.apache.hadoop.hbase.ServerNam
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.executor.EventHandler.EventType;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
@@ -94,7 +93,8 @@ public class Mocking {
 
     boolean wait = true;
     while (wait) {
-      AssignmentManager.RegionState state = am.getRegionsInTransition().get(encodedName);
+      RegionState state = am.getRegionStates()
+        .getRegionsInTransition().get(encodedName);
       if (state != null && state.isPendingOpen()){
         wait = false;
       } else {



Mime
View raw message