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

svn commit: r985106 - in /hbase/branches/0.90_master_rewrite/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/catalog/ main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/executor/ main/java/org/apache/h...

Author: stack
Date: Fri Aug 13 06:33:06 2010
New Revision: 985106

URL: http://svn.apache.org/viewvc?rev=985106&view=rev
Log:
Some bug fixing.  Small stuff.

M src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java
  I'd added a bunch of tests here for functionality i later ripped out.
  Keep the cleanup done.
M src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
  Let out IE until we decide what we want to do with these (We're letting out
  KEs currently).
M src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java
  This is the test I'm currently working on. Its good for state across
  restarts.  Added in more logging and assertions.
M src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java
  Make master wait for ever as default.
M src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
  Javadoc and moved minor duplicated code.
M src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
  More strict about adhering to passed timeout.
  I'd added new blockUntilChanged methods but thinking on it, they were a
  mistake.  Notion was wait until the data up in zk had changed -- say
  root region had moved -- but trouble is that we may assign root back to
  same host... and so data would be the same (not checking zk revision
  -- perhaps we should be).  This is probably an open issue given how
  assignment as currently done looks wrong (We always assign root and
  meta on startup). TBD.
M src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
  Letting out IE.
M src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
  Bug fix; need to zero out root location in zk before we assign.

Modified:
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java
    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/catalog/MetaEditor.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
    hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java
    hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/MasterAddressTracker.java Fri Aug 13 06:33:06 2010
@@ -85,7 +85,7 @@ public class MasterAddressTracker extend
    */
   public synchronized HServerAddress waitForMaster(long timeout)
   throws InterruptedException {
-    byte [] data = super.blockUntilAvailable(timeout);
+    byte [] data = super.blockUntilAvailable();
     return data == null ? null : new HServerAddress(Bytes.toString(data));
   }
 }
