Search in sources :

Example 11 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestDistributedLogSplitting method testDisallowWritesInRecovering.

@Ignore("DLR is broken by HBASE-12751")
@Test(timeout = 300000)
public void testDisallowWritesInRecovering() throws Exception {
    LOG.info("testDisallowWritesInRecovering");
    conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, true);
    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3);
    conf.setBoolean(HConstants.DISALLOW_WRITES_IN_RECOVERING, true);
    startCluster(NUM_RS);
    final int NUM_REGIONS_TO_CREATE = 40;
    // turn off load balancing to prevent regions from moving around otherwise
    // they will consume recovered.edits
    master.balanceSwitch(false);
    List<RegionServerThread> rsts = cluster.getLiveRegionServerThreads();
    final ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "table-creation", null);
    Table ht = installTable(zkw, "table", "family", NUM_REGIONS_TO_CREATE);
    try {
        final SplitLogManager slm = master.getMasterWalManager().getSplitLogManager();
        Set<HRegionInfo> regionSet = new HashSet<>();
        HRegionInfo region = null;
        HRegionServer hrs = null;
        HRegionServer dstRS = null;
        for (int i = 0; i < NUM_RS; i++) {
            hrs = rsts.get(i).getRegionServer();
            List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(hrs.getRSRpcServices());
            if (regions.isEmpty())
                continue;
            region = regions.get(0);
            regionSet.add(region);
            dstRS = rsts.get((i + 1) % NUM_RS).getRegionServer();
            break;
        }
        slm.markRegionsRecovering(hrs.getServerName(), regionSet);
        // move region in order for the region opened in recovering state
        final HRegionInfo hri = region;
        final HRegionServer tmpRS = dstRS;
        TEST_UTIL.getAdmin().move(region.getEncodedNameAsBytes(), Bytes.toBytes(dstRS.getServerName().getServerName()));
        // wait for region move completes
        final RegionStates regionStates = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
        TEST_UTIL.waitFor(45000, 200, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                ServerName sn = regionStates.getRegionServerOfRegion(hri);
                return (sn != null && sn.equals(tmpRS.getServerName()));
            }
        });
        try {
            byte[] key = region.getStartKey();
            if (key == null || key.length == 0) {
                key = new byte[] { 0, 0, 0, 0, 1 };
            }
            Put put = new Put(key);
            put.addColumn(Bytes.toBytes("family"), Bytes.toBytes("c1"), new byte[] { 'b' });
            ht.put(put);
        } catch (IOException ioe) {
            Assert.assertTrue(ioe instanceof RetriesExhaustedWithDetailsException);
            RetriesExhaustedWithDetailsException re = (RetriesExhaustedWithDetailsException) ioe;
            boolean foundRegionInRecoveryException = false;
            for (Throwable t : re.getCauses()) {
                if (t instanceof RegionInRecoveryException) {
                    foundRegionInRecoveryException = true;
                    break;
                }
            }
            Assert.assertTrue("No RegionInRecoveryException. Following exceptions returned=" + re.getCauses(), foundRegionInRecoveryException);
        }
    } finally {
        if (ht != null)
            ht.close();
        if (ht != null)
            zkw.close();
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) RegionInRecoveryException(org.apache.hadoop.hbase.exceptions.RegionInRecoveryException) IOException(java.io.IOException) OperationConflictException(org.apache.hadoop.hbase.exceptions.OperationConflictException) RegionInRecoveryException(org.apache.hadoop.hbase.exceptions.RegionInRecoveryException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Waiter(org.apache.hadoop.hbase.Waiter) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestDistributedLogSplitting method testLogReplayWithNonMetaRSDown.

@Ignore("DLR is broken by HBASE-12751")
@Test(timeout = 300000)
public void testLogReplayWithNonMetaRSDown() throws Exception {
    LOG.info("testLogReplayWithNonMetaRSDown");
    // create more than one wal
    conf.setLong("hbase.regionserver.hlog.blocksize", 30 * 1024);
    conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, true);
    startCluster(NUM_RS);
    final int NUM_REGIONS_TO_CREATE = 40;
    final int NUM_LOG_LINES = 1000;
    // turn off load balancing to prevent regions from moving around otherwise
    // they will consume recovered.edits
    master.balanceSwitch(false);
    final ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "table-creation", null);
    Table ht = installTable(zkw, "table", "family", NUM_REGIONS_TO_CREATE);
    try {
        HRegionServer hrs = findRSToKill(false, "table");
        List<HRegionInfo> regions = ProtobufUtil.getOnlineRegions(hrs.getRSRpcServices());
        makeWAL(hrs, regions, "table", "family", NUM_LOG_LINES, 100);
        // wait for abort completes
        this.abortRSAndVerifyRecovery(hrs, ht, zkw, NUM_REGIONS_TO_CREATE, NUM_LOG_LINES);
    } finally {
        if (ht != null)
            ht.close();
        if (zkw != null)
            zkw.close();
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Table(org.apache.hadoop.hbase.client.Table) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestRSStatusServlet method setupBasicMocks.

@Before
public void setupBasicMocks() throws IOException, ServiceException {
    rs = Mockito.mock(HRegionServer.class);
    rpcServices = Mockito.mock(RSRpcServices.class);
    rpcServer = Mockito.mock(RpcServerInterface.class);
    Mockito.doReturn(HBaseConfiguration.create()).when(rs).getConfiguration();
    Mockito.doReturn(rpcServices).when(rs).getRSRpcServices();
    Mockito.doReturn(rpcServer).when(rs).getRpcServer();
    Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo((RpcController) Mockito.any(), (GetServerInfoRequest) Mockito.any());
    // Fake ZKW
    ZooKeeperWatcher zkw = Mockito.mock(ZooKeeperWatcher.class);
    Mockito.doReturn("fakequorum").when(zkw).getQuorum();
    Mockito.doReturn(zkw).when(rs).getZooKeeper();
    // Fake CacheConfig
    LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0");
    CacheConfig cacheConf = Mockito.mock(CacheConfig.class);
    Mockito.doReturn(null).when(cacheConf).getBlockCache();
    Mockito.doReturn(cacheConf).when(rs).getCacheConfig();
    // Fake MasterAddressTracker
    MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class);
    Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress();
    Mockito.doReturn(mat).when(rs).getMasterAddressTracker();
    MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
    Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
    Mockito.doReturn(rms).when(rs).getRegionServerMetrics();
    MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
    Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
    Mockito.doReturn(ms).when(rpcServer).getMetrics();
}
Also used : MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig) MetricsHBaseServer(org.apache.hadoop.hbase.ipc.MetricsHBaseServer) MetricsHBaseServerWrapperStub(org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperStub) Before(org.junit.Before)

