Java api for checking hbase start

I am trying to handle failure scenarios when connecting to HBase. I have currently checked if HBase works with HBaseAdmin.checkHBaseAvailable(conf); . But this api MasterNotRunning exception in case of MasterNotRunning or ZookeeperConnectionException after only ~ 40 seconds. So, I tried to set the following repetitions, hbase.client.retries.number = 1 and zookeeper.recovery.retry = 1 . This made me an exception that could be handled in 6-7 seconds. But I need a much faster way to find out if the HBase cluster is working, as I register with HBase in a synchronous call in my application.

+4
source share
1 answer

How about checking the connection 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

+3
source

Source: https://habr.com/ru/post/1502863/


All Articles