Skip to content

Commit

Permalink
HBASE-5415 FSTableDescriptors should handle random folders in
Browse files Browse the repository at this point in the history
               hbase.root.dir better


git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1293042 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jdcryans committed Feb 24, 2012
1 parent bb7d2b1 commit 268a7fe
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/apache/hadoop/hbase/TableDescriptors.java
Expand Up @@ -34,7 +34,7 @@ public interface TableDescriptors {
* @throws IOException
*/
public HTableDescriptor get(final String tablename)
throws TableExistsException, FileNotFoundException, IOException;
throws FileNotFoundException, IOException;

/**
* @param tablename
Expand All @@ -44,7 +44,7 @@ public HTableDescriptor get(final String tablename)
* @throws IOException
*/
public HTableDescriptor get(final byte[] tablename)
throws TableExistsException, FileNotFoundException, IOException;
throws FileNotFoundException, IOException;

/**
* Get Map of all HTableDescriptors. Populates the descriptor cache as a
Expand Down
Expand Up @@ -321,7 +321,7 @@ public boolean accept(Path path) {
}

private HTableDescriptor getTableDescriptor(byte[] tableName)
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
return this.services.getTableDescriptors().get(Bytes.toString(tableName));
}
}
Expand Up @@ -687,17 +687,14 @@ private HTableDescriptor getTableDescriptor(byte[] tableName)
{
tableDescriptor = this.services.getTableDescriptors().
get(Bytes.toString(tableName));
}
} catch (TableExistsException tee) {
LOG.debug("TableExistsException during getTableDescriptors." +
" Current table name = " + tableName , tee);
}
} catch (FileNotFoundException fnfe) {
LOG.debug("FileNotFoundException during getTableDescriptors." +
" Current table name = " + tableName , fnfe);
}

return tableDescriptor;
}
}

/**
* Map hostname to ServerName, The output ServerName list will have the same
Expand Down
Expand Up @@ -272,7 +272,7 @@ protected void handleInstantSchemaChanges(List<HRegionInfo> regions) {
* @throws IOException
*/
HTableDescriptor getTableDescriptor()
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
final String name = Bytes.toString(tableName);
HTableDescriptor htd =
this.masterServices.getTableDescriptors().get(name);
Expand Down
Expand Up @@ -122,7 +122,7 @@ public FSTableDescriptors(final FileSystem fs, final Path rootdir,
*/
@Override
public HTableDescriptor get(final byte [] tablename)
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
return get(Bytes.toString(tablename));
}

Expand All @@ -131,7 +131,7 @@ public HTableDescriptor get(final byte [] tablename)
*/
@Override
public HTableDescriptor get(final String tablename)
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
invocations++;
if (HTableDescriptor.ROOT_TABLEDESC.getNameAsString().equals(tablename)) {
cachehits++;
Expand Down Expand Up @@ -160,10 +160,12 @@ public HTableDescriptor get(final String tablename)
}
HTableDescriptor htd = getTableDescriptor(this.fs, this.rootdir, tablename);
if (htd == null) {
// More likely is above will throw a FileNotFoundException
throw new TableExistsException("No descriptor for " + tablename);
LOG.warn("The following folder is in HBase's root directory and " +
"doesn't contain a table descriptor, " +
"do consider deleting it: " + tablename);
} else {
this.cache.put(tablename, new TableDescriptorModtime(modtime, htd));
}
this.cache.put(tablename, new TableDescriptorModtime(modtime, htd));
return htd;
}

Expand Down
Expand Up @@ -235,13 +235,13 @@ public Map<String, HTableDescriptor> getAll() throws IOException {

@Override
public HTableDescriptor get(byte[] tablename)
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
return get(Bytes.toString(tablename));
}

@Override
public HTableDescriptor get(String tablename)
throws TableExistsException, FileNotFoundException, IOException {
throws FileNotFoundException, IOException {
return createHTableDescriptor();
}

Expand Down
Expand Up @@ -202,14 +202,15 @@ public HTableDescriptor get(byte[] tablename)
htds.cachehits >= ((count * 2) + 1));
}

@Test (expected=org.apache.hadoop.hbase.TableExistsException.class)
@Test
public void testNoSuchTable() throws IOException {
final String name = "testNoSuchTable";
FileSystem fs = FileSystem.get(UTIL.getConfiguration());
// Cleanup old tests if any detrius laying around.
Path rootdir = new Path(UTIL.getDataTestDir(), name);
TableDescriptors htds = new FSTableDescriptors(fs, rootdir);
htds.get("NoSuchTable");
assertNull("There shouldn't be any HTD for this table",
htds.get("NoSuchTable"));
}

@Test
Expand Down

0 comments on commit 268a7fe

Please sign in to comment.