diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 39cbed1b657..d03d86ddaae 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -2714,8 +2714,15 @@ public class AssignmentManager extends ZooKeeperListener { + " to ENABLED state."); // enableTable in sync way during master startup, // no need to invoke coprocessor - new EnableTableHandler(this.server, tableName, - catalogTracker, this, tableLockManager, true).prepare().process(); + EnableTableHandler eth = new EnableTableHandler(this.server, tableName, + catalogTracker, this, tableLockManager, true); + try { + eth.prepare(); + } catch (TableNotFoundException e) { + LOG.warn("Table " + tableName + " not found in hbase:meta to recover."); + continue; + } + eth.process(); } } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java index 8ebcb470c8b..0e21a2569aa 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java @@ -91,6 +91,7 @@ public class EnableTableHandler extends EventHandler { } try { this.assignmentManager.getZKTable().removeEnablingTable(tableName, true); + throw new TableNotFoundException(tableName); } catch (KeeperException e) { // TODO : Use HBCK to clear such nodes LOG.warn("Failed to delete the ENABLING node for the table " + tableName diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java index f4eb232cef4..408509f68ed 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java @@ -947,6 +947,35 @@ public class TestAssignmentManager { } } + /** + * Test verifies whether stale znodes of unknown tables as for the hbase:meta will be removed or + * not. + * @throws KeeperException + * @throws IOException + * @throws Exception + */ + @Test + public void testMasterRestartShouldRemoveStaleZnodesOfUnknownTableAsForMeta() + throws KeeperException, IOException, Exception { + List destServers = new ArrayList(1); + destServers.add(SERVERNAME_A); + Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers); + Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true); + HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0); + Server server = new HMaster(HTU.getConfiguration()); + Whitebox.setInternalState(server, "serverManager", this.serverManager); + AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server, + this.serverManager); + try { + TableName tableName = TableName.valueOf("dummyTable"); + // set table in enabling state. + am.getZKTable().setEnablingTable(tableName); + am.joinCluster(); + assertFalse("Table should not be present in zookeeper.", + am.getZKTable().isTablePresent(tableName)); + } finally { + } + } /** * When a region is in transition, if the region server opening the region goes down, * the region assignment takes a long time normally (waiting for timeout monitor to trigger assign).