\ No newline at end of file

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=985106&r1=985105&r2=985106&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 Fri Aug 13 06:33:06 2010
@@ -90,14 +90,16 @@ public class CatalogTracker {
    * Determines current availability of catalog tables and ensures all further
    * transitions of either region is tracked.
    * @throws IOException
+   * @throws InterruptedException 
    */
-  public void start() throws IOException {
+  public void start() throws IOException, InterruptedException {
     // Register listeners with zk
     zookeeper.registerListener(rootRegionTracker);
     zookeeper.registerListener(metaNodeTracker);
     // Start root tracking
     rootRegionTracker.start();
-    // Determine meta assignment
+    // Determine meta assignment; may not work because root and meta not yet
+    // deployed.
     getMetaServerConnection(true);
   }
 
@@ -105,8 +107,9 @@ public class CatalogTracker {
    * Gets the current location for <code>-ROOT-</code> or null if location is
    * not currently available.
    * @return location of root, null if not available
+   * @throws InterruptedException 
    */
-  public HServerAddress getRootLocation() {
+  public HServerAddress getRootLocation() throws InterruptedException {
     return rootRegionTracker.getRootRegionLocation();
   }
 
@@ -117,7 +120,7 @@ public class CatalogTracker {
    */
   public void waitForRoot()
   throws InterruptedException {
-    rootRegionTracker.waitRootRegionLocation(-1);
+    rootRegionTracker.getRootRegionLocation();
   }
 
   /**
@@ -130,12 +133,11 @@ public class CatalogTracker {
    * @throws NotAllMetaRegionsOnlineException if root not available before
    *                                          timeout
    */
-  public HServerAddress waitForRoot(long timeout)
+  public HServerAddress waitForRoot(final long timeout)
   throws InterruptedException, NotAllMetaRegionsOnlineException {
     HServerAddress address = rootRegionTracker.waitRootRegionLocation(timeout);
     if (address == null) {
-      throw new NotAllMetaRegionsOnlineException(
-          "Timed out (" + timeout + "ms)");
+      throw new NotAllMetaRegionsOnlineException("Timed out; " + timeout + "ms");
     }
     return address;
   }
@@ -176,9 +178,10 @@ public class CatalogTracker {
    * if available.  Returns null if no location is immediately available.
    * @return connection to server hosting root, null if not available
    * @throws IOException
+   * @throws InterruptedException 
    */
   private HRegionInterface getRootServerConnection()
-  throws IOException {
+  throws IOException, InterruptedException {
     HServerAddress address = rootRegionTracker.getRootRegionLocation();
     if (address == null) {
       return null;
@@ -200,9 +203,10 @@ public class CatalogTracker {
    *
    * @return connection to server hosting meta, null if location not available
    * @throws IOException
+   * @throws InterruptedException 
    */
   private HRegionInterface getMetaServerConnection(boolean refresh)
-  throws IOException {
+  throws IOException, InterruptedException {
     synchronized(metaAvailable) {
       if(metaAvailable.get()) {
         HRegionInterface current = getCachedConnection(metaLocation);

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/catalog/MetaEditor.java Fri Aug 13 06:33:06 2010
@@ -72,8 +72,8 @@ public class MetaEditor {
   public static void updateMetaLocation(CatalogTracker catalogTracker,
       HRegionInfo regionInfo, HServerInfo serverInfo)
   throws IOException {
-    updateLocation(catalogTracker.waitForRootServerConnectionDefault(),
-        CatalogTracker.ROOT_REGION, regionInfo, serverInfo);
+    HRegionInterface server = catalogTracker.waitForRootServerConnectionDefault();
+    updateLocation(server, CatalogTracker.ROOT_REGION, regionInfo, serverInfo);
   }
 
   /**
@@ -112,15 +112,14 @@ public class MetaEditor {
   throws IOException {
     Put put = new Put(regionInfo.getRegionName());
     put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
-        Bytes.toBytes(serverInfo.getHostnamePort()));
+      Bytes.toBytes(serverInfo.getHostnamePort()));
     put.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
-        Bytes.toBytes(serverInfo.getStartCode()));
+      Bytes.toBytes(serverInfo.getStartCode()));
     server.put(catalogRegionName, put);
-
     LOG.info("Updated row " + regionInfo.getRegionNameAsString() +
-          " in region " + Bytes.toString(catalogRegionName) + " with " +
-          "server=" + serverInfo.getHostnamePort() + ", " +
-          "startcode=" + serverInfo.getStartCode());
+      " in region " + Bytes.toString(catalogRegionName) + " with " +
+      "server=" + serverInfo.getHostnamePort() + ", " +
+      "startcode=" + serverInfo.getStartCode());
   }
 
   /**

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java Fri Aug 13 06:33:06 2010
@@ -40,7 +40,6 @@ import org.apache.hadoop.hbase.util.Writ
  * minor releases.
  */
 public class MetaScanner {
-
   /**
    * Scans the meta table and calls a visitor on each RowResult and uses a empty
    * start row value as table name.
@@ -52,7 +51,7 @@ public class MetaScanner {
   public static void metaScan(Configuration configuration,
       MetaScannerVisitor visitor)
   throws IOException {
-    metaScan(configuration, visitor, HConstants.EMPTY_START_ROW);
+    metaScan(configuration, visitor, null);
   }
 
   /**

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/executor/RegionTransitionData.java Fri Aug 13 06:33:06 2010
@@ -204,7 +204,7 @@ public class RegionTransitionData implem
 
   @Override
   public String toString() {
-    return "region=" + regionName + ",server=" + serverName + ",state=" +
-        eventType;
+    return "region=" + Bytes.toString(regionName) + ", server=" + serverName +
+      ", state=" + eventType;
   }
 }

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java Fri Aug 13 06:33:06 2010
@@ -47,6 +47,7 @@ import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.Stoppable;
 import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaReader;
+import org.apache.hadoop.hbase.catalog.RootLocationEditor;
 import org.apache.hadoop.hbase.client.MetaScanner;
 import org.apache.hadoop.hbase.executor.RegionTransitionData;
 import org.apache.hadoop.hbase.master.LoadBalancer.RegionPlan;
@@ -623,9 +624,10 @@ public class AssignmentManager extends Z
    * <p>
    * Forcibly unsets the current root region location in ZooKeeper and assigns
    * ROOT to a random RegionServer.
+   * @throws KeeperException 
    */
-  public void assignRoot() {
-    // Force assignment to a random server
+  public void assignRoot() throws KeeperException {
+    RootLocationEditor.deleteRootLocation(this.master.getZooKeeper());
     assign(HRegionInfo.ROOT_REGIONINFO);
   }
 
@@ -654,9 +656,9 @@ public class AssignmentManager extends Z
     // Simpler because just wait for no regions in transition
 
     // Scan META for all user regions
-    List<HRegionInfo> allRegions = MetaScanner.listAllRegions(
-        master.getConfiguration());
-    if(allRegions == null || allRegions.isEmpty()) {
+    List<HRegionInfo> allRegions =
+      MetaScanner.listAllRegions(master.getConfiguration());
+    if (allRegions == null || allRegions.isEmpty()) {
       return;
     }
 

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=985106&r1=985105&r2=985106&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 Fri Aug 13 06:33:06 2010
@@ -168,8 +168,10 @@ implements HMasterInterface, HMasterRegi
    *     region server queue, file system manager, etc
    * <li>Block until becoming active master
    * </ol>
+   * @throws InterruptedException 
    */
-  public HMaster(Configuration conf) throws IOException, KeeperException {
+  public HMaster(Configuration conf)
+  throws IOException, KeeperException, InterruptedException {
     // initialize some variables
     this.conf = conf;
 
@@ -274,6 +276,11 @@ implements HMasterInterface, HMasterRegi
       startServiceThreads();
       // wait for minimum number of region servers to be up
       serverManager.waitForMinServers();
+
+      // TOOD: Whey do we assign root and meta on startup?  Shouldn't we check
+      // if we started the cluster before we assigning root and meta?  Perhaps
+      // they are happy where they are?  St.Ack 20100812.
+
       // assign the root region
       assignmentManager.assignRoot();
       catalogTracker.waitForRoot();
@@ -293,7 +300,8 @@ implements HMasterInterface, HMasterRegi
         // rebuild in-memory state.
         assignmentManager.processFailover();
       }
-      LOG.info("HMaster started on " + this.address.toString());
+      LOG.info("HMaster started on " + this.address.toString() +
+        "; clusterStarter=" + this.clusterStarter);
       Sleeper sleeper = new Sleeper(1000, this);
       int countOfServersStillRunning = this.serverManager.numServers();
       while (!this.stopped  && !this.abort) {
@@ -768,10 +776,11 @@ implements HMasterInterface, HMasterRegi
         masterClass.getConstructor(Configuration.class);
       return c.newInstance(conf);
     } catch (InvocationTargetException ite) {
-      Throwable target = ite.getTargetException();
+      Throwable target = ite.getTargetException() != null?
+        ite.getTargetException(): ite;
+      if (target.getCause() != null) target = target.getCause();
       throw new RuntimeException("Failed construction of Master: " +
-        masterClass.toString() + ((target.getCause() != null)?
-          target.getCause().getMessage(): ""), target);
+        masterClass.toString(), target);
     } catch (Exception e) {
       throw new RuntimeException("Failed construction of Master: " +
         masterClass.toString() + ((e.getCause() != null)?
@@ -786,7 +795,7 @@ implements HMasterInterface, HMasterRegi
     private MiniZooKeeperCluster zkcluster = null;
 
     public LocalHMaster(Configuration conf)
-    throws IOException, KeeperException {
+    throws IOException, KeeperException, InterruptedException {
       super(conf);
     }
 

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=985106&r1=985105&r2=985106&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 Fri Aug 13 06:33:06 2010
@@ -92,5 +92,4 @@ public class OpenedRegionHandler extends
     assignmentManager.regionOnline(regionInfo, serverInfo);
     LOG.debug("Opened region " + regionInfo);
   }
-
 }

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Fri Aug 13 06:33:06 2010
@@ -253,8 +253,9 @@ public class HRegionServer implements HR
    *
    * @param conf
    * @throws IOException
+   * @throws InterruptedException 
    */
-  public HRegionServer(Configuration conf) throws IOException {
+  public HRegionServer(Configuration conf) throws IOException, InterruptedException {
     machineName = DNS.getDefaultHost(conf.get(
         "hbase.regionserver.dns.interface", "default"), conf.get(
         "hbase.regionserver.dns.nameserver", "default"));
@@ -307,8 +308,9 @@ public class HRegionServer implements HR
    * call it.
    *
    * @throws IOException
+   * @throws InterruptedException 
    */
-  private void initialize() throws IOException {
+  private void initialize() throws IOException, InterruptedException {
     this.abortRequested = false;
     this.stopped = false;
 
@@ -335,7 +337,7 @@ public class HRegionServer implements HR
     }
   }
 
-  private void initializeZooKeeper() throws IOException {
+  private void initializeZooKeeper() throws IOException, InterruptedException {
     // open connection to zookeeper and set primary watcher
     zooKeeper = new ZooKeeperWatcher(conf, REGIONSERVER + "-"
         + serverInfo.getServerName(), this);

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java Fri Aug 13 06:33:06 2010
@@ -48,25 +48,33 @@ public class RootRegionTracker extends Z
   }
 
   /**
-   * Gets the root region location, if available.  Null if not.
-   * @return server address for server hosting root region, null if none
-   *         available
+   * Gets the root region location, if available.  Null if not.  Does not block.
+   * @return server address for server hosting root region, null if none available
+   * @throws InterruptedException 
    */
-  public HServerAddress getRootRegionLocation() {
-    byte [] data = super.getData();
-    return data == null ? null : new HServerAddress(Bytes.toString(data));
+  public HServerAddress getRootRegionLocation() throws InterruptedException {
+    return dataToHServerAddress(super.getData());
   }
 
   /**
    * Gets the root region location, if available, and waits for up to the
    * specified timeout if not immediately available.
-   * @param timeout maximum time to wait, in millis, use 0 for forever
+   * @param timeout maximum time to wait, in millis, use {@link ZooKeeperNodeTracker#NO_TIMEOUT} for
+   * forever
    * @return server address for server hosting root region, null if timed out
    * @throws InterruptedException if interrupted while waiting
    */
   public HServerAddress waitRootRegionLocation(long timeout)
   throws InterruptedException {
-    byte [] data = super.blockUntilAvailable(timeout);
-    return data == null ? null : new HServerAddress(Bytes.toString(data));
+    return dataToHServerAddress(super.blockUntilAvailable(timeout));
+  }
+
+  /*
+   * @param data
+   * @return Returns null if <code>data</code> is null else converts passed data
+   * to an HServerAddress instance.
+   */
+  private static HServerAddress dataToHServerAddress(final byte [] data) {
+    return data == null ? null: new HServerAddress(Bytes.toString(data));
   }
 }
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java Fri Aug 13 06:33:06 2010
@@ -32,6 +32,10 @@ import org.apache.zookeeper.KeeperExcept
  * RegionServers.
  */
 public abstract class ZooKeeperNodeTracker extends ZooKeeperListener {
+  /**
+   * Pass this if you do not want a timeout.
+   */
+  public final static long NO_TIMEOUT = -1;
 
   /** Path of node being tracked */
   protected final String node;
@@ -89,10 +93,7 @@ public abstract class ZooKeeperNodeTrack
    */
   public synchronized byte [] blockUntilAvailable()
   throws InterruptedException {
-    while(data == null) {
-      wait();
-    }
-    return data;
+    return blockUntilAvailable(NO_TIMEOUT);
   }
 
   /**
@@ -100,18 +101,19 @@ public abstract class ZooKeeperNodeTrack
    * specified timeout has elapsed.
    *
    * @param timeout maximum time to wait for the node data to be available,
-   *                in milliseconds
+   *                in milliseconds.  Pass {@link #NO_TIMEOUT} for no timeout.
    * @return data of the node
    * @throws InterruptedException if the waiting thread is interrupted
    */
   public synchronized byte [] blockUntilAvailable(long timeout)
   throws InterruptedException {
-    while(data == null) {
-      if (timeout == -1) {
-        wait();
-      } else {
-        wait(timeout);
-      }
+    if (timeout != NO_TIMEOUT && timeout < 0) throw new IllegalArgumentException();
+    long startTime = System.currentTimeMillis();
+    long remaining = timeout;
+    while ((remaining == NO_TIMEOUT || remaining > 0) && this.data == null) {
+      if (remaining == NO_TIMEOUT) wait();
+      else wait(remaining);
+      remaining = timeout - (System.currentTimeMillis() - startTime);
     }
     return data;
   }
@@ -167,4 +169,4 @@ public abstract class ZooKeeperNodeTrack
       nodeCreated(path);
     }
   }
-}
+}
\ No newline at end of file

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java Fri Aug 13 06:33:06 2010
@@ -83,7 +83,7 @@ public class MiniHBaseCluster {
       new ConcurrentHashMap<HServerInfo, IOException>();
 
     public MiniHBaseClusterMaster(final Configuration conf)
-    throws IOException, KeeperException {
+    throws IOException, KeeperException, InterruptedException {
       super(conf);
     }
 
@@ -152,7 +152,7 @@ public class MiniHBaseCluster {
     private Thread shutdownThread = null;
 
     public MiniHBaseClusterRegionServer(Configuration conf)
-        throws IOException {
+        throws IOException, InterruptedException {
       super(setDifferentUser(conf));
     }
 

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java Fri Aug 13 06:33:06 2010
@@ -19,9 +19,11 @@
  */
 package org.apache.hadoop.hbase.master;
 
+import static org.junit.Assert.*;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -30,6 +32,7 @@ import org.apache.hadoop.hbase.HBaseConf
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.client.MetaScanner;
 import org.apache.hadoop.hbase.executor.EventHandler.EventType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
@@ -82,6 +85,9 @@ public class TestRestartCluster {
       utility.createTable(TABLE, FAMILY);
       utility.waitTableAvailable(TABLE, 30000);
     }
+    List<HRegionInfo> allRegions =
+      MetaScanner.listAllRegions(utility.getConfiguration());
+    assertEquals(3, allRegions.size());
 
     LOG.info("\n\nShutting down cluster");
     utility.getHBaseCluster().shutdown();
@@ -93,6 +99,9 @@ public class TestRestartCluster {
     LOG.info("\n\nStarting cluster the second time");
     utility.restartHBaseCluster(3);
 
+    allRegions = MetaScanner.listAllRegions(utility.getConfiguration());
+    assertEquals(3, allRegions.size());
+
     LOG.info("\n\nWaiting for tables to be available");
     for(byte [] TABLE : TABLES) {
       try {

Modified: hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java?rev=985106&r1=985105&r2=985106&view=diff
==============================================================================
--- hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java (original)
+++ hbase/branches/0.90_master_rewrite/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperNodeTracker.java Fri Aug 13 06:33:06 2010
@@ -37,8 +37,8 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -46,7 +46,6 @@ import org.junit.Test;
 
 public class TestZooKeeperNodeTracker {
   private static final Log LOG = LogFactory.getLog(TestZooKeeperNodeTracker.class);
-
   private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
 
   private final static Random rand = new Random();
@@ -69,11 +68,11 @@ public class TestZooKeeperNodeTracker {
         "testNodeTracker", abortable);
     ZKUtil.createAndFailSilent(zk, zk.baseZNode);
 
-    String node =
+    final String node =
       ZKUtil.joinZNode(zk.baseZNode, new Long(rand.nextLong()).toString());
 
-    byte [] dataOne = Bytes.toBytes("dataOne");
-    byte [] dataTwo = Bytes.toBytes("dataTwo");
+    final byte [] dataOne = Bytes.toBytes("dataOne");
+    final byte [] dataTwo = Bytes.toBytes("dataTwo");
 
     // Start a ZKNT with no node currently available
     TestTracker localTracker = new TestTracker(zk, node, abortable);
@@ -97,7 +96,7 @@ public class TestZooKeeperNodeTracker {
 
     // Create a completely separate zk connection for test triggers and avoid
     // any weird watcher interactions from the test
-    ZooKeeper zkconn = new ZooKeeper(
+    final ZooKeeper zkconn = new ZooKeeper(
         ZKConfig.getZKQuorumServersString(TEST_UTIL.getConfiguration()), 60000,
         new StubWatcher());
 
@@ -176,7 +175,6 @@ public class TestZooKeeperNodeTracker {
     assertTrue(thread.hasData);
     assertTrue(Bytes.equals(thread.tracker.getData(), dataOne));
     LOG.info("Successfully got data one following a data change on all trackers and threads");
-
   }
 
   public static class WaitToGetDataThread extends Thread {