HBASE-2857 HBaseAdmin.tableExists() should not require a full meta scan

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@991734 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-09-01 22:14:40 +00:00
parent 34efa17d46
commit 1e70bfbb00
4 changed files with 9 additions and 61 deletions

View File

@ -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

View File

@ -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 <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");
}

View File

@ -59,16 +59,6 @@ public interface HConnection {
public boolean isMasterRunning()
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

View File

@ -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 <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;