Search in sources :

Example 46 with HRegionServer

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()));
}
Also used : BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) ReportRegionStateTransitionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse) TransitionCode(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode) RegionStateTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition) HConstants(org.apache.hadoop.hbase.HConstants) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) Configuration(org.apache.hadoop.conf.Configuration) MasterServices(org.apache.hadoop.hbase.master.MasterServices) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) KeeperException(org.apache.zookeeper.KeeperException) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) ReportRegionStateTransitionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) CountDownLatch(java.util.concurrent.CountDownLatch) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) CountDownLatch(java.util.concurrent.CountDownLatch) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 47 with HRegionServer

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());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Admin(org.apache.hadoop.hbase.client.Admin) Waiter(org.apache.hadoop.hbase.Waiter) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 48 with HRegionServer

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;
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 49 with HRegionServer

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());
}
Also used : DisablePeerProcedure(org.apache.hadoop.hbase.master.replication.DisablePeerProcedure) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 50 with HRegionServer

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;
            }
        });
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) Waiter(org.apache.hadoop.hbase.Waiter) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Aggregations

HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)253 Test (org.junit.Test)188 TableName (org.apache.hadoop.hbase.TableName)70 Table (org.apache.hadoop.hbase.client.Table)67 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)59 IOException (java.io.IOException)53 Region (org.apache.hadoop.hbase.regionserver.Region)49 Configuration (org.apache.hadoop.conf.Configuration)47 ServerName (org.apache.hadoop.hbase.ServerName)46 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)41 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)41 Put (org.apache.hadoop.hbase.client.Put)39 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)32 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)32 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)23 List (java.util.List)22 HMaster (org.apache.hadoop.hbase.master.HMaster)22 ArrayList (java.util.ArrayList)21 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)21 Waiter (org.apache.hadoop.hbase.Waiter)21