use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestOpenRegionProcedureHang method test.
@Test
public void test() throws InterruptedException, KeeperException, IOException {
RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
HRegionServer rs1 = UTIL.getRSForFirstRegionInTable(NAME);
HRegionServer rs2 = UTIL.getOtherRegionServer(rs1);
ARRIVE = new CountDownLatch(1);
RESUME = new CountDownLatch(1);
FINISH = new CountDownLatch(1);
ABORT = new CountDownLatch(1);
am.moveAsync(new RegionPlan(region, rs1.getServerName(), rs2.getServerName()));
ARRIVE.await();
ARRIVE = null;
HMaster master = UTIL.getMiniHBaseCluster().getMaster();
master.getZooKeeper().close();
UTIL.waitFor(30000, () -> {
for (MasterThread mt : UTIL.getMiniHBaseCluster().getMasterThreads()) {
if (mt.getMaster() != master && mt.getMaster().isActiveMaster()) {
return mt.getMaster().isInitialized();
}
}
return false;
});
ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
UTIL.waitFor(30000, () -> procExec.getProcedures().stream().filter(p -> p instanceof OpenRegionProcedure).map(p -> (OpenRegionProcedure) p).anyMatch(p -> p.region.getTable().equals(NAME)));
OpenRegionProcedure proc = procExec.getProcedures().stream().filter(p -> p instanceof OpenRegionProcedure).map(p -> (OpenRegionProcedure) p).filter(p -> p.region.getTable().equals(NAME)).findFirst().get();
// wait a bit to let the OpenRegionProcedure send out the request
Thread.sleep(2000);
RESUME.countDown();
if (!FINISH.await(15, TimeUnit.SECONDS)) {
LOG.info("Wait reportRegionStateTransition to finish timed out, this is possible if" + " we update the procedure store, as the WALProcedureStore" + " will retry forever to roll the writer if it is not closed");
}
FINISH = null;
// if the reportRegionTransition is finished, wait a bit to let it return the data to RS
Thread.sleep(2000);
ABORT.countDown();
UTIL.waitFor(30000, () -> procExec.isFinished(proc.getProcId()));
UTIL.waitFor(30000, () -> procExec.isFinished(proc.getParentProcId()));
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestReplicationSource method testServerShutdownRecoveredQueue.
/**
* Tests that recovered queues are preserved on a regionserver shutdown.
* See HBASE-18192
*/
@Test
public void testServerShutdownRecoveredQueue() throws Exception {
try {
// Ensure single-threaded WAL
conf.set("hbase.wal.provider", "defaultProvider");
conf.setInt("replication.sleep.before.failover", 2000);
// Introduces a delay in regionserver shutdown to give the race condition a chance to kick in.
conf.set(HConstants.REGION_SERVER_IMPL, ShutdownDelayRegionServer.class.getName());
SingleProcessHBaseCluster cluster = TEST_UTIL.startMiniCluster(2);
TEST_UTIL_PEER.startMiniCluster(1);
HRegionServer serverA = cluster.getRegionServer(0);
final ReplicationSourceManager managerA = serverA.getReplicationSourceService().getReplicationManager();
HRegionServer serverB = cluster.getRegionServer(1);
final ReplicationSourceManager managerB = serverB.getReplicationSourceService().getReplicationManager();
final Admin admin = TEST_UTIL.getAdmin();
final String peerId = "TestPeer";
admin.addReplicationPeer(peerId, ReplicationPeerConfig.newBuilder().setClusterKey(TEST_UTIL_PEER.getClusterKey()).build());
// Wait for replication sources to come up
Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() {
return !(managerA.getSources().isEmpty() || managerB.getSources().isEmpty());
}
});
// Disabling peer makes sure there is at least one log to claim when the server dies
// The recovered queue will also stay there until the peer is disabled even if the
// WALs it contains have no data.
admin.disableReplicationPeer(peerId);
// Stopping serverA
// It's queues should be claimed by the only other alive server i.e. serverB
cluster.stopRegionServer(serverA.getServerName());
Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return managerB.getOldSources().size() == 1;
}
});
final HRegionServer serverC = cluster.startRegionServer().getRegionServer();
serverC.waitForServerOnline();
Waiter.waitFor(conf, 20000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return serverC.getReplicationSourceService() != null;
}
});
final ReplicationSourceManager managerC = ((Replication) serverC.getReplicationSourceService()).getReplicationManager();
// Sanity check
assertEquals(0, managerC.getOldSources().size());
// Stopping serverB
// Now serverC should have two recovered queues:
// 1. The serverB's normal queue
// 2. serverA's recovered queue on serverB
cluster.stopRegionServer(serverB.getServerName());
Waiter.waitFor(conf, 20000, (Waiter.Predicate<Exception>) () -> managerC.getOldSources().size() == 2);
admin.enableReplicationPeer(peerId);
Waiter.waitFor(conf, 20000, (Waiter.Predicate<Exception>) () -> managerC.getOldSources().size() == 0);
} finally {
conf.set(HConstants.REGION_SERVER_IMPL, HRegionServer.class.getName());
}
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestMetaRegionReplicaReplication method getAllRegions.
/**
* @return All Regions for tableName including Replicas.
*/
private Region[] getAllRegions(TableName tableName, int replication) {
final Region[] regions = new Region[replication];
for (int i = 0; i < NB_SERVERS; i++) {
HRegionServer rs = HTU.getMiniHBaseCluster().getRegionServer(i);
List<HRegion> onlineRegions = rs.getRegions(tableName);
for (HRegion region : onlineRegions) {
regions[region.getRegionInfo().getReplicaId()] = region;
}
}
for (Region region : regions) {
assertNotNull(region);
}
return regions;
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRefreshPeerWhileRegionServerRestarts method testRestart.
@Test
public void testRestart() throws Exception {
UTIL1.getMiniHBaseCluster().getConfiguration().setClass(HConstants.REGION_SERVER_IMPL, RegionServerForTest.class, HRegionServer.class);
CountDownLatch arrive = new CountDownLatch(1);
ARRIVE = arrive;
RESUME = new CountDownLatch(1);
// restart a new region server, and wait until it finish initialization and want to call
// regionServerReport, so it will load the peer state to peer cache.
Future<HRegionServer> regionServerFuture = ForkJoinPool.commonPool().submit(() -> UTIL1.getMiniHBaseCluster().startRegionServer().getRegionServer());
ARRIVE.await();
// change the peer state, wait until it reach the last state, where we have already get the
// region server list for refreshing
Future<Void> future = hbaseAdmin.disableReplicationPeerAsync(PEER_ID2);
try {
UTIL1.waitFor(30000, () -> {
for (Procedure<?> proc : UTIL1.getMiniHBaseCluster().getMaster().getProcedures()) {
if (proc instanceof DisablePeerProcedure) {
return ((DisablePeerProcedure) proc).getCurrentStateId() == MasterProcedureProtos.PeerModificationState.POST_PEER_MODIFICATION_VALUE;
}
}
return false;
});
} finally {
// let the new region server go
RESUME.countDown();
}
// wait the disable peer operation to finish
future.get();
// assert that the peer cache on the new region server has also been refreshed
ReplicationPeer peer = regionServerFuture.get().getReplicationSourceService().getReplicationPeers().getPeer(PEER_ID2);
assertEquals(PeerState.DISABLED, peer.getPeerState());
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestRegionReplicaReplication method verifyReplication.
private void verifyReplication(TableName tableName, int regionReplication, final int startRow, final int endRow, final boolean present) throws Exception {
// find the regions
final Region[] regions = new Region[regionReplication];
for (int i = 0; i < NB_SERVERS; i++) {
HRegionServer rs = HTU.getMiniHBaseCluster().getRegionServer(i);
List<HRegion> onlineRegions = rs.getRegions(tableName);
for (HRegion region : onlineRegions) {
regions[region.getRegionInfo().getReplicaId()] = region;
}
}
for (Region region : regions) {
assertNotNull(region);
}
for (int i = 1; i < regionReplication; i++) {
final Region region = regions[i];
// wait until all the data is replicated to all secondary regions
Waiter.waitFor(HTU.getConfiguration(), 90000, 1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
LOG.info("verifying replication for region replica:" + region.getRegionInfo());
try {
HTU.verifyNumericRows(region, HBaseTestingUtil.fam1, startRow, endRow, present);
} catch (Throwable ex) {
LOG.warn("Verification from secondary region is not complete yet", ex);
// still wait
return false;
}
return true;
}
});
}
}
Aggregations