You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2012/08/14 22:46:18 UTC

svn commit: r1373074 - /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java

Author: tedyu
Date: Tue Aug 14 20:46:17 2012
New Revision: 1373074

URL: http://svn.apache.org/viewvc?rev=1373074&view=rev
Log:
HBASE-6576 HBaseAdmin.createTable should wait until the table is enabled (Gregory Chanan)


Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1373074&r1=1373073&r2=1373074&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Tue Aug 14 20:46:17 2012
@@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.NotServin
 import org.apache.hadoop.hbase.RegionException;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.TableNotEnabledException;
 import org.apache.hadoop.hbase.TableNotFoundException;
 import org.apache.hadoop.hbase.UnknownRegionException;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
@@ -399,57 +400,66 @@ public class HBaseAdmin implements Abort
     }
     int numRegs = splitKeys == null ? 1 : splitKeys.length + 1;
     int prevRegCount = 0;
+    boolean doneWithMetaScan = false;
     for (int tries = 0; tries < this.numRetries * this.retryLongerMultiplier;
       ++tries) {
-      // Wait for new table to come on-line
-      final AtomicInteger actualRegCount = new AtomicInteger(0);
-      MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
-        @Override
-        public boolean processRow(Result rowResult) throws IOException {
-          HRegionInfo info = Writables.getHRegionInfoOrNull(
+      if (!doneWithMetaScan) {
+        // Wait for new table to come on-line
+        final AtomicInteger actualRegCount = new AtomicInteger(0);
+        MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
+          @Override
+          public boolean processRow(Result rowResult) throws IOException {
+            HRegionInfo info = Writables.getHRegionInfoOrNull(
               rowResult.getValue(HConstants.CATALOG_FAMILY,
-                  HConstants.REGIONINFO_QUALIFIER));
-          //If regioninfo is null, skip this row
-          if (null == info) {
+              HConstants.REGIONINFO_QUALIFIER));
+            //If regioninfo is null, skip this row
+            if (null == info) {
+              return true;
+            }
+            if (!(Bytes.equals(info.getTableName(), desc.getName()))) {
+              return false;
+            }
+            String hostAndPort = null;
+            byte [] value = rowResult.getValue(HConstants.CATALOG_FAMILY,
+              HConstants.SERVER_QUALIFIER);
+            // Make sure that regions are assigned to server
+            if (value != null && value.length > 0) {
+              hostAndPort = Bytes.toString(value);
+            }
+            if (!(info.isOffline() || info.isSplit()) && hostAndPort != null) {
+              actualRegCount.incrementAndGet();
+            }
             return true;
           }
-          if (!(Bytes.equals(info.getTableName(), desc.getName()))) {
-            return false;
+        };
+        MetaScanner.metaScan(conf, visitor, desc.getName());
+        if (actualRegCount.get() != numRegs) {
+          if (tries == this.numRetries * this.retryLongerMultiplier - 1) {
+            throw new RegionOfflineException("Only " + actualRegCount.get() +
+              " of " + numRegs + " regions are online; retries exhausted.");
           }
-          String hostAndPort = null;
-          byte [] value = rowResult.getValue(HConstants.CATALOG_FAMILY,
-              HConstants.SERVER_QUALIFIER);
-          // Make sure that regions are assigned to server
-          if (value != null && value.length > 0) {
-            hostAndPort = Bytes.toString(value);
+          try { // Sleep
+            Thread.sleep(getPauseTime(tries));
+          } catch (InterruptedException e) {
+            throw new InterruptedIOException("Interrupted when opening" +
+              " regions; " + actualRegCount.get() + " of " + numRegs +
+              " regions processed so far");
           }
-          if (!(info.isOffline() || info.isSplit()) && hostAndPort != null) {
-            actualRegCount.incrementAndGet();
+          if (actualRegCount.get() > prevRegCount) { // Making progress
+            prevRegCount = actualRegCount.get();
+            tries = -1;
           }
-          return true;
-        }
-      };
-      MetaScanner.metaScan(conf, visitor, desc.getName());
-      if (actualRegCount.get() != numRegs) {
-        if (tries == this.numRetries * this.retryLongerMultiplier - 1) {
-          throw new RegionOfflineException("Only " + actualRegCount.get() +
-            " of " + numRegs + " regions are online; retries exhausted.");
-        }
-        try { // Sleep
-          Thread.sleep(getPauseTime(tries));
-        } catch (InterruptedException e) {
-          throw new InterruptedIOException("Interrupted when opening" +
-              " regions; " + actualRegCount.get() + " of " + numRegs + 
-              " regions processed so far");
-        }
-        if (actualRegCount.get() > prevRegCount) { // Making progress
-          prevRegCount = actualRegCount.get();
-          tries = -1;
+        } else {
+          doneWithMetaScan = true;
         }
-      } else {
+      }
+      if (doneWithMetaScan && isTableEnabled(desc.getName())) {
         return;
       }
     }
+    throw new TableNotEnabledException(
+      "Retries exhausted while still waiting for table: "
+      + desc.getNameAsString() + " to be enabled");
   }
 
   /**