use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestMaster method testMoveRegionWhenNotInitialized.
@Test
public void testMoveRegionWhenNotInitialized() {
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HMaster m = cluster.getMaster();
try {
// fake it, set back later
m.setInitialized(false);
HRegionInfo meta = HRegionInfo.FIRST_META_REGIONINFO;
m.move(meta.getEncodedNameAsBytes(), null);
fail("Region should not be moved since master is not initialized");
} catch (IOException ioe) {
assertTrue(ioe instanceof PleaseHoldException);
} finally {
m.setInitialized(true);
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentManagerOnCluster method testRestartMetaRegionServer.
/**
* 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);
}
RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
assertEquals("Meta should be not in transition", metaState.getState(), RegionState.State.OPEN);
assertNotEquals("Meta should be moved off master", metaState.getServerName(), master.getServerName());
assertEquals("Meta should be on the meta server", metaState.getServerName(), metaServerName);
cluster.killRegionServer(metaServerName);
stoppedARegionServer = true;
cluster.waitForRegionServerToStop(metaServerName, 60000);
// Wait for SSH to finish
final ServerName oldServerName = metaServerName;
final ServerManager serverManager = master.getServerManager();
TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return serverManager.isServerDead(oldServerName) && !serverManager.areDeadServersInProgress();
}
});
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
// Now, make sure meta is assigned
assertTrue("Meta should be assigned", regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO));
// Now, make sure meta is registered in zk
metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
assertEquals("Meta should be not in transition", metaState.getState(), RegionState.State.OPEN);
assertEquals("Meta should be assigned", metaState.getServerName(), regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO));
assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(), metaServerName);
} finally {
if (stoppedARegionServer) {
cluster.startRegionServer();
}
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentManagerOnCluster method testAssignOfflinedRegionBySSH.
/**
* Test offlined region is assigned by SSH
*/
@Test(timeout = 60000)
public void testAssignOfflinedRegionBySSH() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
MyMaster master = null;
try {
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY));
admin.createTable(desc);
Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME);
HRegionInfo hri = new HRegionInfo(desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z"));
MetaTableAccessor.addRegionToMeta(meta, hri);
// Assign the region
master = (MyMaster) cluster.getMaster();
AssignmentManager am = master.getAssignmentManager();
am.assign(hri);
RegionStates regionStates = am.getRegionStates();
ServerName metaServer = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO);
ServerName oldServerName = null;
while (true) {
assertTrue(am.waitForAssignment(hri));
RegionState state = regionStates.getRegionState(hri);
oldServerName = state.getServerName();
if (!ServerName.isSameHostnameAndPort(oldServerName, metaServer)) {
// Mark the hosting server aborted, but don't actually kill it.
// It doesn't have meta on it.
MyRegionServer.abortedServer = oldServerName;
break;
}
int i = cluster.getServerWithMeta();
HRegionServer rs = cluster.getRegionServer(i == 0 ? 1 : 0);
oldServerName = rs.getServerName();
master.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(oldServerName.getServerName()));
}
// Make sure the region is assigned on the dead server
assertTrue(regionStates.isRegionOnline(hri));
assertEquals(oldServerName, regionStates.getRegionServerOfRegion(hri));
// Kill the hosting server, which doesn't have meta on it.
cluster.killRegionServer(oldServerName);
cluster.waitForRegionServerToStop(oldServerName, -1);
ServerManager serverManager = master.getServerManager();
while (!serverManager.isServerDead(oldServerName) || serverManager.getDeadServers().areDeadServersInProgress()) {
Thread.sleep(100);
}
// Let's check if it's assigned after it's out of transition.
// no need to assign it manually, SSH should do it
am.waitOnRegionToClearRegionsInTransition(hri);
assertTrue(am.waitForAssignment(hri));
ServerName serverName = master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(hri);
TEST_UTIL.assertRegionOnlyOnServer(hri, serverName, 200);
} finally {
MyRegionServer.abortedServer = null;
TEST_UTIL.deleteTable(tableName);
cluster.startRegionServer();
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentListener method areAllRegionsLocatedOnSameServer.
private boolean areAllRegionsLocatedOnSameServer(TableName TABLE_NAME) {
MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
int serverCount = 0;
for (JVMClusterUtil.RegionServerThread regionThread : miniCluster.getRegionServerThreads()) {
if (!regionThread.getRegionServer().getOnlineRegions(TABLE_NAME).isEmpty()) {
++serverCount;
}
if (serverCount > 1) {
return false;
}
}
return serverCount == 1;
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestRSGroups method afterMethod.
@After
public void afterMethod() throws Exception {
deleteTableIfNecessary();
deleteNamespaceIfNecessary();
deleteGroups();
int missing = NUM_SLAVES_BASE - getNumServers();
LOG.info("Restoring servers: " + missing);
for (int i = 0; i < missing; i++) {
((MiniHBaseCluster) cluster).startRegionServer();
}
rsGroupAdmin.addRSGroup("master");
ServerName masterServerName = ((MiniHBaseCluster) cluster).getMaster().getServerName();
try {
rsGroupAdmin.moveServers(Sets.newHashSet(masterServerName.getAddress()), "master");
} catch (Exception ex) {
LOG.warn("Got this on setup, FYI", ex);
}
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
LOG.info("Waiting for cleanup to finish " + rsGroupAdmin.listRSGroups());
return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size() == NUM_SLAVES_BASE;
}
});
}
Aggregations