视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
HBase源码分析之GET操作之get转化为scan
2020-11-09 10:55:29 责编:小采
文档


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;
}

下载本文
显示全文
专题