Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java API to HBase exception:cannot get location

I am trying to use JAVA API to connect to HBase. My codes are shown below:

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);
    }
}

When I run this program in my cluster, I got exception: I ran this and got error below:

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)

I ran this in a HDP cluster, exception happens after hbaseAdmin instantiation. It seems that JAVA client is not able to connect to Hbase using zookeeper, but I can use command "hbase zkcli" to open shell successfully.

Anyone knows what is problem? Is there any way to check zookeeper is good or not? Any help is appreciated.

like image 677
Frankie Avatar asked Aug 11 '16 16:08

Frankie


1 Answers

This seems to be an issue with the cluster. Can you make sure that HBase is happy and healthy and all Region servers are up and running?

Please open the shell and list the tables first to ensure basic check.. Also, check if any version mismatch of jars.

If you are running from the cluster below is sure shot approach to avoid any surprises.

Configuration conf = HBaseConfiguration.create();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");

also check that below way you are running java client

# export HADOOP_CLASSPATH=`./hbase classpath`
like image 163
Ram Ghadiyaram Avatar answered Sep 18 '22 12:09

Ram Ghadiyaram