Author: stack
Date: Wed Sep  1 22:14:40 2010
New Revision: 991734

URL: http://svn.apache.org/viewvc?rev=991734&view=rev
Log:
HBASE-2857 HBaseAdmin.tableExists() should not require a full meta scan

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
    
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java

Modified: hbase/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=991734&r1=991733&r2=991734&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Wed Sep  1 22:14:40 2010
@@ -873,6 +873,7 @@ Release 0.21.0 - Unreleased
                thread only.
    HBASE-1676  load balancing on a large cluster doesn't work very well
    HBASE-2953  Edit of hbase-default.xml removing stale configs.
+   HBASE-2857  HBaseAdmin.tableExists() should not require a full meta scan
 
   NEW FEATURES
    HBASE-1961  HBase EC2 scripts

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=991734&r1=991733&r2=991734&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java 
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java 
Wed Sep  1 22:14:40 2010
@@ -138,24 +138,21 @@ public class HBaseAdmin implements Abort
   /**
    * @param tableName Table to check.
    * @return True if table exists already.
-   * @throws MasterNotRunningException if the master is not running
-   * @throws ZooKeeperConnectionException if unable to connect to zookeeper
+   * @throws IOException 
    */
   public boolean tableExists(final String tableName)
-  throws MasterNotRunningException, ZooKeeperConnectionException {
-    return tableExists(Bytes.toBytes(tableName));
+  throws IOException {
+    return MetaReader.tableExists(getCatalogTracker(), tableName);
   }
 
   /**
    * @param tableName Table to check.
    * @return True if table exists already.
-   * @throws MasterNotRunningException if the master is not running
-   * @throws ZooKeeperConnectionException if unable to connect to zookeeper
+   * @throws IOException 
    */
   public boolean tableExists(final byte [] tableName)
-  throws MasterNotRunningException, ZooKeeperConnectionException {
-    connection.isMasterRunning();
-    return connection.tableExists(tableName);
+  throws IOException {
+    return tableExists(Bytes.toString(tableName));
   }
 
   /**
@@ -945,11 +942,10 @@ public class HBaseAdmin implements Abort
    * @return True if <code>tableNameOrRegionName</code> is *possibly* a region
    * name else false if a verified tablename (we call {...@link 
#tableExists(byte[])};
    * else we throw an exception.
-   * @throws ZooKeeperConnectionException 
-   * @throws MasterNotRunningException 
+   * @throws IOException 
    */
   private boolean isRegionName(final byte [] tableNameOrRegionName)
-  throws MasterNotRunningException, ZooKeeperConnectionException {
+  throws IOException {
     if (tableNameOrRegionName == null) {
       throw new IllegalArgumentException("Pass a table name or region name");
     }

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=991734&r1=991733&r2=991734&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java 
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnection.java 
Wed Sep  1 22:14:40 2010
@@ -60,16 +60,6 @@ public interface HConnection {
   throws MasterNotRunningException, ZooKeeperConnectionException;
 
   /**
-   * Checks if <code>tableName</code> exists.
-   * @param tableName Table to check.
-   * @return True if table exists already.
-   * @throws MasterNotRunningException if the master is not running
-   * @throws ZooKeeperConnectionException if unable to connect to zookeeper
-   */
-  public boolean tableExists(final byte [] tableName)
-  throws MasterNotRunningException, ZooKeeperConnectionException;
-
-  /**
    * A table that isTableEnabled == false and isTableDisabled == false
    * is possible. This happens when a table has a lot of regions
    * that must be processed.

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=991734&r1=991733&r2=991734&view=diff
==============================================================================
--- 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
 (original)
+++ 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
 Wed Sep  1 22:14:40 2010
@@ -61,7 +61,6 @@ import org.apache.hadoop.hbase.ipc.HBase
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.MetaUtils;
 import org.apache.hadoop.hbase.util.SoftValueSortedMap;
 import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.hbase.zookeeper.ZKTableDisable;
@@ -370,38 +369,6 @@ public class HConnectionManager {
       throw new MasterNotRunningException();
     }
 
-    public boolean tableExists(final byte [] tableName)
-    throws MasterNotRunningException, ZooKeeperConnectionException {
-      getMaster();
-      if (tableName == null) {
-        throw new IllegalArgumentException("Table name cannot be null");
-      }
-      if (isMetaTableName(tableName)) {
-        return true;
-      }
-      boolean exists = false;
-      try {
-        HTableDescriptor[] tables = listTables();
-        for (HTableDescriptor table : tables) {
-          if (Bytes.equals(table.getName(), tableName)) {
-            exists = true;
-          }
-        }
-      } catch (IOException e) {
-        LOG.warn("Testing for table existence threw exception", e);
-      }
-      return exists;
-    }
-
-    /*
-     * @param n
-     * @return Truen if passed tablename <code>n</code> is equal to the name
-     * of a catalog table.
-     */
-    private static boolean isMetaTableName(final byte [] n) {
-      return MetaUtils.isMetaTableName(n);
-    }
-
     public HRegionLocation getRegionLocation(final byte [] name,
         final byte [] row, boolean reload)
     throws IOException {
@@ -409,7 +376,6 @@ public class HConnectionManager {
     }
 
     public HTableDescriptor[] listTables() throws IOException {
-      getMaster();
       final TreeSet<HTableDescriptor> uniqueTables =
         new TreeSet<HTableDescriptor>();
       MetaScannerVisitor visitor = new MetaScannerVisitor() {
@@ -433,7 +399,6 @@ public class HConnectionManager {
         }
       };
       MetaScanner.metaScan(conf, visitor);
-
       return uniqueTables.toArray(new HTableDescriptor[uniqueTables.size()]);
     }
 
@@ -475,10 +440,6 @@ public class HConnectionManager {
      */
     private boolean testTableOnlineState(byte[] tableName, boolean online)
     throws IOException {
-      // TODO: Replace w/ CatalogTracker-based tableExists test.
-      if (!tableExists(tableName)) {
-        throw new TableNotFoundException(Bytes.toString(tableName));
-      }
       if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
         // The root region is always enabled
         return true;


Reply via email to