Java API exception for HBase: Unable to get location

I am trying to use the 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 an exception: I ran this and got the 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 an HDP cluster, an exception occurs after creating hbaseAdmin. It seems that the JAVA client cannot connect to Hbase using zookeeper, but I can use the "hbase zkcli" command to successfully open the shell.

Does anyone know what the problem is? Is there a way to check zookeeper is good or not? Any help is appreciated.

+4
source share
3 answers

, , . , HBase , ?

, , . , , - .

, , , .

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

, java-

# export HADOOP_CLASSPATH=`./hbase classpath`
+2

,

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

:

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

.

+1

, - API, .

, org.apache.hadoop.hbase.client.Connection Hbase.

zookeeper.

Connections are created 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());
    }

The table handle can be obtained as:

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

Source: https://habr.com/ru/post/1650938/


All Articles