diff --git a/CHANGES.txt b/CHANGES.txt
index 3d7f311427a..9357f032947 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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
diff --git a/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
index b52a7e193f4..d0ad1c97924 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
@@ -138,24 +138,21 @@ public class HBaseAdmin implements Abortable {
/**
* @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 Abortable {
* @return True if tableNameOrRegionName
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");
}
diff --git a/src/main/java/org/apache/hadoop/hbase/client/HConnection.java b/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
index e1233fb0255..e80a4f80b30 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
@@ -59,16 +59,6 @@ public interface HConnection {
public boolean isMasterRunning()
throws MasterNotRunningException, ZooKeeperConnectionException;
- /**
- * Checks if tableName
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
diff --git a/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
index 91747c5826a..4c703399f12 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
@@ -61,7 +61,6 @@ import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
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 n
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 uniqueTables =
new TreeSet();
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;