HBASE-11703 Meta region state could be corrupted

This commit is contained in:
Jimmy Xiang 2014-08-07 20:58:17 -07:00
parent 9abe2da9e8
commit 1262f1e2d4
3 changed files with 48 additions and 8 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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<Exception>() {
@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
*/