hbase源码分析HTable ->getScanner(final Scan scan)源码分析

来源:互联网 发布:网络写作平台17k 编辑:程序博客网 时间:2024/05/29 04:46
HTable ->getScanner(final Scan scan)源码分析


1、判断scan.getBatch() > 0 && scan.isSmall()
batch默认为-1 


small默认为false 
定义如下:
/**
   * Set it true for small scan to get better performance
   *
   * Small scan should use pread and big scan can use seek + read
   *
   * seek + read is fast but can cause two problem (1) resource contention (2)
   * cause too much network io
   *
   * [89-fb] Using pread for non-compaction read request
   * https://issues.apache.org/jira/browse/HBASE-7266
   *
   * On the other hand, if setting it true, we would do
   * openScanner,next,closeScanner in one RPC call. It means the better
   * performance for small scan. [HBASE-9488].
   *
   * Generally, if the scan range is within one data block(64KB), it could be
   * considered as a small scan.
   */
  private boolean small = false;


如果判断为true,则抛出异常
throw new IllegalArgumentException("Small scan should not be used with batching");
也就是说如果scan是small就不能batch


2、判断scan.getCaching() <= 0
如果为true从配置文件中hbase.client.scanner.caching读取,如果不存在,返回值为Integer.MAX_VALUE


3、判断scan.getMaxResultSize() <= 0
maxResultSize默认值为-1,if语句为true,则从配置文件中hbase.client.scanner.max.result.size中读取,如果不存在,返回值为2 * 1024 * 1024


 /** 
     * scan总共分为四种类型: 
     * 1、reversed、small--ClientSmallReversedScanner 
     * 2、reversed、big--ReversedClientScanner 
     * 3、notReversed、small--ClientSmallScanner 
     * 4、notReversed、big--ClientScanner 
     */  


4、判断scan.isReversed()


  /**
   * Get whether this scan is a reversed one.
   * @return true if backward scan, false if forward(default) scan
   */
4.1、判断scan.isSmall()
/**
   * Get whether this scan is a small scan
   * @return true if small scan
   */
true:
return new ClientSmallReversedScanner(getConfiguration(), scan, getName(),
            this.connection, this.rpcCallerFactory, this.rpcControllerFactory,
            pool, tableConfiguration.getReplicaCallTimeoutMicroSecondScan());
false:
 return new ReversedClientScanner(getConfiguration(), scan, getName(),
            this.connection, this.rpcCallerFactory, this.rpcControllerFactory,
            pool, tableConfiguration.getReplicaCallTimeoutMicroSecondScan());
5、判断scan.isSmall()
true:
 return new ClientSmallScanner(getConfiguration(), scan, getName(),
          this.connection, this.rpcCallerFactory, this.rpcControllerFactory,
          pool, tableConfiguration.getReplicaCallTimeoutMicroSecondScan());
false:
return new ClientScanner(getConfiguration(), scan, getName(), this.connection,
          this.rpcCallerFactory, this.rpcControllerFactory,

          pool, tableConfiguration.getReplicaCallTimeoutMicroSecondScan());

接下来再一个一个分析

0 0