[关闭]
@xtccc 2015-11-19T09:15:28.000000Z 字数 1717 阅读 8729

HBase应用的常见异常

给我写信
GitHub

此处输入图片的描述


HBase


#1 无法连接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时,使用下面的代码

  1. val hbaseConf = HBaseConfiguration.create
  2. val htable = new HTable(hbaseConf, s"${tablename}")
  3. val startKeys = htable.getStartKeys
  4. 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的地址,如下:

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

其中的常量Commons.ZkQurom形如"hadoop1.com:2181,hadoop4.com:2181,hadoop5.com:2181"


这样,就可以连接到位于其他节点的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

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注