Testing java HBase connection

痴心易碎 提交于 2019-11-30 17:33:43

问题


I am trying to use the HBase Java APIs to write data into HBase. I installed Hadoop/HBase through Ambari.

Here is how the configuration is currently set up:

final Configuration CONFIGURATION = HBaseConfiguration.create();
final HBaseAdmin HBASE_ADMIN;

HBASE_ADMIN = new HBaseAdmin(CONFIGURATION)

When I try to write to HBase, I check to make sure that the table exists

!HBASE_ADMIN.tableExists(tableName)

If not, create a new one. However, it appears that when attempting to check if the table exists exceptions are being thrown.

I'm wondering if I'm not correctly connected to HBase...is there any good way to verify that the configuration is correct and that I am connecting to HBase? The exception I'm getting is below.

Thanks.


java.lang.RuntimeException: java.lang.NullPointerException
  at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:209)
  at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:288)
  at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:268)
  at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:140)
  at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:135)
  at org.apache.hadoop.hbase.catalog.MetaReader.fullScan(MetaReader.java:597)
  at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:802)
  at org.apache.hadoop.hbase.catalog.MetaReader.tableExists(MetaReader.java:359)
  at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:287)
  at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:301)
  at com.business.project.hbase.HBaseMessageWriter.getTable(HBaseMessageWriter.java:40)
  at com.business.project.hbase.HBaseMessageWriter.write(HBaseMessageWriter.java:59)
  at com.business.project.hbase.HBaseMessageWriter.write(HBaseMessageWriter.java:54)
  at com.business.project.storm.bolt.package.exampleBolt.execute(exampleBolt.java:19)
  at backtype.storm.daemon.executor$fn__5697$tuple_action_fn__5699.invoke(executor.clj:659)
  at backtype.storm.daemon.executor$mk_task_receiver$fn__5620.invoke(executor.clj:415)
  at backtype.storm.disruptor$clojure_handler$reify__1741.onEvent(disruptor.clj:58)
  at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:125)
  at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:99)
  at backtype.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:80)
  at backtype.storm.daemon.executor$fn__5697$fn__5710$fn__5761.invoke(executor.clj:794)
  at backtype.storm.util$async_loop$fn__452.invoke(util.clj:465)
  at clojure.lang.AFn.run(AFn.java:24)
  at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
  at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.getMetaReplicaNodes(ZooKeeperWatcher.java:269)
  at org.apache.hadoop.hbase.zookeeper.MetaRegionTracker.blockUntilAvailable(MetaRegionTracker.java:241)
  at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:62)
  at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1203)
  at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1164)
  at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:294)
  at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:130)
  at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:55)
  at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:201)

回答1:


In addition to the configuration parameters suggested by Yosr, specifying

conf.set("zookeeper.znode.parent", "VALUE")

would help resolve the issue.




回答2:


The property below resolved my issue

For Hortonworks: hconfig.set("zookeeper.znode.parent", "/hbase-unsecure")

For cloudera: hconfig.set("zookeeper.znode.parent", "/hbase")




回答3:


   Configuration conf = HBaseConfiguration.create();
   conf.set("hbase.master", "ip_address:60000");
   conf.set("hbase.zookeeper.quorum","ip_address");
   conf.set("hbase.zookeeper.property.clientPort", "2181");

    HBaseAdmin admin = new HBaseAdmin(conf);

    boolean bool = admin.tableExists("table_name");
    System.out.println( bool);

ip_address : this is the ip_adress of your hbase cluster, change your hbase zookeeper port (2181) if it is not the same on your configuration files.




回答4:


You can use HBaseAdmin.checkHBaseAvailable(conf);



来源:https://stackoverflow.com/questions/29564831/testing-java-hbase-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!