Java API到HBase异常:无法获取位置

Fra*_*kie 6 java hbase apache-zookeeper

我正在尝试使用JAVA API连接到HBase.我的代码如下所示:

public class Test {
    public static void main(String[] args) throws IOException{
        TableName tableName = TableName.valueOf("TABLE2");

        Configuration conf = HBaseConfiguration.create();
        conf.set("zookeeper.znode.parent", "/hbase-secure");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        conf.set("hbase.zookeeper.quorum", "xxxxxxxxxxxxxx");
        conf.set("hbase.master", "xxxxxxxxxxxxx");

        Connection conn = ConnectionFactory.createConnection(conf);
        Admin admin = conn.getAdmin();
        System.out.println(admin.toString());

        if(!admin.tableExists(tableName)){
            admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor("cf")));
        }

        Table table = conn.getTable(tableName);
        Put p = new Put(Bytes.toBytes("AAPL10232015"));
        p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("close"), Bytes.toBytes(119));
        table.put(p);

        Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));
        System.out.println(r);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在我的集​​群中运行这个程序时,我遇到了异常:我运行了这个并得到以下错误:

Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
        at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:312)
        at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:151)
        at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:59)
        at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
        at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:320)
        at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:295)
        at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:160)
        at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:155)
        at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:821)
        at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
        at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
        at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:303)
        at java2hbase.Test.main(Test.java:31)
Run Code Online (Sandbox Code Playgroud)

我在HDP集群中运行它,在hbaseAdmin实例化之后发生异常.似乎JAVA客户端无法使用zookeeper连接到Hbase,但我可以使用命令"hbase zkcli"成功打开shell.

谁知道什么是问题?有没有办法检查zookeeper是好还是不好?任何帮助表示赞赏.

Ram*_*ram 2

这似乎是集群的问题。您能否确保 HBase 正常运行并且所有区域服务器都正常运行?

请先打开 shell 并列出表以确保基本检查。此外,检查 jar 是否有任何版本不匹配。

如果您从下面的集群中运行,则一定要采取射击方法以避免任何意外。

Configuration conf = HBaseConfiguration.create();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");
Run Code Online (Sandbox Code Playgroud)

还要检查您是否以下面的方式运行 java 客户端

# export HADOOP_CLASSPATH=`./hbase classpath`
Run Code Online (Sandbox Code Playgroud)