我正在尝试连接到HBase时处理故障情况.目前,我检查HBase是否与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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。