HBase使用常见异常

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u011491148/article/details/46848673

无法连接ZooKeeper


典型异常:

INFO ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

15/07/12 10:06:33 WARN ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect


例如当我们想获取HBase某张表各个Region的Start Keys时,使用下面的代码:

val hbaseConf = HBaseConfiguration.create
val htable = new HTable(hbaseConf, s"${tablename}")
val startKeys = htable.getStartKeys
startKeys.foreach(keys => println(Bytes.toStringBinary(keys)))



如果运行上述代码的节点没有安装ZooKeeper,那么就会报Session 0x0 for server null异常,如果运行的节点是ZooKeeper Qurom的一个节点,就不会报异常。


原因:由于代码中在创建HBase Configuration时没有显式地指定ZooKeeper Qurom,HBase的应用程序不知道到哪里去连接ZooKeeper Qurom,因此它会去尝试连接一个默认<localhost:2181>,从下面的日志可以看出来:

INFO ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)



因此,我们可以在代码中指定ZooKeeper Qurom的地址,如下:

val hbaseConf = HBaseConfiguration.create
hbaseConf.set(HConstants.ZOOKEEPER_QUORUM, Commons.ZkQurom)



这样,就可以连接到位于其他节点的ZooKeeper了,从下面的日志可以看出:

INFO ZooKeeper: Initiating client connection, connectString=hadoop4.com:2181,hadoop1.com:2181,hadoop5.com:2181 sessionTimeout=90000 watcher=hconnection-0x68122ade, quorum=hadoop4.com:2181,hadoop1.com:2181,hadoop5.com:2181, baseZNode=/hbase

15/07/12 10:15:58 INFO ClientCnxn: Opening socket connection to server hadoop1.com/59.215.222.3:2181. Will not attempt to authenticate using SASL (unknown error)

15/07/12 10:15:58 INFO ClientCnxn: Socket connection established to hadoop1.com/59.215.222.3:2181, initiating session

15/07/12 10:15:58 INFO ClientCnxn: Session establishment complete on server hadoop1.com/59.215.222.3:2181, sessionid = 0x24e51f0d17b4955, negotiated timeout = 60000

展开阅读全文

没有更多推荐了,返回首页