use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestMasterObserver method testRegionTransitionOperations.
@Test
public void testRegionTransitionOperations() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
SingleProcessHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
cp.resetStates();
Table table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY);
try (RegionLocator r = UTIL.getConnection().getRegionLocator(tableName)) {
UTIL.waitUntilAllRegionsAssigned(tableName);
List<HRegionLocation> regions = r.getAllRegionLocations();
HRegionLocation firstGoodPair = null;
for (HRegionLocation e : regions) {
if (e.getServerName() != null) {
firstGoodPair = e;
break;
}
}
assertNotNull("Found a non-null entry", firstGoodPair);
LOG.info("Found " + firstGoodPair.toString());
// Try to force a move
Collection<ServerName> servers = master.getClusterMetrics().getLiveServerMetrics().keySet();
String destName = null;
String serverNameForFirstRegion = firstGoodPair.getServerName().toString();
LOG.info("serverNameForFirstRegion=" + serverNameForFirstRegion);
ServerName masterServerName = master.getServerName();
boolean found = false;
// Find server that is NOT carrying the first region
for (ServerName info : servers) {
LOG.info("ServerName=" + info);
if (!serverNameForFirstRegion.equals(info.getServerName()) && !masterServerName.equals(info)) {
destName = info.toString();
found = true;
break;
}
}
assertTrue("Found server", found);
LOG.info("Found " + destName);
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(firstGoodPair.getRegion().getEncodedNameAsBytes(), ServerName.valueOf(destName)));
assertTrue("Coprocessor should have been called on region move", cp.wasMoveCalled());
// make sure balancer is on
master.balanceSwitch(true);
assertTrue("Coprocessor should have been called on balance switch", cp.wasBalanceSwitchCalled());
// turn balancer off
master.balanceSwitch(false);
// wait for assignments to finish, if any
UTIL.waitUntilNoRegionsInTransition();
// move half the open regions from RS 0 to RS 1
HRegionServer rs = cluster.getRegionServer(0);
byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
// Make sure no regions are in transition now
UTIL.waitUntilNoRegionsInTransition();
List<RegionInfo> openRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
int moveCnt = openRegions.size() / 2;
for (int i = 0; i < moveCnt; i++) {
RegionInfo info = openRegions.get(i);
if (!info.isMetaRegion()) {
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(openRegions.get(i).getEncodedNameAsBytes(), ServerName.valueOf(Bytes.toString(destRS))));
}
}
// Make sure no regions are in transition now
UTIL.waitUntilNoRegionsInTransition();
// now trigger a balance
master.balanceSwitch(true);
master.balance();
assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
} finally {
Admin admin = UTIL.getAdmin();
admin.disableTable(tableName);
deleteTable(admin, tableName);
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionServerCoprocessorExceptionWithAbort method testExceptionDuringInitialization.
@Test
public void testExceptionDuringInitialization() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
// Let's fail fast.
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, true);
conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, "");
TEST_UTIL.startMiniCluster(2);
try {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
// Trigger one regionserver to fail as if it came up with a coprocessor
// that fails during initialization
final HRegionServer regionServer = cluster.getRegionServer(0);
conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, FailedInitializationObserver.class.getName());
regionServer.getRegionServerCoprocessorHost().loadSystemCoprocessors(conf, CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
TEST_UTIL.waitFor(10000, 1000, new Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return regionServer.isAborted();
}
});
} finally {
TEST_UTIL.shutdownMiniCluster();
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionServerCoprocessorExceptionWithAbort method testExceptionFromCoprocessorDuringPut.
@Test
public void testExceptionFromCoprocessorDuringPut() throws Exception {
// set configure to indicate which cp should be loaded
Configuration conf = TEST_UTIL.getConfiguration();
// Let's fail fast.
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, BuggyRegionObserver.class.getName());
conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, true);
TEST_UTIL.startMiniCluster(2);
try {
// When we try to write to TEST_TABLE, the buggy coprocessor will
// cause a NullPointerException, which will cause the regionserver (which
// hosts the region we attempted to write to) to abort.
final byte[] TEST_FAMILY = Bytes.toBytes("aaa");
Table table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, TEST_FAMILY);
TEST_UTIL.waitUntilAllRegionsAssigned(TABLE_NAME);
// Note which regionServer will abort (after put is attempted).
final HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
try {
final byte[] ROW = Bytes.toBytes("aaa");
Put put = new Put(ROW);
put.addColumn(TEST_FAMILY, ROW, ROW);
table.put(put);
} catch (IOException e) {
// The region server is going to be aborted.
// We may get an exception if we retry,
// which is not guaranteed.
}
// Wait 10 seconds for the regionserver to abort: expected result is that
// it will abort.
boolean aborted = false;
for (int i = 0; i < 10; i++) {
aborted = regionServer.isAborted();
if (aborted) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
fail("InterruptedException while waiting for regionserver " + "zk node to be deleted.");
}
}
Assert.assertTrue("The region server should have aborted", aborted);
table.close();
} finally {
TEST_UTIL.shutdownMiniCluster();
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionServerCoprocessorExceptionWithRemove method testExceptionFromCoprocessorDuringPut.
@Test
public void testExceptionFromCoprocessorDuringPut() throws IOException, InterruptedException {
// Set watches on the zookeeper nodes for all of the regionservers in the
// cluster. When we try to write to TEST_TABLE, the buggy coprocessor will
// cause a NullPointerException, which will cause the regionserver (which
// hosts the region we attempted to write to) to abort. In turn, this will
// cause the nodeDeleted() method of the DeadRegionServer tracker to
// execute, which will set the rsZKNodeDeleted flag to true, which will
// pass this test.
TableName TEST_TABLE = TableName.valueOf("observed_table");
byte[] TEST_FAMILY = Bytes.toBytes("aaa");
Table table = TEST_UTIL.createMultiRegionTable(TEST_TABLE, TEST_FAMILY);
TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
// Note which regionServer that should survive the buggy coprocessor's
// prePut().
HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(TEST_TABLE);
boolean threwIOE = false;
try {
final byte[] ROW = Bytes.toBytes("aaa");
Put put = new Put(ROW);
put.addColumn(TEST_FAMILY, ROW, ROW);
table.put(put);
// We may need two puts to reliably get an exception
table.put(put);
} catch (IOException e) {
threwIOE = true;
} finally {
assertTrue("The regionserver should have thrown an exception", threwIOE);
}
// it will survive and not abort.
for (int i = 0; i < 10; i++) {
assertFalse(regionServer.isAborted());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
fail("InterruptedException while waiting for regionserver " + "zk node to be deleted.");
}
}
table.close();
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestProcedurePriority method test.
@Test
public void test() throws Exception {
RegionServerThread rsWithMetaThread = UTIL.getMiniHBaseCluster().getRegionServerThreads().stream().filter(t -> !t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()).findAny().get();
HRegionServer rsNoMeta = UTIL.getOtherRegionServer(rsWithMetaThread.getRegionServer());
FAIL = true;
UTIL.getMiniHBaseCluster().killRegionServer(rsNoMeta.getServerName());
// wait until all the worker thread are stuck, which means that the stuck checker will start to
// add new worker thread.
ProcedureExecutor<?> executor = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
UTIL.waitFor(60000, new ExplainingPredicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return executor.getWorkerThreadCount() > CORE_POOL_SIZE;
}
@Override
public String explainFailure() throws Exception {
return "Stuck checker does not add new worker thread";
}
});
UTIL.getMiniHBaseCluster().killRegionServer(rsWithMetaThread.getRegionServer().getServerName());
rsWithMetaThread.join();
FAIL = false;
// verify that the cluster is back
UTIL.waitUntilNoRegionsInTransition(480000);
for (int i = 0; i < TABLE_COUNT; i++) {
try (Table table = UTIL.getConnection().getTable(TableName.valueOf(TABLE_NAME_PREFIX + i))) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
UTIL.waitFor(60000, new ExplainingPredicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return executor.getWorkerThreadCount() == CORE_POOL_SIZE;
}
@Override
public String explainFailure() throws Exception {
return "The new workers do not timeout";
}
});
}
Aggregations