3

I'm currently using HBase v0.98.6. I would like to check the current connection status from an external Java program. Right now, I'm doing something like this to check:

connectionSuccess = true;
try {
     HConnection hConnection = createConnection(config);
} catch (Exception ex) {
     connectionSuccess = false;
}

When the connection is working, this returns fairly quickly. The problem is when the connection is not working, and it takes 20 minutes for it to finally return connectionSuccess=false. Is there a way to reduce this time limit, as I'm just interested in getting the connection status at the current time?

shimizu
  • 998
  • 14
  • 20
  • You can use an Executor to time out the connection attempt as shown at http://stackoverflow.com/questions/1164301/how-do-i-call-some-blocking-method-with-a-timeout-in-java. –  Jul 10 '15 at 19:42
  • I'd prefer to set this in a configuration property, if possible. – shimizu Jul 10 '15 at 20:36
  • Reading through http://apache-hbase.679495.n3.nabble.com/How-to-make-the-client-fast-fail-td4072257.html the best solution is to use a timeout thread and using an Executor is equivalent to that. –  Jul 10 '15 at 21:23
  • Btw, the timeout thread works fine for my purpose. Thanks! – shimizu Aug 19 '15 at 02:27

3 Answers3

3

The reason it takes so long is that by default if the connection fails it will retry multiple times (I think 6? don't quote me), and each connection attempt takes a while. Try a combination of these commands to limit time per connection before timeout, and number of permitted retry attempts.

hbase.client.retries.number = 3
hbase.client.pause = 1000
zookeeper.recovery.retry = 1 (i.e. no retry)

Credit to Lars from http://hadoop-hbase.blogspot.com/2012/09/hbase-client-timeouts.html

Daniel Epstein
  • 481
  • 5
  • 6
1

You can set the retries value to 1 to get the status of the connection at the current time.

Configuration conf = HBaseConfiguration.create();
conf.setInt("hbase.client.retries.number",1);
conf.setInt("zookeeper.recovery.retry",0);

Or you can use the below in-built HbaseAdmin method which does the same thing.

connectionSuccess = true;
try
{
  HBaseAdmin.checkHBaseAvailable(config);
}
catch(MasterNotRunningException e)
{
  connectionSuccess = false;
}
0

My org.apache.hadoop.conf.Configuration object contains following key value pairs:

Configuration conf = HBaseConfiguration.create();

//configuring timeout and retry parameters
conf.set("hbase.rpc.timeout", "10000");
conf.set("hbase.client.scanner.timeout.period", "10000");
conf.set("hbase.cells.scanned.per.heartbeat.check", "10000");
conf.set("zookeeper.session.timeout", "10000");
conf.set("phoenix.query.timeoutMs", "10000");
conf.set("phoenix.query.keepAliveMs", "10000");
conf.set("hbase.client.retries.number", "3");
conf.set("hbase.client.pause", "1000");
conf.set("zookeeper.recovery.retry", "1");
mahkras
  • 541
  • 4
  • 6