您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

HBase源码分析之GET操作之get转化为scan

2025/11/1 14:48:55发布16次查看
hbase源码分析之get操作之get转化为scan 1,还是先看构造函数 public get(byte [] row) { this(row, null); } public ge
hbase源码分析之get操作之get转化为scan
1,还是先看构造函数
  public get(byte [] row) {
    this(row, null);
  }
public get(byte [] row, rowlock rowlock) {
    this.row = row;
    if(rowlock != null) {
      this.lockid = rowlock.getlockid();
    }
  }
  public get addfamily(byte [] family) {
    familymap.remove(family);
    familymap.put(family, null);
    return this;
  }
public get addcolumn(byte [] family, byte [] qualifier) {
    navigableset set = familymap.get(family);
    if(set == null) {
      set = new treeset(bytes.bytes_comparator);
    }
    set.add(qualifier);
    familymap.put(family, set);
    return this;
public get addcolumn(final byte [] column) {
    if (column == null) return this;
    byte [][] split = keyvalue.parsecolumn(column);
    if (split.length > 1 && split[1] != null && split[1].length > 0) {
      addcolumn(split[0], split[1]);
    } else {
      addfamily(split[0]);
    }
    return this;
  }
2,htable.java  里的get方法,,实则是调用了hregionserver的get方法。
  public result get(final get get) throws ioexception {
    return connection.getregionserverwithretries(
        new servercallable(connection, tablename, get.getrow()) {
          public result call() throws ioexception {
            return server.get(location.getregioninfo().getregionname(), get);
          }
        }
    );
  }
3,再来看看hregionserver.java
  /** {@inheritdoc} */
  public result get(byte[] regionname, get get) throws ioexception {
    checkopen();
    requestcount.incrementandget();
    try {
      hregion region = getregion(regionname);
      return region.get(get, getlockfromid(get.getlockid()));
    } catch (throwable t) {
      throw convertthrowabletoioe(cleanup(t));
    }
  }
再来看看hregion的get方法:
1),首先是检测family,保证table中的family与get中的一致
  public result get(final get get, final integer lockid) throws ioexception {
    // verify families are all valid
    if (get.hasfamilies()) {
      for (byte [] family: get.familyset()) {
        checkfamily(family);
      }
    } else { // adding all families to scanner
      for (byte[] family: regioninfo.gettabledesc().getfamilieskeys()) {
        get.addfamily(family);
      }
    }
    list result = get(get);
return new result(result);
  }
最终get其实是转化为scan了
 /*
  * do a get based on the get parameter.
  */
  private list get(final get get) throws ioexception {
    scan scan = new scan(get);
list results = new arraylist();
internalscanner scanner = null;
    try {
      scanner = getscanner(scan);
      scanner.next(results);
    } finally {
      if (scanner != null)
        scanner.close();
    }
    return results;
  }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product