Search in sources :

Example 11 with ZKWatcher

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

the class TestReplicationSourceManager method setupZkAndReplication.

protected static void setupZkAndReplication() throws Exception {
    // The implementing class should set up the conf
    assertNotNull(conf);
    zkw = new ZKWatcher(conf, "test", null);
    ZKUtil.createWithParents(zkw, "/hbase/replication");
    ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1");
    ZKUtil.setData(zkw, "/hbase/replication/peers/1", Bytes.toBytes(conf.get(HConstants.ZOOKEEPER_QUORUM) + ":" + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT) + ":/1"));
    ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/peer-state");
    ZKUtil.setData(zkw, "/hbase/replication/peers/1/peer-state", ZKReplicationPeerStorage.ENABLED_ZNODE_BYTES);
    ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/sync-rep-state");
    ZKUtil.setData(zkw, "/hbase/replication/peers/1/sync-rep-state", ZKReplicationPeerStorage.NONE_STATE_ZNODE_BYTES);
    ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/new-sync-rep-state");
    ZKUtil.setData(zkw, "/hbase/replication/peers/1/new-sync-rep-state", ZKReplicationPeerStorage.NONE_STATE_ZNODE_BYTES);
    ZKUtil.createWithParents(zkw, "/hbase/replication/state");
    ZKUtil.setData(zkw, "/hbase/replication/state", ZKReplicationPeerStorage.ENABLED_ZNODE_BYTES);
    ZKClusterId.setClusterId(zkw, new ClusterId());
    CommonFSUtils.setRootDir(utility.getConfiguration(), utility.getDataTestDir());
    fs = FileSystem.get(conf);
    oldLogDir = utility.getDataTestDir(HConstants.HREGION_OLDLOGDIR_NAME);
    logDir = utility.getDataTestDir(HConstants.HREGION_LOGDIR_NAME);
    remoteLogDir = utility.getDataTestDir(ReplicationUtils.REMOTE_WAL_DIR_NAME);
    replication = new Replication();
    replication.initialize(new DummyServer(), fs, logDir, oldLogDir, new WALFactory(conf, "test", null, false));
    managerOfCluster = getManagerFromCluster();
    if (managerOfCluster != null) {
        // After replication procedure, we need to add peer by hand (other than by receiving
        // notification from zk)
        managerOfCluster.addPeer(slaveId);
    }
    manager = replication.getReplicationManager();
    manager.addSource(slaveId);
    if (managerOfCluster != null) {
        waitPeer(slaveId, managerOfCluster, true);
    }
    waitPeer(slaveId, manager, true);
    htd = TableDescriptorBuilder.newBuilder(test).setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(f1).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(f2)).build();
    scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    for (byte[] fam : htd.getColumnFamilyNames()) {
        scopes.put(fam, 0);
    }
    hri = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(r1).setEndKey(r2).build();
}
Also used : ClusterId(org.apache.hadoop.hbase.ClusterId) ZKClusterId(org.apache.hadoop.hbase.zookeeper.ZKClusterId) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) WALFactory(org.apache.hadoop.hbase.wal.WALFactory)

Example 12 with ZKWatcher

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

the class TestDumpReplicationQueues method testDumpReplicationReturnsWalSorted.

/**
 * Makes sure dumpQueues returns wals znodes ordered chronologically.
 * @throws Exception if dumpqueues finds any error while handling list of znodes.
 */
