HBASE ScannerTimeoutException 问题

在对Hbase进行Scan的时候有时候会抛出ScannerTimeoutException,场景如下:

 

Java代码   收藏代码
  1. 2012 15:28:52 (14mins, 41sec)  
  2. org.apache.hadoop.hbase.client.ScannerTimeoutException: 60622ms passed since the last invocation, timeout is currently set to 60000  
  3.     at org.apache.hadoop.hbase.client.HTable$ClientScanner.next(HTable.java:1196)  
  4.     at org.apache.hadoop.hbase.mapreduce.TableRecordReaderImpl.nextKeyValue(TableRecordReaderImpl.java:133)  
  5.     at org.apache.hadoop.hbase.mapreduce.TableRecordReader.nextKeyValue(TableRecordReader.java:142)  
  6.     at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:532)  
  7.     at org.apache.hadoop.mapreduce.MapContext.nextKeyValue(MapContext.java:67)  
  8.     at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:143)  
  9.     at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)  
  10.     at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)  
  11.     at org.apache.hadoop.mapred.Child$4.run(Child.java:255)  
  12.     at java.security.AccessController.doPrivileged(Native Method)  
  13.     at javax.security.auth.Subject.doAs(Subject.java:396)  
  14.     at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093)  
  15.     at org.apache.hadoop.mapred.Child.main(Child.java:249)  

 

原因查看步骤: 

查找源码如下:

 

Java代码   收藏代码
  1. long timeout = lastNext + scannerTimeout;  
  2.              // If we are over the timeout, throw this exception to the client  
  3.              // Else, it's because the region moved and we used the old id  
  4.              // against the new region server; reset the scanner.  
  5.              if (timeout < System.currentTimeMillis()) {  
  6.                long elapsed = System.currentTimeMillis() - lastNext;  
  7.                ScannerTimeoutException ex = new ScannerTimeoutException(  
  8.                    elapsed + "ms passed since the last invocation, " +  
  9.                        "timeout is currently set to " + scannerTimeout);  
  10.                ex.initCause(e);  
  11.                throw ex;  
  12.              }  

 

 核实下如下代码

 

Java代码   收藏代码
  1. long timeout = lastNext + scannerTimeout;  
Java代码   收藏代码
  1. 得出:ClientScanner.lastNext和HTable.scannerTimeout  

 

 跟踪:HTable.scannerTimeout

 

Java代码   收藏代码
  1. this.scannerTimeout =  
  2.      (int) conf.getLong(HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, HConstants.DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD);  

 

 查看HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY和HConstants.DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD

我们可以得知如果没有设置HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY那么他们采用默认值即

 

Java代码   收藏代码
  1. public static long DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD = 60000;  

 跟踪:ClientScanner.lastNext发现此为上次访问时间

解决方案:

可以通过设置HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY解决

代码如下:

 

Java代码   收藏代码
  1. config.setLong(HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, 120000);    

猜你喜欢

转载自zhangxiong0301.iteye.com/blog/2142659