hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1522676 - in /hbase/branches/0.96: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Date Thu, 12 Sep 2013 17:36:56 GMT
Author: tedyu
Date: Thu Sep 12 17:36:56 2013
New Revision: 1522676

URL: http://svn.apache.org/r1522676
Log:
HBASE-9462 HBaseAdmin#isTableEnabled() should throw exception for non-existent table


Modified:
    hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java

Modified: hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1522676&r1=1522675&r2=1522676&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
(original)
+++ hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
Thu Sep 12 17:36:56 2013
@@ -772,7 +772,13 @@ public class HBaseAdmin implements Abort
     boolean enabled = false;
     long start = EnvironmentEdgeManager.currentTimeMillis();
     for (int tries = 0; tries < (this.numRetries * this.retryLongerMultiplier); tries++)
{
-      enabled = isTableEnabled(tableName) && isTableAvailable(tableName);
+      try {
+        enabled = isTableEnabled(tableName);
+      } catch (TableNotFoundException tnfe) {
+        // wait for table to be created
+        enabled = false;
+      }
+      enabled = enabled && isTableAvailable(tableName);
       if (enabled) {
         break;
       }
@@ -1001,12 +1007,23 @@ public class HBaseAdmin implements Abort
     return failed.toArray(new HTableDescriptor[failed.size()]);
   }
 
+  /*
+   * Checks whether table exists. If not, throws TableNotFoundException
+   * @param tableName
+   */
+  private void checkTableExistence(TableName tableName) throws IOException {
+    if (!tableExists(tableName)) {
+      throw new TableNotFoundException(tableName);
+    }
+  }
+  
   /**
    * @param tableName name of table to check
    * @return true if table is on-line
    * @throws IOException if a remote or network exception occurs
    */
   public boolean isTableEnabled(TableName tableName) throws IOException {
+    checkTableExistence(tableName);
     return connection.isTableEnabled(tableName);
   }
 
@@ -1026,6 +1043,7 @@ public class HBaseAdmin implements Abort
    * @throws IOException if a remote or network exception occurs
    */
   public boolean isTableDisabled(TableName tableName) throws IOException {
+    checkTableExistence(tableName);
     return connection.isTableDisabled(tableName);
   }
 

Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1522676&r1=1522675&r2=1522676&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
(original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Thu Sep 12 17:36:56 2013
@@ -367,7 +367,23 @@ public class TestAdmin {
            assertTrue(exceptionThrown);
        }
    }
-  /**
+  
+  @Test
+  public void testIsEnabledOrDisabledOnUnknownTable() throws Exception {
+    try {
+      admin.isTableEnabled(Bytes.toBytes("unkownTable"));
+      fail("Test should fail if isTableEnabled called on unknown table.");
+    } catch (IOException e) {
+    }
+
+    try {
+      admin.isTableDisabled(Bytes.toBytes("unkownTable"));
+      fail("Test should fail if isTableDisabled called on unknown table.");
+    } catch (IOException e) {
+    }
+  }
+   
+    /**
    * Verify schema modification takes.
    * @throws IOException
    * @throws InterruptedException



Mime
View raw message