[英]Java api to check if hbase is up and running
我正在尝试连接到HBase时处理故障情况。 目前,我检查HBase是否与HBaseAdmin.checkHBaseAvailable(conf);
一起运行HBaseAdmin.checkHBaseAvailable(conf);
。 但是这个api只会在大约40秒之后抛出MasterNotRunning
或ZookeeperConnectionException
的异常。 所以,我尝试设置以下重试, hbase.client.retries.number = 1
和zookeeper.recovery.retry = 1
。 这让我在6-7秒内处理异常。 但是,我需要一种更快速的方法来了解HBase集群是否正在运行,因为我正在我的应用程序中的同步调用中登录到HBase。
以这种方式检查连接怎么样:
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;
}
注意:我假设这里版本> = 0.94.5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.