Java API to HBase exception:cannot get location
Asked Answered
R

3

6

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.

Rumple answered 11/8, 2016 at 16:14 Comment(12)
are you connecting to hbase from windows eclipse like ide or you are running the program directly in cluster?Mucky
@RamPrasadG I am running the jar file directly in cluster. I run the same program in my sandbox, it works fine. But in cluster, it does not work.Rumple
okay. did you run the java client with -cp hbase classpath?Mucky
I only added path of jar in -cp.Rumple
add hbase classpath also with ` as start and ` as end characterMucky
@RamPrasadG I added it in my -cp. It still does not work but I got new error: [main] zookeeper.RecoverableZooKeeper: Unable to create ZooKeeper Connection: java.net.UnknownHostException:Rumple
please paste complete command you were submitting the job. If done correctly and cluster network is correct then it should workMucky
My command to submitting job is: java -cp /home/username/java2hbase-0.0.1-SNAPSHOT-jar-with-dependencies.jar:hbase classpath java2hbase-0.0.1-SNAPSHOT-jar-with-dependencies.jar. I guess name of server cannot be recognized, so I will change them into IP addr and try.Rumple
@RamPrasadG Oh cool, after change to IP addr. I got new error: java.lang.reflet.InvocationTargetException and java.lang.NoSuchMethodError. I guess it because version mismatch, right?Rumple
yes I think that might be the issueMucky
I compile my program in java 1.5 while in cluster the java version is 1.8. I am going to compile with the same version and see. Thanks for your help @RamPrasadGRumple
I have same issue .I am running this using eclipse on windows.please help me. this my hbase-site.xml<property> <name>hbase.zookeeper.quorum</name> <value>localhost</value> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property>Nesta
M
2

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`
Mucky answered 11/8, 2016 at 17:19 Comment(3)
pls try to do the above and post resultMucky
I did it, but still does not work. After that, I added HBaseAdmin.checkHBaseAvailable(conf); to check and I got a NullPointerErrorRumple
since hbaseadmin is not initialized it might be null. so method call on null leaded to null pointer exceptionMucky
H
1

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.

Herwick answered 22/1, 2018 at 12:33 Comment(0)
B
0

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));
Birdella answered 14/12, 2017 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.