Java Code Examples for org.apache.hadoop.hbase.zookeeper.ZKWatcher#close()

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKWatcher#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMasterNoCluster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@After
public void tearDown()
throws KeeperException, ZooKeeperConnectionException, IOException {
  // Make sure zk is clean before we run the next test.
  ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(),
      "@Before", new Abortable() {
    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(why, e);
    }

    @Override
    public boolean isAborted() {
      return false;
    }
  });
  ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode);
  zkw.close();
}
 
Example 2
Source File: SpliceReplicationSinkChore.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initReplicationConfig() throws IOException {
    SpliceLogUtils.info(LOG, "isReplicationSlave = %s", isReplicationSlave);
    if (isReplicationSlave) {
        String clusterKey = new String(ZkUtils.getData(replicationSourcePath));
        byte[] replicationStatusBytes = ZkUtils.getData(replicationPeerPath);
        ReplicationStatus replicationStatus = ReplicationStatus.parseFrom(replicationStatusBytes);
        peerId = Short.toString(replicationStatus.getPeerId());
        String[] s = clusterKey.split(":");
        masterQuorum = s[0] + ":" + s[1];
        rootDir = s[2];
        Configuration masterConf = ReplicationUtils.createConfiguration(masterQuorum);
        replicationSourceWatcher = new ZKWatcher(masterConf, "replicationProgressTrackerChore", null, false);
    }
    else {
        if (replicationSourceWatcher != null) {
            replicationSourceWatcher.close();
            replicationSourceWatcher = null;
            rootDir = null;
            peerId = null;
        }
    }
}
 
Example 3
Source File: TestLogsCleaner.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * When zk is working both files should be returned
 * @throws Exception from ZK watcher
 */
@Test
public void testZooKeeperNormal() throws Exception {
  ReplicationLogCleaner cleaner = new ReplicationLogCleaner();

  // Subtract 1000 from current time so modtime is for sure older
  // than 'now'.
  long modTime = System.currentTimeMillis() - 1000;
  List<FileStatus> dummyFiles = Arrays.asList(
      new FileStatus(100, false, 3, 100, modTime, new Path("log1")),
      new FileStatus(100, false, 3, 100, modTime, new Path("log2"))
  );

  ZKWatcher zkw = new ZKWatcher(conf, "testZooKeeperAbort-normal", null);
  try {
    cleaner.setConf(conf, zkw);
    cleaner.preClean();
    Iterable<FileStatus> filesToDelete = cleaner.getDeletableFiles(dummyFiles);
    Iterator<FileStatus> iter = filesToDelete.iterator();
    assertTrue(iter.hasNext());
    assertEquals(new Path("log1"), iter.next().getPath());
    assertTrue(iter.hasNext());
    assertEquals(new Path("log2"), iter.next().getPath());
    assertFalse(iter.hasNext());
  } finally {
    zkw.close();
  }
}
 
Example 4
Source File: TestReplicationHFileCleaner.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * ReplicationHFileCleaner should be able to ride over ZooKeeper errors without aborting.
 */
@Test
public void testZooKeeperAbort() throws Exception {
  ReplicationHFileCleaner cleaner = new ReplicationHFileCleaner();

  List<FileStatus> dummyFiles =
      Lists.newArrayList(new FileStatus(100, false, 3, 100, System.currentTimeMillis(), new Path(
          "hfile1")), new FileStatus(100, false, 3, 100, System.currentTimeMillis(), new Path(
          "hfile2")));

  FaultyZooKeeperWatcher faultyZK =
      new FaultyZooKeeperWatcher(conf, "testZooKeeperAbort-faulty", null);
  try {
    faultyZK.init();
    cleaner.setConf(conf, faultyZK);
    // should keep all files due to a ConnectionLossException getting the queues znodes
    Iterable<FileStatus> toDelete = cleaner.getDeletableFiles(dummyFiles);
    assertFalse(toDelete.iterator().hasNext());
    assertFalse(cleaner.isStopped());
  } finally {
    faultyZK.close();
  }

  // when zk is working both files should be returned
  cleaner = new ReplicationHFileCleaner();
  ZKWatcher zkw = new ZKWatcher(conf, "testZooKeeperAbort-normal", null);
  try {
    cleaner.setConf(conf, zkw);
    Iterable<FileStatus> filesToDelete = cleaner.getDeletableFiles(dummyFiles);
    Iterator<FileStatus> iter = filesToDelete.iterator();
    assertTrue(iter.hasNext());
    assertEquals(new Path("hfile1"), iter.next().getPath());
    assertTrue(iter.hasNext());
    assertEquals(new Path("hfile2"), iter.next().getPath());
    assertFalse(iter.hasNext());
  } finally {
    zkw.close();
  }
}
 
