From 9df1c244a07c2c750f59d798d074adbbf9bee8b4 Mon Sep 17 00:00:00 2001 From: Andrey Stepachev Date: Wed, 25 Mar 2015 22:57:37 +0000 Subject: [PATCH] HBASE-13326 Disabled table can't be enabled after HBase is restarted --- .../hbase/master/AssignmentManager.java | 7 ++++++ .../handler/TestEnableTableHandler.java | 22 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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 3e895b4d066..b1a1cc73a4d 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 @@ -2893,6 +2893,13 @@ public class AssignmentManager extends ZooKeeperListener { } ServerName lastHost = hrl.getServerName(); ServerName regionLocation = RegionStateStore.getRegionServer(result, replicaId); + if (tableStateManager.isTableState(regionInfo.getTable(), + ZooKeeperProtos.Table.State.DISABLED)) { + // force region to forget it hosts for disabled/disabling tables. + // see HBASE-13326 + lastHost = null; + regionLocation = null; + } regionStates.createRegionState(regionInfo, state, regionLocation, lastHost); if (!regionStates.isRegionInState(regionInfo, State.OPEN)) { // Region is not open (either offline or in transition), skip diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java index 87b6e9b87a0..4f97a2e3cee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java @@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Delete; @@ -112,6 +111,27 @@ public class TestEnableTableHandler { assertEquals(tableName, onlineRegions.get(1).getTable()); } + + @Test(timeout = 300000) + public void testDisableTableAndRestart() throws Exception { + final TableName tableName = TableName.valueOf("testDisableTableAndRestart"); + final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); + final HTableDescriptor desc = new HTableDescriptor(tableName); + desc.addFamily(new HColumnDescriptor(FAMILYNAME)); + admin.createTable(desc); + admin.disableTable(tableName); + TEST_UTIL.waitTableDisabled(tableName.getName()); + + TEST_UTIL.getHBaseCluster().shutdown(); + TEST_UTIL.getHBaseCluster().waitUntilShutDown(); + + TEST_UTIL.restartHBaseCluster(2); + + admin.enableTable(tableName); + TEST_UTIL.waitTableEnabled(tableName); + } + /** * We were only clearing rows that had a hregioninfo column in hbase:meta. Mangled rows that * were missing the hregioninfo because of error were being left behind messing up any