I have written a very short program to connect to Hbase
.
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class HbaseMonitor {
public static void main(String args[]){
Configuration conf = new Configuration();
try{
HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);
ClusterStatus clusterStatus = hbaseAdmin.getClusterStatus();
System.out.println("Has regions: "+clusterStatus.getRegionsCount());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
Compiled it using the same jars available in the lib
directory of hbase as shown below:
javac -cp /usr/lib/hbase/hbase-0.94.1-Intel.jar:/usr/lib/hadoop/hadoop-core-1.0.3-Intel.jar:/usr/lib/hbase/lib/commons-logging-1.1.1.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-lang-2.5.jar:/usr/lib/hbase/lib/slf4j-api-1.4.3.jar:/usr/lib/hbase/lib/slf4j-log4j12-1.4.3.jar:/usr/lib/hbase/lib/log4j-1.2.16.jar:/usr/lib/hbase/lib/guava-11.0.2.jar:/usr/lib/hbase/lib/protobuf-java-2.4.0a.jar:. HbaseMonitor.java
And when I run it, I get below exceptions:
15/03/19 17:47:07 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
15/03/19 17:47:07 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 17277@ostrich-node1
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration)
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x4c31791de7041e, negotiated timeout = 180000
15/03/19 17:47:07 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 0 of 10 failed; retrying after sleep of 1006
java.io.IOException: Call to ostrich-node1/192.168.151.50:60000 failed on local exception: java.io.EOFException
at org.apache.hadoop.hbase.ipc.HBaseClient.wrapException(HBaseClient.java:1110)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:1079)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:150)
at com.sun.proxy.$Proxy5.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:183)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:335)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:312)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:364)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:710)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:141)
at HbaseMonitor.main(HbaseMonitor.java:17)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.receiveResponse(HBaseClient.java:605)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.run(HBaseClient.java:538)
Telnet to the hbase-master works fine:
[root@ostrich-node1 test]# telnet ostrich-node1 60000
Trying 192.168.151.50...
Connected to ostrich-node1.
Escape character is '^]'.
Telnet of localhost clearly shows that the client could connect to the hbase:
[root@ostrich-node1 test]# telnet localhost 2181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
^CConnection closed by foreign host.
Log of master ( hbase-hbase-master-ostrich-node1.log
) displays below warning for the above exception:
2015-03-19 17:47:07,711 WARN org.apache.hadoop.ipc.SecureServer: Incorrect header or version mismatch from 192.168.151.50:57502 got version 3 expected version 4
From the above warning, one may say that the hadoop-core.jar
I am using for hbase
is different from the one being used for hadoop
. Yes, it was. So, I replaced the jar but unfortunately the error didn't go away.
Please note that I have executed my program on the same machine which has hbase installed.
Hbase version:
[root@ostrich-node1 logs]# hbase version
15/03/19 17:59:17 INFO util.VersionInfo: HBase 0.94.1-Intel
Hadoop version:
[root@ostrich-node1 logs]# hadoop version
Hadoop 1.0.3-Intel
Hbase shell works:
[root@ostrich-node1 logs]# hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.1-Intel, r17177, Wed Sep 18 14:52:53 CST 2013
hbase(main):001:0> list
TABLE
ATTR
RECO
SUBSCRIBER
SUBSCRIBER2
TPETEST
test
6 row(s) in 1.0700 seconds
So, what can be the issue? Please help.
This worked for me by doing following things:
HBASE_CONF
in the end of the classpath
, like shown below (right click over image and open it in a new tab, if they are too small to understand): Note : in my hbase master node, HBASE_CONF=/usr/lib/hbase/conf .
Note: HBaseConfiguration()
is deprecated but works for hbase-0.94.1 (Intel).
And the output is shown below:
Sorry, code highlighter was not working for large codes. Therefore, I used images to show them properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.