From a4a4e97338e763fdf990f5a23e0ce47e47834360 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Fri, 24 Feb 2012 00:41:31 +0000 Subject: [PATCH] HBASE-5415 FSTableDescriptors should handle random folders in hbase.root.dir better git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1293042 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/hbase/TableDescriptors.java | 4 ++-- .../apache/hadoop/hbase/master/CatalogJanitor.java | 2 +- .../hadoop/hbase/master/DefaultLoadBalancer.java | 7 ++----- .../hbase/master/handler/TableEventHandler.java | 2 +- .../apache/hadoop/hbase/util/FSTableDescriptors.java | 12 +++++++----- .../hadoop/hbase/master/TestCatalogJanitor.java | 4 ++-- .../hadoop/hbase/util/TestFSTableDescriptors.java | 5 +++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java b/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java index 50bff2b74ea..145589504b5 100644 --- a/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java +++ b/src/main/java/org/apache/hadoop/hbase/TableDescriptors.java @@ -34,7 +34,7 @@ public interface TableDescriptors { * @throws IOException */ public HTableDescriptor get(final String tablename) - throws TableExistsException, FileNotFoundException, IOException; + throws FileNotFoundException, IOException; /** * @param tablename @@ -44,7 +44,7 @@ public interface TableDescriptors { * @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 diff --git a/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java b/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java index 5e4c5749dc3..4ee75ee948e 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java +++ b/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java @@ -321,7 +321,7 @@ class CatalogJanitor extends Chore { } private HTableDescriptor getTableDescriptor(byte[] tableName) - throws TableExistsException, FileNotFoundException, IOException { + throws FileNotFoundException, IOException { return this.services.getTableDescriptors().get(Bytes.toString(tableName)); } } diff --git a/src/main/java/org/apache/hadoop/hbase/master/DefaultLoadBalancer.java b/src/main/java/org/apache/hadoop/hbase/master/DefaultLoadBalancer.java index 702f622765a..9b132c0286a 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/DefaultLoadBalancer.java +++ b/src/main/java/org/apache/hadoop/hbase/master/DefaultLoadBalancer.java @@ -687,17 +687,14 @@ public class DefaultLoadBalancer implements LoadBalancer { { 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 diff --git a/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java b/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java index 58d54543d7d..af5b96a412a 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java +++ b/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java @@ -272,7 +272,7 @@ public abstract class TableEventHandler extends EventHandler { * @throws IOException */ HTableDescriptor getTableDescriptor() - throws TableExistsException, FileNotFoundException, IOException { + throws FileNotFoundException, IOException { final String name = Bytes.toString(tableName); HTableDescriptor htd = this.masterServices.getTableDescriptors().get(name); diff --git a/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java b/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java index 5b260e2027c..a59acde01b4 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java +++ b/src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java @@ -122,7 +122,7 @@ public class FSTableDescriptors implements TableDescriptors { */ @Override public HTableDescriptor get(final byte [] tablename) - throws TableExistsException, FileNotFoundException, IOException { + throws FileNotFoundException, IOException { return get(Bytes.toString(tablename)); } @@ -131,7 +131,7 @@ public class FSTableDescriptors implements TableDescriptors { */ @Override public HTableDescriptor get(final String tablename) - throws TableExistsException, FileNotFoundException, IOException { + throws FileNotFoundException, IOException { invocations++; if (HTableDescriptor.ROOT_TABLEDESC.getNameAsString().equals(tablename)) { cachehits++; @@ -160,10 +160,12 @@ public class FSTableDescriptors implements TableDescriptors { } 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; } diff --git a/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java b/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java index c4fa1d49e7c..a5628b95e2f 100644 --- a/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java +++ b/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java @@ -235,13 +235,13 @@ public class TestCatalogJanitor { @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(); } diff --git a/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java b/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java index 744270410f7..0db4d425f73 100644 --- a/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java +++ b/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java @@ -202,14 +202,15 @@ public class TestFSTableDescriptors { 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