Index: hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java =================================================================== --- hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java (revision 1456797) +++ hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java (working copy) @@ -364,4 +364,20 @@ } return allTables; } + + /** + * If the table is found in ENABLING state the inmemory state is removed. This + * helps in cases where CreateTable is to be retried by the client incase of + * failures + * + * @param tableName + */ + public void removeEnablingTable(final String tableName) { + synchronized (this.cache) { + if (isEnablingTable(tableName)) { + this.cache.remove(tableName); + } + + } + } } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java (revision 1456797) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java (working copy) @@ -166,6 +166,15 @@ * @param exception null if process() is successful or not null if something has failed. */ protected void completed(final Throwable exception) { + // Try deleting the enabling node in case of error + // If this does not happen then if the client tries to create the table + // again with the same Active master + // It will block the creation saying TableAlreadyExists. + if (exception != null) { + this.assignmentManager.getZKTable().removeEnablingTable( + this.hTableDescriptor.getNameAsString()); + } + } /** @@ -186,6 +195,15 @@ Path tempdir = fileSystemManager.getTempDir(); FileSystem fs = fileSystemManager.getFileSystem(); + try { + createTableInternals(tableName, tempdir, fs); + } finally { + releaseTableLock(); + } + } + + private void createTableInternals(String tableName, Path tempdir, FileSystem fs) + throws IOException, InterruptedIOException { // 1. Create Table Descriptor FSTableDescriptors.createTableDescriptor(fs, tempdir, this.hTableDescriptor); Path tempTableDir = new Path(tempdir, tableName); @@ -222,8 +240,6 @@ } catch (KeeperException e) { throw new IOException("Unable to ensure that " + tableName + " will be" + " enabled because of a ZooKeeper issue", e); - } finally { - releaseTableLock(); } }