簡體   English   中英

Java api檢查hbase是否已啟動並正在運行

[英]Java api to check if hbase is up and running

我正在嘗試連接到HBase時處理故障情況。 目前,我檢查HBase是否與HBaseAdmin.checkHBaseAvailable(conf);一起運行HBaseAdmin.checkHBaseAvailable(conf); 但是這個api只會在大約40秒之后拋出MasterNotRunningZookeeperConnectionException的異常。 所以,我嘗試設置以下重試, hbase.client.retries.number = 1zookeeper.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM