Index: src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java (revision 1156970) +++ src/main/java/org/apache/hadoop/hbase/master/MasterFileSystem.java (working copy) @@ -414,7 +414,8 @@ * Create new HTableDescriptor in HDFS. * @param htableDescriptor */ - public void createTableDescriptor(HTableDescriptor htableDescriptor) { + public void createTableDescriptor(HTableDescriptor htableDescriptor) + throws IOException { FSUtils.createTableDescriptor(htableDescriptor, conf); } Index: src/main/java/org/apache/hadoop/hbase/util/FSUtils.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (revision 1156970) +++ src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (working copy) @@ -943,13 +943,14 @@ * @param htableDescriptor * @param conf */ - public static void createTableDescriptor(HTableDescriptor htableDescriptor, - Configuration conf) { + public static boolean createTableDescriptor( + HTableDescriptor htableDescriptor, Configuration conf) throws IOException { try { FileSystem fs = getCurrentFileSystem(conf); - createTableDescriptor(fs, getRootDir(conf), htableDescriptor); - } catch(IOException ioe) { + return createTableDescriptor(fs, getRootDir(conf), htableDescriptor); + } catch (IOException ioe) { LOG.info("IOException while trying to create tableInfo in HDFS", ioe); + throw ioe; } } @@ -958,22 +959,24 @@ * @param htableDescriptor * @param rootdir */ - public static void createTableDescriptor(FileSystem fs, - Path rootdir, HTableDescriptor htableDescriptor) { + public static boolean createTableDescriptor(FileSystem fs, Path rootdir, + HTableDescriptor htableDescriptor) throws IOException { try { - Path tableInfoPath = - getTableInfoPath(rootdir, htableDescriptor.getNameAsString()); - LOG.info("Current tableInfoPath = " + tableInfoPath) ; - if (fs.exists(tableInfoPath) && - fs.getFileStatus(tableInfoPath).getLen() > 0) { + Path tableInfoPath = getTableInfoPath(rootdir, htableDescriptor + .getNameAsString()); + LOG.info("Current tableInfoPath = " + tableInfoPath); + if (fs.exists(tableInfoPath) + && fs.getFileStatus(tableInfoPath).getLen() > 0) { LOG.info("TableInfo already exists.. Skipping creation"); - return; + return false; } - writeTableDescriptor(fs, htableDescriptor, - getTablePath(rootdir, htableDescriptor.getNameAsString())); - } catch(IOException ioe) { + writeTableDescriptor(fs, htableDescriptor, getTablePath(rootdir, + htableDescriptor.getNameAsString())); + } catch (IOException ioe) { LOG.info("IOException while trying to create tableInfo in HDFS", ioe); + throw ioe; } + return true; } /** Index: src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java (revision 1156970) +++ src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java (working copy) @@ -17,7 +17,11 @@ */ package org.apache.hadoop.hbase.util; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.io.FileNotFoundException; import java.io.IOException; @@ -32,8 +36,6 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableDescriptors; import org.apache.hadoop.hbase.TableExistsException; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.FSUtils; import org.junit.Test; @@ -145,4 +147,27 @@ htds.add(htd); htds.add(htd); } + + @Test + public void testShouldNotCreateTheSameTableDescriptor() throws IOException { + final String name = "testAlreadyExists"; + FileSystem fs = FileSystem.get(UTIL.getConfiguration()); + // Cleanup old tests if any detrius laying around. + Path rootdir = new Path(HBaseTestingUtility.getTestDir(), name); + TableDescriptors htds = new FSTableDescriptors(fs, rootdir); + HTableDescriptor htd = new HTableDescriptor(name); + htds.add(htd); + assertFalse("Should not create new table descriptor", FSUtils + .createTableDescriptor(fs, rootdir, htd)); + } + + @Test + public void testShouldReturnTrueIfNewHTDCanBeCreated() throws IOException { + final String name = "createNewTable2"; + FileSystem fs = FileSystem.get(UTIL.getConfiguration()); + Path rootdir = new Path(HBaseTestingUtility.getTestDir(), name); + HTableDescriptor htd = new HTableDescriptor(name); + assertTrue("Should create new table descriptor", FSUtils + .createTableDescriptor(fs, rootdir, htd)); + } }