Frank Kong
Frank Kong

Reputation: 1072

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.

Upvotes: 6

Views: 12969

Answers (3)

Abhash Kumar
Abhash Kumar

Reputation: 1228

I was also getting the same error earlier when i had

conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX");
conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX");
conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX");

I changed it to :

 conf.set("zookeeper.znode.parent", "/hbase-secure");       
 conf.set("hbase.zookeeper.property.clientPort", "2181");
 conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX"); 
 conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX");
 conf.set("hbase.zookeeper.quorum", "XXXX.XXXX.XXXX.XXXX.XXXX.XXXX");

Now it is working.

Upvotes: 1

Manoj Kumar Vohra
Manoj Kumar Vohra

Reputation: 321

I believe this could be because of deprecated APIs if the cluster is upgraded.

It is recommended that org.apache.hadoop.hbase.client.Connection should be used to connect with Hbase tables.

Connection object encapsulates lower level individual connections to actual servers and a connection to zookeeper.

Connections are instantiated through the org.apache.hadoop.hbase.client.ConnectionFactory class.

Connections can be created as : this.configuration = HBaseConfiguration.create();

    try {
        connection = ConnectionFactory.createConnection(configuration);
    } catch (IOException e) {
        logger.error("Exception Occured While Creating Connection:" + 
e.getMessage());
    }

Table handle can be acquired as:

table = connection.getTable(TableName.valueOf(queryTable));

Upvotes: 0

Ram Ghadiyaram
Ram Ghadiyaram

Reputation: 29195

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`

Upvotes: 2

Related Questions