@Test
public void testDumpReplicationReturnsWalSorted() throws Exception {
    Configuration config = HBaseConfiguration.create();
    ZKWatcher zkWatcherMock = mock(ZKWatcher.class);
    ZNodePaths zNodePath = new ZNodePaths(config);
    RecoverableZooKeeper recoverableZooKeeperMock = mock(RecoverableZooKeeper.class);
    when(zkWatcherMock.getRecoverableZooKeeper()).thenReturn(recoverableZooKeeperMock);
    when(zkWatcherMock.getZNodePaths()).thenReturn(zNodePath);
    List<String> nodes = new ArrayList<>();
    String server = "rs1,60030," + EnvironmentEdgeManager.currentTime();
    nodes.add(server);
    when(recoverableZooKeeperMock.getChildren("/hbase/rs", null)).thenReturn(nodes);
    when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs", null)).thenReturn(nodes);
    List<String> queuesIds = new ArrayList<>();
    queuesIds.add("1");
    when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs/" + server, null)).thenReturn(queuesIds);
    List<String> wals = new ArrayList<>();
    wals.add("rs1%2C60964%2C1549394085556.1549394101427");
    wals.add("rs1%2C60964%2C1549394085556.1549394101426");
    wals.add("rs1%2C60964%2C1549394085556.1549394101428");
    when(recoverableZooKeeperMock.getChildren("/hbase/replication/rs/" + server + "/1", null)).thenReturn(wals);
    DumpReplicationQueues dumpQueues = new DumpReplicationQueues();
    Set<String> peerIds = new HashSet<>();
    peerIds.add("1");
    dumpQueues.setConf(config);
    String dump = dumpQueues.dumpQueues(zkWatcherMock, peerIds, false);
    String[] parsedDump = dump.split("Replication position for");
    assertEquals("Parsed dump should have 4 parts.", 4, parsedDump.length);
    assertTrue("First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1], parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0);
    assertTrue("Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2], parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0);
    assertTrue("Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3], parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0);
}
Also used : RecoverableZooKeeper(org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ArrayList(java.util.ArrayList) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ZKWatcher

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

the class TestZKProcedureControllers method testSimpleZKCohortMemberController.

/**
 * Smaller test to just test the actuation on the cohort member
 * @throws Exception on failure
 */
@Test
public void testSimpleZKCohortMemberController() throws Exception {
    ZKWatcher watcher = UTIL.getZooKeeperWatcher();
    final String operationName = "instanceTest";
    final Subprocedure sub = Mockito.mock(Subprocedure.class);
    Mockito.when(sub.getName()).thenReturn(operationName);
    final byte[] data = new byte[] { 1, 2, 3 };
    final CountDownLatch prepared = new CountDownLatch(1);
    final CountDownLatch committed = new CountDownLatch(1);
    final ForeignExceptionDispatcher monitor = spy(new ForeignExceptionDispatcher());
    final ZKProcedureMemberRpcs controller = new ZKProcedureMemberRpcs(watcher, "testSimple");
    // mock out cohort member callbacks
    final ProcedureMember member = Mockito.mock(ProcedureMember.class);
    Mockito.doReturn(sub).when(member).createSubprocedure(operationName, data);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            controller.sendMemberAcquired(sub);
            prepared.countDown();
            return null;
        }
    }).when(member).submitSubprocedure(sub);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            controller.sendMemberCompleted(sub, memberData);
            committed.countDown();
            return null;
        }
    }).when(member).receivedReachedGlobalBarrier(operationName);
    // start running the listener
    controller.start(COHORT_NODE_NAME, member);
    // set a prepare node from a 'coordinator'
    String prepare = ZKProcedureUtil.getAcquireBarrierNode(controller.getZkController(), operationName);
    ZKUtil.createSetData(watcher, prepare, ProtobufUtil.prependPBMagic(data));
    // wait for the operation to be prepared
    prepared.await();
    // create the commit node so we update the operation to enter the commit phase
    String commit = ZKProcedureUtil.getReachedBarrierNode(controller.getZkController(), operationName);
    LOG.debug("Found prepared, posting commit node:" + commit);
    ZKUtil.createAndFailSilent(watcher, commit);
    LOG.debug("Commit node:" + commit + ", exists:" + ZKUtil.checkExists(watcher, commit));
    committed.await();
    verify(monitor, never()).receive(Mockito.any());
    // XXX: broken due to composition.
    // verify(member, never()).getManager().controllerConnectionFailure(Mockito.anyString(),
    // Mockito.any());
    // cleanup after the test
    ZKUtil.deleteNodeRecursively(watcher, controller.getZkController().getBaseZnode());
    assertEquals("Didn't delete prepare node", -1, ZKUtil.checkExists(watcher, prepare));
    assertEquals("Didn't delete commit node", -1, ZKUtil.checkExists(watcher, commit));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Test(org.junit.Test)

Example 14 with ZKWatcher

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

the class TestSplitLogWorker method setup.

@Before
public void setup() throws Exception {
    TEST_UTIL.startMiniZKCluster();
    Configuration conf = TEST_UTIL.getConfiguration();
    zkw = new ZKWatcher(TEST_UTIL.getConfiguration(), "split-log-worker-tests", null);
    ds = new DummyServer(zkw, conf);
    ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
    ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
    assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
    LOG.debug(zkw.getZNodePaths().baseZNode + " created");
    ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
    assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));
    LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
    ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
    assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));
    SplitLogCounters.resetCounters();
    executorService = new ExecutorService("TestSplitLogWorker");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.RS_LOG_REPLAY_OPS).setCorePoolSize(10));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ExecutorService(org.apache.hadoop.hbase.executor.ExecutorService) Before(org.junit.Before)

Example 15 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher 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(Mockito.any(), Mockito.any());
    // Fake ZKW
    ZKWatcher zkw = Mockito.mock(ZKWatcher.class);
    Mockito.doReturn("fakequorum").when(zkw).getQuorum();
    Mockito.doReturn(zkw).when(rs).getZooKeeper();
    // Fake BlockCache
    LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0");
    Mockito.doReturn(Optional.empty()).when(rs).getBlockCache();
    // 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).getMetrics();
    MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
    Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
    Mockito.doReturn(ms).when(rpcServer).getMetrics();
    Mockito.doReturn(ByteBuffAllocator.HEAP).when(rpcServer).getByteBuffAllocator();
}
Also used : MetricsRegionServerWrapperStub(org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapperStub) MasterAddressTracker(org.apache.hadoop.hbase.zookeeper.MasterAddressTracker) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) RSRpcServices(org.apache.hadoop.hbase.regionserver.RSRpcServices) MetricsRegionServer(org.apache.hadoop.hbase.regionserver.MetricsRegionServer) MetricsHBaseServer(org.apache.hadoop.hbase.ipc.MetricsHBaseServer) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) MetricsHBaseServerWrapperStub(org.apache.hadoop.hbase.ipc.MetricsHBaseServerWrapperStub) Before(org.junit.Before)

Aggregations

ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)66 Configuration (org.apache.hadoop.conf.Configuration)27 Test (org.junit.Test)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)13 ArrayList (java.util.ArrayList)10 ServerName (org.apache.hadoop.hbase.ServerName)10 IOException (java.io.IOException)8 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)8 Before (org.junit.Before)8 BeforeClass (org.junit.BeforeClass)8 Admin (org.apache.hadoop.hbase.client.Admin)7 Abortable (org.apache.hadoop.hbase.Abortable)6 HMaster (org.apache.hadoop.hbase.master.HMaster)6 MiniZooKeeperCluster (org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster)6 List (java.util.List)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)5 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)5 KeeperException (org.apache.zookeeper.KeeperException)5 CountDownLatch (java.util.concurrent.CountDownLatch)4