当连接到HBase时,我正在尝试处理失败的情况。目前,我正在检查HBase是否与HBaseAdmin.checkHBaseAvailable(conf);一起运行。但是,如果是MasterNotRunning或ZookeeperConnectionException,此接口将在大约40秒后抛出异常。因此,我尝试设置以下重试:hbase.client.retries.number = 1和zookeeper.recovery.retry = 1。这让我可以在6-7秒内处理异常。但是,我需要一种更快的方法来了解HBase集群是否正在运行,因为我在应用程序内的一个同步调用中登录到HBase。
发布于 2013-09-20 21:09:06
用这种方式检查连接怎么样:
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
https://stackoverflow.com/questions/18877594
复制相似问题