Example 5
Source File: TestRegionServerHostname.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegionServerHostname() throws Exception {
  Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
  while (netInterfaceList.hasMoreElements()) {
    NetworkInterface ni = netInterfaceList.nextElement();
    Enumeration<InetAddress> addrList = ni.getInetAddresses();
    // iterate through host addresses and use each as hostname
    while (addrList.hasMoreElements()) {
      InetAddress addr = addrList.nextElement();
      if (addr.isLoopbackAddress() || addr.isLinkLocalAddress() || addr.isMulticastAddress() ||
          !addr.isSiteLocalAddress()) {
        continue;
      }
      String hostName = addr.getHostName();
      LOG.info("Found " + hostName + " on " + ni + ", addr=" + addr);

      TEST_UTIL.getConfiguration().set(DNS.MASTER_HOSTNAME_KEY, hostName);
      TEST_UTIL.getConfiguration().set(DNS.RS_HOSTNAME_KEY, hostName);
      StartMiniClusterOption option = StartMiniClusterOption.builder()
          .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
      TEST_UTIL.startMiniCluster(option);
      try {
        ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
        List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
        // there would be NUM_RS+1 children - one for the master
        assertTrue(servers.size() ==
          NUM_RS + (LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration())? 1: 0));
        for (String server : servers) {
          assertTrue("From zookeeper: " + server + " hostname: " + hostName,
            server.startsWith(hostName.toLowerCase(Locale.ROOT)+","));
        }
        zkw.close();
      } finally {
        TEST_UTIL.shutdownMiniCluster();
      }
    }
  }
}
 
Example 6
Source File: DumpReplicationQueues.java    From hbase with Apache License 2.0 4 votes vote down vote up
private int dumpReplicationQueues(DumpOptions opts) throws Exception {
  Configuration conf = getConf();
  Connection connection = ConnectionFactory.createConnection(conf);
  Admin admin = connection.getAdmin();

  ZKWatcher zkw = new ZKWatcher(conf, "DumpReplicationQueues" + System.currentTimeMillis(),
      new WarnOnlyAbortable(), true);

  try {
    // Our zk watcher
    LOG.info("Our Quorum: " + zkw.getQuorum());
    List<TableCFs> replicatedTableCFs = admin.listReplicatedTableCFs();
    if (replicatedTableCFs.isEmpty()) {
      LOG.info("No tables with a configured replication peer were found.");
      return(0);
    } else {
      LOG.info("Replicated Tables: " + replicatedTableCFs);
    }

    List<ReplicationPeerDescription> peers = admin.listReplicationPeers();

    if (peers.isEmpty()) {
      LOG.info("Replication is enabled but no peer configuration was found.");
    }

    System.out.println("Dumping replication peers and configurations:");
    System.out.println(dumpPeersState(peers));

    if (opts.isDistributed()) {
      LOG.info("Found [--distributed], will poll each RegionServer.");
      Set<String> peerIds = peers.stream().map((peer) -> peer.getPeerId())
          .collect(Collectors.toSet());
      System.out.println(dumpQueues(zkw, peerIds, opts.isHdfs()));
      System.out.println(dumpReplicationSummary());
    } else {
      // use ZK instead
      System.out.print("Dumping replication znodes via ZooKeeper:");
      System.out.println(ZKUtil.getReplicationZnodesDump(zkw));
    }
    return (0);
  } catch (IOException e) {
    return (-1);
  } finally {
    zkw.close();
  }
}