Example 14 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestRegionServerNoMaster method stopMasterAndAssignMeta.

public static void stopMasterAndAssignMeta(HBaseTestingUtility HTU) throws IOException, InterruptedException {
    // Stop master
    HMaster master = HTU.getHBaseCluster().getMaster();
    Thread masterThread = HTU.getHBaseCluster().getMasterThread();
    ServerName masterAddr = master.getServerName();
    master.stopMaster();
    LOG.info("Waiting until master thread exits");
    while (masterThread != null && masterThread.isAlive()) {
        Threads.sleep(100);
    }
    HRegionServer.TEST_SKIP_REPORTING_TRANSITION = true;
    // Master is down, so is the meta. We need to assign it somewhere
    // so that regions can be assigned during the mocking phase.
    HRegionServer hrs = HTU.getHBaseCluster().getLiveRegionServerThreads().get(0).getRegionServer();
    ZooKeeperWatcher zkw = hrs.getZooKeeper();
    MetaTableLocator mtl = new MetaTableLocator();
    ServerName sn = mtl.getMetaRegionLocation(zkw);
    if (sn != null && !masterAddr.equals(sn)) {
        return;
    }
    ProtobufUtil.openRegion(null, hrs.getRSRpcServices(), hrs.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
    while (true) {
        sn = mtl.getMetaRegionLocation(zkw);
        if (sn != null && sn.equals(hrs.getServerName()) && hrs.onlineRegions.containsKey(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName())) {
            break;
        }
        Thread.sleep(100);
    }
}
Also used : MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)

Example 15 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestGlobalThrottler method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    conf1 = HBaseConfiguration.create();
    conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
    conf1.setLong("replication.source.sleepforretries", 100);
    // Each WAL is about 120 bytes
    conf1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, 200);
    conf1.setLong("replication.source.per.peer.node.bandwidth", 100L);
    utility1 = new HBaseTestingUtility(conf1);
    utility1.startMiniZKCluster();
    MiniZooKeeperCluster miniZK = utility1.getZkCluster();
    new ZooKeeperWatcher(conf1, "cluster1", null, true);
    conf2 = new Configuration(conf1);
    conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
    utility2 = new HBaseTestingUtility(conf2);
    utility2.setZkCluster(miniZK);
    new ZooKeeperWatcher(conf2, "cluster2", null, true);
    ReplicationAdmin admin1 = new ReplicationAdmin(conf1);
    ReplicationPeerConfig rpc = new ReplicationPeerConfig();
    rpc.setClusterKey(utility2.getClusterKey());
    utility1.startMiniCluster(1, 1);
    utility2.startMiniCluster(1, 1);
    admin1.addPeer("peer1", rpc, null);
    admin1.addPeer("peer2", rpc, null);
    admin1.addPeer("peer3", rpc, null);
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ReplicationAdmin(org.apache.hadoop.hbase.client.replication.ReplicationAdmin) MiniZooKeeperCluster(org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster) BeforeClass(org.junit.BeforeClass)

Aggregations

ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)60 Test (org.junit.Test)33 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)20 Table (org.apache.hadoop.hbase.client.Table)19 Configuration (org.apache.hadoop.conf.Configuration)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Ignore (org.junit.Ignore)15 IOException (java.io.IOException)13 ServerName (org.apache.hadoop.hbase.ServerName)12 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)12 TimeoutException (java.util.concurrent.TimeoutException)9 Waiter (org.apache.hadoop.hbase.Waiter)9 OperationConflictException (org.apache.hadoop.hbase.exceptions.OperationConflictException)9 ArrayList (java.util.ArrayList)8 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)8 RegionInRecoveryException (org.apache.hadoop.hbase.exceptions.RegionInRecoveryException)8 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)8 MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)7 HashSet (java.util.HashSet)6 TableName (org.apache.hadoop.hbase.TableName)6