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:
parent
34efa17d46
commit
1e70bfbb00
|
@ -873,6 +873,7 @@ Release 0.21.0 - Unreleased
|
||||||
thread only.
|
thread only.
|
||||||
HBASE-1676 load balancing on a large cluster doesn't work very well
|
HBASE-1676 load balancing on a large cluster doesn't work very well
|
||||||
HBASE-2953 Edit of hbase-default.xml removing stale configs.
|
HBASE-2953 Edit of hbase-default.xml removing stale configs.
|
||||||
|
HBASE-2857 HBaseAdmin.tableExists() should not require a full meta scan
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
HBASE-1961 HBase EC2 scripts
|
HBASE-1961 HBase EC2 scripts
|
||||||
|
|
|
@ -138,24 +138,21 @@ public class HBaseAdmin implements Abortable {
|
||||||
/**
|
/**
|
||||||
* @param tableName Table to check.
|
* @param tableName Table to check.
|
||||||
* @return True if table exists already.
|
* @return True if table exists already.
|
||||||
* @throws MasterNotRunningException if the master is not running
|
* @throws IOException
|
||||||
* @throws ZooKeeperConnectionException if unable to connect to zookeeper
|
|
||||||
*/
|
*/
|
||||||
public boolean tableExists(final String tableName)
|
public boolean tableExists(final String tableName)
|
||||||
throws MasterNotRunningException, ZooKeeperConnectionException {
|
throws IOException {
|
||||||
return tableExists(Bytes.toBytes(tableName));
|
return MetaReader.tableExists(getCatalogTracker(), tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tableName Table to check.
|
* @param tableName Table to check.
|
||||||
* @return True if table exists already.
|
* @return True if table exists already.
|
||||||
* @throws MasterNotRunningException if the master is not running
|
* @throws IOException
|
||||||
* @throws ZooKeeperConnectionException if unable to connect to zookeeper
|
|
||||||
*/
|
*/
|
||||||
public boolean tableExists(final byte [] tableName)
|
public boolean tableExists(final byte [] tableName)
|
||||||
throws MasterNotRunningException, ZooKeeperConnectionException {
|
throws IOException {
|
||||||
connection.isMasterRunning();
|
return tableExists(Bytes.toString(tableName));
|
||||||
return connection.tableExists(tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -945,11 +942,10 @@ public class HBaseAdmin implements Abortable {
|
||||||
* @return True if <code>tableNameOrRegionName</code> is *possibly* a region
|
* @return True if <code>tableNameOrRegionName</code> is *possibly* a region
|
||||||
* name else false if a verified tablename (we call {@link #tableExists(byte[])};
|
* name else false if a verified tablename (we call {@link #tableExists(byte[])};
|
||||||
* else we throw an exception.
|
* else we throw an exception.
|
||||||
* @throws ZooKeeperConnectionException
|
* @throws IOException
|
||||||
* @throws MasterNotRunningException
|
|
||||||
*/
|
*/
|
||||||
private boolean isRegionName(final byte [] tableNameOrRegionName)
|
private boolean isRegionName(final byte [] tableNameOrRegionName)
|
||||||
throws MasterNotRunningException, ZooKeeperConnectionException {
|
throws IOException {
|
||||||
if (tableNameOrRegionName == null) {
|
if (tableNameOrRegionName == null) {
|
||||||
throw new IllegalArgumentException("Pass a table name or region name");
|
throw new IllegalArgumentException("Pass a table name or region name");
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,16 +59,6 @@ public interface HConnection {
|
||||||
public boolean isMasterRunning()
|
public boolean isMasterRunning()
|
||||||
throws MasterNotRunningException, ZooKeeperConnectionException;
|
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
|
* A table that isTableEnabled == false and isTableDisabled == false
|
||||||
* is possible. This happens when a table has a lot of regions
|
* is possible. This happens when a table has a lot of regions
|
||||||
|
|
|
@ -61,7 +61,6 @@ import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
|
||||||
import org.apache.hadoop.hbase.ipc.HMasterInterface;
|
import org.apache.hadoop.hbase.ipc.HMasterInterface;
|
||||||
import org.apache.hadoop.hbase.ipc.HRegionInterface;
|
import org.apache.hadoop.hbase.ipc.HRegionInterface;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
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.SoftValueSortedMap;
|
||||||
import org.apache.hadoop.hbase.util.Writables;
|
import org.apache.hadoop.hbase.util.Writables;
|
||||||
import org.apache.hadoop.hbase.zookeeper.ZKTableDisable;
|
import org.apache.hadoop.hbase.zookeeper.ZKTableDisable;
|
||||||
|
@ -370,38 +369,6 @@ public class HConnectionManager {
|
||||||
throw new MasterNotRunningException();
|
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,
|
public HRegionLocation getRegionLocation(final byte [] name,
|
||||||
final byte [] row, boolean reload)
|
final byte [] row, boolean reload)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -409,7 +376,6 @@ public class HConnectionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTableDescriptor[] listTables() throws IOException {
|
public HTableDescriptor[] listTables() throws IOException {
|
||||||
getMaster();
|
|
||||||
final TreeSet<HTableDescriptor> uniqueTables =
|
final TreeSet<HTableDescriptor> uniqueTables =
|
||||||
new TreeSet<HTableDescriptor>();
|
new TreeSet<HTableDescriptor>();
|
||||||
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
||||||
|
@ -433,7 +399,6 @@ public class HConnectionManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MetaScanner.metaScan(conf, visitor);
|
MetaScanner.metaScan(conf, visitor);
|
||||||
|
|
||||||
return uniqueTables.toArray(new HTableDescriptor[uniqueTables.size()]);
|
return uniqueTables.toArray(new HTableDescriptor[uniqueTables.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,10 +440,6 @@ public class HConnectionManager {
|
||||||
*/
|
*/
|
||||||
private boolean testTableOnlineState(byte[] tableName, boolean online)
|
private boolean testTableOnlineState(byte[] tableName, boolean online)
|
||||||
throws IOException {
|
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)) {
|
if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
|
||||||
// The root region is always enabled
|
// The root region is always enabled
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue