hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r989501 - in /hbase/branches/0.90_master_rewrite/src: main/java/org/apache/hadoop/hbase/catalog/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hbase/master/handler/ main/java/org/apache/hadoop/hbase/regionserver/hand...
Date Thu, 26 Aug 2010 07:43:48 GMT
Author: stack
Date: Thu Aug 26 07:43:48 2010
New Revision: 989501

URL: http://svn.apache.org/viewvc?rev=989501&view=rev
Log:

Redid how balancer is integrated.

Fixed some more tests.

M src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
  Removed unused imports. Upped retries.  This is still not right
  but is passing for now.
M src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java
  I'd fixed infinite loop in one test but second test duplicated
  the code that made for infinite loop.
M src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java
  LB constructor changes args.
M src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
  Fix this test by making it use new check if table is disabled.

Modified:
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.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/LoadBalancer.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/CatalogTracker.java
Thu Aug 26 07:43:48 2010
@@ -385,6 +385,8 @@ public class CatalogTracker {
     if (metaHsa == null) {
       LOG.info(".META. is not assigned; continuing");
     } else if (hsi.getServerAddress().equals(metaHsa)) {
+      LOG.info(hsi.getServerName() + " carrying .META.; unsetting " +
+        ".META. location");
       result.setSecond(true);
       resetMetaLocation();
     }

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=989501&r1=989500&r2=989501&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
Thu Aug 26 07:43:48 2010
@@ -26,11 +26,14 @@ import java.lang.management.RuntimeMXBea
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.UnknownHostException;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Chore;
 import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -54,10 +57,10 @@ import org.apache.hadoop.hbase.catalog.M
 import org.apache.hadoop.hbase.catalog.MetaReader;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.MetaScanner;
-import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ServerConnection;
 import org.apache.hadoop.hbase.client.ServerConnectionManager;
+import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
 import org.apache.hadoop.hbase.executor.ExecutorService;
 import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType;
 import org.apache.hadoop.hbase.ipc.HBaseRPC;
@@ -65,6 +68,7 @@ import org.apache.hadoop.hbase.ipc.HBase
 import org.apache.hadoop.hbase.ipc.HBaseServer;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HMasterRegionInterface;
+import org.apache.hadoop.hbase.master.LoadBalancer.RegionPlan;
 import org.apache.hadoop.hbase.master.handler.DeleteTableHandler;
 import org.apache.hadoop.hbase.master.handler.DisableTableHandler;
 import org.apache.hadoop.hbase.master.handler.EnableTableHandler;
@@ -158,7 +162,8 @@ implements HMasterInterface, HMasterRegi
   // Instance of the hbase executor service.
   ExecutorService executorService;
 
-  private LoadBalancer balancer;
+  private LoadBalancer balancer = new LoadBalancer();
+  private Chore balancerChore;
 
   /**
    * Initializes the HMaster. The steps are as follows:
@@ -300,7 +305,7 @@ implements HMasterInterface, HMasterRegi
       }
     }
     this.rpcServer.stop();
-    this.balancer.interrupt();
+    if (this.balancerChore != null) this.balancerChore.interrupt();
     this.activeMasterManager.stop();
     this.zooKeeper.close();
     this.executorService.shutdown();
@@ -427,13 +432,7 @@ implements HMasterInterface, HMasterRegi
         this.infoServer.setAttribute(MASTER, this);
         this.infoServer.start();
       }
-
-      // Start up the load balancer
-      String name = getServerName() + "-loadbalancer";
-      int period = getConfiguration().getInt("hbase.balancer.period", 300000);
-      this.balancer = new LoadBalancer(name, period, this,
-        this.assignmentManager);
-      Threads.setDaemonThreadRunning(this.balancer, name);
+      this.balancerChore = getAndStartBalancerChore(this);
 
       // Start the server last so everything else is running before we start
       // receiving requests.
@@ -454,6 +453,20 @@ implements HMasterInterface, HMasterRegi
     }
   }
 
+  private static Chore getAndStartBalancerChore(final HMaster master) {
+    String name = master.getServerName() + "-balancerChore";
+    int period = master.getConfiguration().getInt("hbase.balancer.period", 600000);
+    // Start up the load balancer chore
+    Chore chore = new Chore(name, period, master) {
+      @Override
+      protected void chore() {
+        master.balance();
+      }
+    };
+    Threads.setDaemonThreadRunning(chore, name);
+    return chore;
+  }
+
   public MapWritable regionServerStartup(final HServerInfo serverInfo)
   throws IOException {
     // Set the ip into the passed in serverInfo.  Its ip is more than likely
@@ -511,6 +524,27 @@ implements HMasterInterface, HMasterRegi
     return !isStopped();
   }
 
+  /**
+   * Run the balancer.
+   */
+  public void balance() {
+    synchronized (this.balancer) {
+      // Only allow one balance run at at time.
+      if (this.assignmentManager.isRegionsInTransition()) {
+        LOG.debug("Not running balancer because regions in transition: " +
+          this.assignmentManager.getRegionsInTransition());
+        return;
+      }
+      Map<HServerInfo, List<HRegionInfo>> assignments =
+        this.assignmentManager.getAssignments();
+      List<RegionPlan> plans = this.balancer.balanceCluster(assignments);
+      if (plans == null || plans.isEmpty()) return;
+      for (RegionPlan plan: plans) {
+        this.assignmentManager.balance(plan);
+      }
+    }
+  }
+
   public void createTable(HTableDescriptor desc, byte [][] splitKeys)
   throws IOException {
     createTable(desc, splitKeys, false);

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java
Thu Aug 26 07:43:48 2010
@@ -35,10 +35,8 @@ import org.apache.hadoop.fs.BlockLocatio
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.Chore;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerInfo;
-import org.apache.hadoop.hbase.Stoppable;
 
 /**
  * Makes decisions about the placement and movement of Regions across
@@ -56,42 +54,9 @@ import org.apache.hadoop.hbase.Stoppable
  * 
  * <p>This classes produces plans for the {@link AssignmentManager} to execute.
  */
-public class LoadBalancer extends Chore {
+public class LoadBalancer {
   private static final Log LOG = LogFactory.getLog(LoadBalancer.class);
   private static final Random rand = new Random();
-  private final AssignmentManager assignmentManager;
-
-  /**
-   * Instantiate the load balancer with the specified configuration.
-   *
-   * This sets configuration parameters to be used by the balancing algorithms
-   * and launches a background thread to perform periodic load balancing.
-   * @param stoppable
-   * @param period
-   * @param name Name for this LB thread.
-   * @param assignmentManager
-   */
-  public LoadBalancer(final String name, final int period,
-      final Stoppable stoppable, final AssignmentManager assignmentManager) {
-    super(name, period, stoppable);
-    this.assignmentManager = assignmentManager;
-  }
-
-  @Override
-  protected void chore() {
-    if (this.assignmentManager.isRegionsInTransition()) {
-      LOG.debug("Not running balancer because regions in transition: " +
-        this.assignmentManager.getRegionsInTransition());
-      return;
-    }
-    Map<HServerInfo, List<HRegionInfo>> assignments =
-      this.assignmentManager.getAssignments();
-    List<RegionPlan> plans = balanceCluster(assignments);
-    if (plans == null || plans.isEmpty()) return;
-    for (RegionPlan plan: plans) {
-      this.assignmentManager.balance(plan);
-    }
-  }
 
   /**
    * Generate a global load balancing plan according to the specified map of

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
Thu Aug 26 07:43:48 2010
@@ -88,7 +88,7 @@ public class ClosedRegionHandler extends
 
   @Override
   public void process() {
-    LOG.debug("Handling CLOSED event with data: " + data);
+    LOG.debug("Handling CLOSED event");
     // Check if this table is being disabled or not
     if (assignmentManager.isTableOfRegionDisabled(regionInfo.getRegionName())) {
       // Disabling so should not be reassigned, just delete the CLOSED node

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
Thu Aug 26 07:43:48 2010
@@ -85,7 +85,7 @@ public class OpenedRegionHandler extends
 
   @Override
   public void process() {
-    LOG.debug("Handling OPENED event; deleting unassigned node with data: " + data);
+    LOG.debug("Handling OPENED event; deleting unassigned node");
     // TODO: should we check if this table was disabled and get it closed?
     // Remove region from in-memory transition and unassigned node from ZK
     try {

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
Thu Aug 26 07:43:48 2010
@@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaReader;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.master.DeadServer;

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
Thu Aug 26 07:43:48 2010
@@ -27,8 +27,6 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.catalog.CatalogTracker;
-import org.apache.hadoop.hbase.catalog.MetaEditor;
-import org.apache.hadoop.hbase.catalog.RootLocationEditor;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.RegionServerServices;

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/TestMultiParallelPut.java
Thu Aug 26 07:43:48 2010
@@ -20,9 +20,11 @@
 
 package org.apache.hadoop.hbase;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
@@ -30,9 +32,6 @@ import org.apache.hadoop.hbase.client.Pu
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.util.Bytes;
 
-import java.util.ArrayList;
-import java.util.List;
-
 public class TestMultiParallelPut extends MultiRegionTable {
   final Log LOG = LogFactory.getLog(getClass());
   private static final byte[] VALUE = Bytes.toBytes("value");
@@ -71,6 +70,7 @@ public class TestMultiParallelPut extend
   }
 
   public void doATest(boolean doAbort) throws Exception {
+    conf.setInt("hbase.client.retries.number", 10);
     HTable table = new HTable(conf, TEST_TABLE);
     table.setAutoFlush(false);
     table.setWriteBufferSize(10 * 1024 * 1024);

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/mapreduce/TestHFileOutputFormat.java
Thu Aug 26 07:43:48 2010
@@ -242,12 +242,12 @@ public class TestHFileOutputFormat  {
     }
     return ret;
   }
-  
+
   @Test
   public void testMRIncrementalLoad() throws Exception {
     doIncrementalLoadTest(false);
   }
-  
+
   @Test
   public void testMRIncrementalLoadWithSplit() throws Exception {
     doIncrementalLoadTest(true);
@@ -303,13 +303,12 @@ public class TestHFileOutputFormat  {
             
       // Cause regions to reopen
       admin.disableTable(TABLE_NAME);
-      while (table.getRegionsInfo().size() != 0) {
+      while (!admin.isTableDisabled(TABLE_NAME)) {
         Thread.sleep(1000);
         LOG.info("Waiting for table to disable"); 
       }
       admin.enableTable(TABLE_NAME);
       util.waitTableAvailable(TABLE_NAME, 30000);
-      
       assertEquals("Data should remain after reopening of regions",
           tableDigestBefore, util.checksumRows(table));
     } finally {
@@ -317,9 +316,7 @@ public class TestHFileOutputFormat  {
       util.shutdownMiniCluster();
     }
   }
-  
-  
-  
+
   private void runIncrementalPELoad(
       Configuration conf, HTable table, Path outDir)
   throws Exception {

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestLoadBalancer.java
Thu Aug 26 07:43:48 2010
@@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.HRegionIn
 import org.apache.hadoop.hbase.HServerAddress;
 import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.Stoppable;
 import org.apache.hadoop.hbase.master.LoadBalancer.RegionPlan;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.BeforeClass;
@@ -54,15 +53,7 @@ public class TestLoadBalancer {
 
   @BeforeClass
   public static void beforeAllTests() throws Exception {
-    loadBalancer = new LoadBalancer("test", 1, new Stoppable() {
-      @Override
-      public void stop(String why) {
-      }
-      @Override
-      public boolean isStopped() {
-        return false;
-      }
-    }, (AssignmentManager)null);
+    loadBalancer = new LoadBalancer();
     rand = new Random();
   }
 

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java?rev=989501&r1=989500&r2=989501&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java
(original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestZKBasedOpenCloseRegion.java
Thu Aug 26 07:43:48 2010
@@ -99,15 +99,7 @@ public class TestZKBasedOpenCloseRegion 
     int rsIdx = 0;
     HRegionServer regionServer =
       TEST_UTIL.getHBaseCluster().getRegionServer(rsIdx);
-    Collection<HRegionInfo> regions = regionServer.getOnlineRegions();
-    HRegionInfo hri = null;
-    for (HRegionInfo i: regions) {
-      LOG.info(i.getRegionNameAsString());
-      if (!i.isMetaRegion()) {
-        hri = i;
-        break;
-      }
-    }
+    HRegionInfo hri = getNonMetaRegion(regionServer.getOnlineRegions());
     LOG.debug("Asking RS to close region " + hri.getRegionNameAsString());
 
     AtomicBoolean closeEventProcessed = new AtomicBoolean(false);
@@ -128,23 +120,27 @@ public class TestZKBasedOpenCloseRegion 
     LOG.info("Unassign " + hri.getRegionNameAsString());
     cluster.getMaster().assignmentManager.unassign(hri);
 
-    synchronized(closeEventProcessed) {
-      closeEventProcessed.wait(3*60*1000);
+    while (!closeEventProcessed.get()) {
+      Threads.sleep(100);
     }
 
-    if (!closeEventProcessed.get()) {
-      throw new Exception("Timed out, close event not called on master.");
+    while (!reopenEventProcessed.get()) {
+      Threads.sleep(100);
     }
 
-    synchronized(reopenEventProcessed) {
-      reopenEventProcessed.wait(3*60*1000);
-    }
+    LOG.info("Done with testReOpenRegion");
+  }
 
-    if(!reopenEventProcessed.get()) {
-      throw new Exception("Timed out, open event not called on master after region close.");
+  private HRegionInfo getNonMetaRegion(final Collection<HRegionInfo> regions) {
+    HRegionInfo hri = null;
+    for (HRegionInfo i: regions) {
+      LOG.info(i.getRegionNameAsString());
+      if (!i.isMetaRegion()) {
+        hri = i;
+        break;
+      }
     }
-
-    LOG.info("\n\n\nDone with test, RS informed master successfully.\n\n\n");
+    return hri;
   }
 
   public static class ReopenEventListener implements EventHandlerListener {
@@ -198,13 +194,7 @@ public class TestZKBasedOpenCloseRegion 
 
     int rsIdx = 0;
     HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(rsIdx);
-    Collection<HRegionInfo> regions = regionServer.getOnlineRegions();
-    HRegionInfo hri;
-    while((hri = regions.iterator().next()) != null) {
-      if(!hri.isMetaRegion() && !hri.isRootRegion()) {
-        break;
-      }
-    }
+    HRegionInfo hri = getNonMetaRegion(regionServer.getOnlineRegions());
     LOG.debug("Asking RS to close region " + hri.getRegionNameAsString());
 
     AtomicBoolean closeEventProcessed = new AtomicBoolean(false);
@@ -215,16 +205,10 @@ public class TestZKBasedOpenCloseRegion 
 
     cluster.getMaster().assignmentManager.unassign(hri);
 
-    synchronized(closeEventProcessed) {
-      // wait for 3 minutes
-      closeEventProcessed.wait(3*60*1000);
-    }
-    if(!closeEventProcessed.get()) {
-      throw new Exception("Timed out, close event not called on master.");
-    }
-    else {
-      LOG.info("Done with test, RS informed master successfully.");
+    while (!closeEventProcessed.get()) {
+      Threads.sleep(100);
     }
+    LOG.info("Done with testCloseRegion");
   }
 
   public static class CloseRegionEventListener implements EventHandlerListener {
@@ -244,11 +228,11 @@ public class TestZKBasedOpenCloseRegion 
       if(event.getEventType() == EventType.RS2ZK_REGION_CLOSED) {
         LOG.info("Finished processing CLOSE REGION");
         TotesHRegionInfo hriCarrier = (TotesHRegionInfo)event;
-        if(regionToClose.equals(hriCarrier.getHRegionInfo().getRegionNameAsString())) {
+        if (regionToClose.equals(hriCarrier.getHRegionInfo().getRegionNameAsString())) {
+          LOG.info("Setting closeEventProcessed flag");
           closeEventProcessed.set(true);
-        }
-        synchronized(closeEventProcessed) {
-          closeEventProcessed.notifyAll();
+        } else {
+          LOG.info("Region to close didn't match");
         }
       }
     }



Mime
View raw message