Search in sources :

Example 6 with ZooKeeperConnectionException

use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.

the class HBaseAdmin method available.

/**
   * Is HBase available? Throw an exception if not.
   * @param conf system configuration
   * @throws MasterNotRunningException if the master is not running.
   * @throws ZooKeeperConnectionException if unable to connect to zookeeper.
   * // TODO do not expose ZKConnectionException.
   */
public static void available(final Configuration conf) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
    Configuration copyOfConf = HBaseConfiguration.create(conf);
    // We set it to make it fail as soon as possible if HBase is not available
    copyOfConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
    copyOfConf.setInt("zookeeper.recovery.retry", 0);
    // If the connection exists, we may have a connection to ZK that does not work anymore
    try (ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(copyOfConf)) {
        // Check ZK first.
        // If the connection exists, we may have a connection to ZK that does not work anymore
        ZooKeeperKeepAliveConnection zkw = null;
        try {
            // This is NASTY. FIX!!!! Dependent on internal implementation! TODO
            zkw = ((ConnectionImplementation) connection).getKeepAliveZooKeeperWatcher();
            zkw.getRecoverableZooKeeper().getZooKeeper().exists(zkw.znodePaths.baseZNode, false);
        } catch (IOException e) {
            throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException("Can't connect to ZooKeeper").initCause(e);
        } catch (KeeperException e) {
            throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
        } finally {
            if (zkw != null) {
                zkw.close();
            }
        }
        // can throw MasterNotRunningException
        connection.isMasterRunning();
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) Configuration(org.apache.hadoop.conf.Configuration) CompoundConfiguration(org.apache.hadoop.hbase.CompoundConfiguration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with ZooKeeperConnectionException

use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.

the class TestAdmin2 method testCheckHBaseAvailableWithoutCluster.

/**
   * Check that we have an exception if the cluster is not there.
   */
@Test(timeout = 300000)
public void testCheckHBaseAvailableWithoutCluster() {
    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
    // Change the ZK address to go to something not used.
    conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 9999) + 10);
    long start = System.currentTimeMillis();
    try {
        HBaseAdmin.available(conf);
        assertTrue(false);
    } catch (ZooKeeperConnectionException ignored) {
    } catch (IOException ignored) {
    }
    long end = System.currentTimeMillis();
    LOG.info("It took " + (end - start) + " ms to find out that" + " HBase was not available");
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with ZooKeeperConnectionException

use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.

the class ZooKeeperWatcher method createBaseZNodes.

private void createBaseZNodes() throws ZooKeeperConnectionException {
    try {
        // Create all the necessary "directories" of znodes
        ZKUtil.createWithParents(this, znodePaths.baseZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.rsZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.drainingZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.tableZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.splitLogZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.backupMasterAddressesZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.tableLockZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.recoveringRegionsZNode);
        ZKUtil.createAndFailSilent(this, znodePaths.masterMaintZNode);
    } catch (KeeperException e) {
        throw new ZooKeeperConnectionException(prefix("Unexpected KeeperException creating base node"), e);
    }
}
Also used : ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) KeeperException(org.apache.zookeeper.KeeperException)

Example 9 with ZooKeeperConnectionException

use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.

the class HMasterCommandLine method stopMaster.

@SuppressWarnings("resource")
private int stopMaster() {
    Configuration conf = getConf();
    // Don't try more than once
    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Admin admin = connection.getAdmin()) {
            admin.shutdown();
        } catch (Throwable t) {
            LOG.error("Failed to stop master", t);
            return 1;
        }
    } catch (MasterNotRunningException e) {
        LOG.error("Master not running");
        return 1;
    } catch (ZooKeeperConnectionException e) {
        LOG.error("ZooKeeper not available");
        return 1;
    } catch (IOException e) {
        LOG.error("Got IOException: " + e.getMessage(), e);
        return 1;
    }
    return 0;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) Connection(org.apache.hadoop.hbase.client.Connection) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin)

Example 10 with ZooKeeperConnectionException

use of org.apache.hadoop.hbase.ZooKeeperConnectionException in project hbase by apache.

the class TestMasterNoCluster method tearDown.

@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;
        }
    });
    // Before fails sometimes so retry.
    try {
        TESTUTIL.waitFor(10000, (Waiter.Predicate<Exception>) () -> {
            try {
                ZKUtil.deleteNodeRecursively(zkw, zkw.getZNodePaths().baseZNode);
                return true;
            } catch (KeeperException.NotEmptyException e) {
                LOG.info("Failed delete, retrying", e);
            }
            return false;
        });
    } catch (Exception e) {
        LOG.info("Failed zk clear", e);
    }
    zkw.close();
}
Also used : Abortable(org.apache.hadoop.hbase.Abortable) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Waiter(org.apache.hadoop.hbase.Waiter) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) After(org.junit.After)

Aggregations

ZooKeeperConnectionException (org.apache.hadoop.hbase.ZooKeeperConnectionException)12 IOException (java.io.IOException)9 MasterNotRunningException (org.apache.hadoop.hbase.MasterNotRunningException)7 BiMap (com.google.common.collect.BiMap)4 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 ServerName (org.apache.hadoop.hbase.ServerName)4 KeeperException (org.apache.zookeeper.KeeperException)4 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)3 NavigableMap (java.util.NavigableMap)3 HTable (org.apache.hadoop.hbase.client.HTable)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)2 InterruptedIOException (java.io.InterruptedIOException)1