Reputation: 41
I'm trying to handle failure scenarios when connecting to HBase. Currently, I've a check to see if HBase is running with HBaseAdmin.checkHBaseAvailable(conf);
. But this api would thrown an exception in case of MasterNotRunning
or ZookeeperConnectionException
only after ~40 seconds. So, I tried setting the following retries, hbase.client.retries.number = 1
and zookeeper.recovery.retry = 1
. This got me the exception to be handled in 6-7 seconds. But, I need a much quicker way to know if HBase cluster is running, since I'm logging to HBase in a synchronous call within my application.
Upvotes: 4
Views: 2964
Reputation: 10650
What about checking the connection in this way:
import java.net.InetSocketAddress;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.HMasterInterface;
import org.apache.hadoop.hbase.ipc.RpcEngine;
...
public static boolean isRunning() {
boolean result = false;
Configuration conf = HBaseConfiguration.create();
conf.clear();
conf.set("hbase.zookeeper.quorum", "myhost");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.master", "myhost:60000");
RpcEngine rpcEngine = null;
try {
InetSocketAddress isa = new InetSocketAddress("myhost", 60000);
rpcEngine = HBaseRPC.getProtocolEngine(conf);
HMasterInterface master = rpcEngine.getProxy(HMasterInterface.class,
HMasterInterface.VERSION, isa, conf, 1000);
result = master.isMasterRunning();
}
catch (Exception e) {
// ...
}
finally {
if (rpcEngine != null) {
rpcEngine.close();
}
}
return result;
}
Note: I assumed here version >= 0.94.5
Upvotes: 4