diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java index f111107616b..36bc8e28ba1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java @@ -508,7 +508,7 @@ public class RegionStates { ServerName oldServerName = regionAssignments.remove(hri); if (oldServerName != null && serverHoldings.containsKey(oldServerName) && (newState == State.MERGED || newState == State.SPLIT - || tableStateManager.isTableState(hri.getTable(), + || hri.isMetaRegion() || tableStateManager.isTableState(hri.getTable(), ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING))) { // Offline the region only if it's merged/split, or the table is disabled/disabling. // Otherwise, offline it from this server only when it is online on a different server. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java index 5d26ac84ec4..f8674dae9a5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java @@ -156,13 +156,7 @@ public class ServerShutdownHandler extends EventHandler { while (!this.server.isStopped()) { try { server.getMetaTableLocator().waitMetaRegionLocation(server.getZooKeeper()); - // Skip getting user regions if the server is stopped. - if (!this.server.isStopped()) { - hris = am.getRegionStates().getServerRegions(serverName); - if (hris != null) { - hris.remove(HRegionInfo.FIRST_META_REGIONINFO); - } - } + hris = am.getRegionStates().getServerRegions(serverName); break; } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java index ff3a8d909a9..6b1cc23c932 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.master; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -100,6 +101,51 @@ public class TestAssignmentManagerOnCluster { TEST_UTIL.shutdownMiniCluster(); } + /** + * This tests restarting meta regionserver + */ + @Test (timeout=180000) + public void testRestartMetaRegionServer() throws Exception { + MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + boolean stoppedARegionServer = false; + try { + HMaster master = cluster.getMaster(); + RegionStates regionStates = master.getAssignmentManager().getRegionStates(); + ServerName metaServerName = regionStates.getRegionServerOfRegion( + HRegionInfo.FIRST_META_REGIONINFO); + if (master.getServerName().equals(metaServerName)) { + // Move meta off master + metaServerName = cluster.getLiveRegionServerThreads() + .get(0).getRegionServer().getServerName(); + master.move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), + Bytes.toBytes(metaServerName.getServerName())); + TEST_UTIL.waitUntilNoRegionsInTransition(60000); + } + assertNotEquals("Meta should be moved off master", + metaServerName, master.getServerName()); + cluster.killRegionServer(metaServerName); + stoppedARegionServer = true; + cluster.waitForRegionServerToStop(metaServerName, 60000); + + // Wait for SSH to finish + final ServerManager serverManager = master.getServerManager(); + TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate() { + @Override + public boolean evaluate() throws Exception { + return !serverManager.areDeadServersInProgress(); + } + }); + + // Now, make sure meta is assigned + assertTrue("Meta should be assigned", + regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO)); + } finally { + if (stoppedARegionServer) { + cluster.startRegionServer(); + } + } + } + /** * This tests region assignment */