Java 连接HBASE ,执行查询超时的解决方法

在连接hbase时,系统默认的rpc超时时间是1分钟,即60000,scanner 超时默认没有设置。因此,但数据量较大、scanner较慢的时候,查询就会报错:
Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Wed Sep 07 08:14:48 CST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=60316: row '20' on table 'src_customs' at region=src_customs,20,1473065204994.c5296399e88185d6d19e5b600e9376b5., hostname=hadoop-s1,60020,1472804690476, seqNum=2

at org.apache.hadoop.hbase.client.AbstractClientScanner$1.hasNext(AbstractClientScanner.java:97)
at Mysteel.hbase_mobile.HbaseOperator.findRecords(HbaseOperator.java:181)
at Mysteel.hbase_mobile.HbaseOperator.main(HbaseOperator.java:257)
Caused by: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Wed Sep 07 08:14:48 CST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=60316: row '20' on table 'src_customs' at region=src_customs,20,1473065204994.c5296399e88185d6d19e5b600e9376b5., hostname=hadoop-s1,60020,1472804690476, seqNum=2

截图如下:

Java 连接HBASE ,执行查询超时的解决方法_第1张图片
解决办法:在连接的配置中设置超时时长。
public static Configuration getConfig(){
Configuration conf = HBaseConfiguration.create();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.set("hbase.zookeeper.quorum","hadoop-m,hadoop-s1,hadoop-s2,hadoop-s3");
conf.set("hbase.master", ",hadoop-m:60000");
conf.set("hbase.zookeeper.property.clientPort","2181");
conf.setInt("hbase.rpc.timeout",20000);
conf.setInt("hbase.client.operation.timeout",30000);
conf.setInt("hbase.client.scanner.timeout.period",200000);
return conf;
}

你可能感兴趣的:(Hbase)