use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAccessController method testGlobalAuthorizationForNewRegisteredRS.
@Test(timeout = 180000)
public void testGlobalAuthorizationForNewRegisteredRS() throws Exception {
LOG.debug("Test for global authorization for a new registered RegionServer.");
MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
final Admin admin = TEST_UTIL.getAdmin();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE2);
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
createTable(TEST_UTIL, htd);
// Starting a new RegionServer.
JVMClusterUtil.RegionServerThread newRsThread = hbaseCluster.startRegionServer();
final HRegionServer newRs = newRsThread.getRegionServer();
// Move region to the new RegionServer.
List<HRegionLocation> regions;
try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE2)) {
regions = locator.getAllRegionLocations();
}
HRegionLocation location = regions.get(0);
final HRegionInfo hri = location.getRegionInfo();
final ServerName server = location.getServerName();
try (Table table = systemUserConnection.getTable(TEST_TABLE2)) {
AccessTestAction moveAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
admin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(newRs.getServerName().getServerName()));
return null;
}
};
SUPERUSER.runAs(moveAction);
final int RETRIES_LIMIT = 10;
int retries = 0;
while (newRs.getOnlineRegions(TEST_TABLE2).size() < 1 && retries < RETRIES_LIMIT) {
LOG.debug("Waiting for region to be opened. Already retried " + retries + " times.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
retries++;
if (retries == RETRIES_LIMIT - 1) {
fail("Retry exhaust for waiting region to be opened.");
}
}
// Verify write permission for user "admin2" who has the global
// permissions.
AccessTestAction putAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
Put put = new Put(Bytes.toBytes("test"));
put.addColumn(TEST_FAMILY, Bytes.toBytes("qual"), Bytes.toBytes("value"));
table.put(put);
return null;
}
};
USER_ADMIN.runAs(putAction);
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentListener method testServerListener.
@Test(timeout = 60000)
public void testServerListener() throws IOException, InterruptedException {
ServerManager serverManager = TEST_UTIL.getHBaseCluster().getMaster().getServerManager();
DummyServerListener listener = new DummyServerListener();
serverManager.registerListener(listener);
try {
MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
// Start a new Region Server
miniCluster.startRegionServer();
listener.awaitModifications(1);
assertEquals(1, listener.getAddedCount());
assertEquals(0, listener.getRemovedCount());
// Start another Region Server
listener.reset();
miniCluster.startRegionServer();
listener.awaitModifications(1);
assertEquals(1, listener.getAddedCount());
assertEquals(0, listener.getRemovedCount());
int nrs = miniCluster.getRegionServerThreads().size();
// Stop a Region Server
listener.reset();
miniCluster.stopRegionServer(nrs - 1);
listener.awaitModifications(1);
assertEquals(0, listener.getAddedCount());
assertEquals(1, listener.getRemovedCount());
// Stop another Region Server
listener.reset();
miniCluster.stopRegionServer(nrs - 2);
listener.awaitModifications(1);
assertEquals(0, listener.getAddedCount());
assertEquals(1, listener.getRemovedCount());
} finally {
serverManager.unregisterListener(listener);
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentManagerOnCluster method testSSHWaitForServerToAssignRegion.
/**
* Test SSH waiting for extra region server for assignment
*/
@Test(timeout = 300000)
public void testSSHWaitForServerToAssignRegion() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
boolean startAServer = false;
try {
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY));
admin.createTable(desc);
HMaster master = cluster.getMaster();
final ServerManager serverManager = master.getServerManager();
MyLoadBalancer.countRegionServers = Integer.valueOf(serverManager.countOfRegionServers());
HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
assertNotNull("First region should be assigned", rs);
final ServerName serverName = rs.getServerName();
// Wait till SSH tried to assign regions a several times
int counter = MyLoadBalancer.counter.get() + 5;
cluster.killRegionServer(serverName);
startAServer = true;
cluster.waitForRegionServerToStop(serverName, -1);
while (counter > MyLoadBalancer.counter.get()) {
Thread.sleep(1000);
}
cluster.startRegionServer();
startAServer = false;
// Wait till the dead server is processed by SSH
TEST_UTIL.waitFor(120000, 1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return serverManager.isServerDead(serverName) && !serverManager.areDeadServersInProgress();
}
});
TEST_UTIL.waitUntilNoRegionsInTransition(300000);
rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
assertTrue("First region should be re-assigned to a different server", rs != null && !serverName.equals(rs.getServerName()));
} finally {
MyLoadBalancer.countRegionServers = null;
TEST_UTIL.deleteTable(tableName);
if (startAServer) {
cluster.startRegionServer();
}
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestAssignmentManagerOnCluster method testAssignRacingWithSSH.
/**
* Test force unassign/assign a region hosted on a dead server
*/
@Test(timeout = 60000)
public void testAssignRacingWithSSH() 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);
// Hold SSH before killing the hosting server
master.enableSSH(false);
RegionStates regionStates = am.getRegionStates();
ServerName metaServer = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO);
while (true) {
assertTrue(am.waitForAssignment(hri));
RegionState state = regionStates.getRegionState(hri);
ServerName oldServerName = state.getServerName();
if (!ServerName.isSameHostnameAndPort(oldServerName, metaServer)) {
// Kill the hosting server, which doesn't have meta on it.
cluster.killRegionServer(oldServerName);
cluster.waitForRegionServerToStop(oldServerName, -1);
break;
}
int i = cluster.getServerWithMeta();
HRegionServer rs = cluster.getRegionServer(i == 0 ? 1 : 0);
oldServerName = rs.getServerName();
master.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(oldServerName.getServerName()));
}
// You can't assign a dead region before SSH
am.assign(hri, true);
RegionState state = regionStates.getRegionState(hri);
assertTrue(state.isFailedClose());
// You can't unassign a dead region before SSH either
am.unassign(hri);
state = regionStates.getRegionState(hri);
assertTrue(state.isFailedClose());
// Enable SSH so that log can be split
master.enableSSH(true);
// 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, 6000);
} finally {
if (master != null) {
master.enableSSH(true);
}
TEST_UTIL.deleteTable(tableName);
cluster.startRegionServer();
}
}
use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.
the class TestDistributedLogSplitting method abortRSAndWaitForRecovery.
private void abortRSAndWaitForRecovery(HRegionServer hrs, final ZooKeeperWatcher zkw, final int numRegions) throws Exception {
final MiniHBaseCluster tmpCluster = this.cluster;
// abort RS
LOG.info("Aborting region server: " + hrs.getServerName());
hrs.abort("testing");
// wait for abort completes
TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return (tmpCluster.getLiveRegionServerThreads().size() <= (NUM_RS - 1));
}
});
// wait for regions come online
TEST_UTIL.waitFor(180000, 200, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return (HBaseTestingUtility.getAllOnlineRegions(tmpCluster).size() >= (numRegions + 1));
}
});
// wait for all regions are fully recovered
TEST_UTIL.waitFor(180000, 200, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
List<String> recoveringRegions = zkw.getRecoverableZooKeeper().getChildren(zkw.znodePaths.recoveringRegionsZNode, false);
return (recoveringRegions != null && recoveringRegions.isEmpty());
}
});
}
Aggregations