Hbase region split源代码阅读笔记
客户端
1. HbaseAdmin.split(final byte [] tableNameOrRegionName,
final byte [] splitPoint)
这个方法首先判断参数是regionName还是tableName;如果是regionName则只分裂该region,如果是tableName则分裂该表下的所有region
if (isRegionName(tableNameOrRegionName)) {//如果是regionName
// Its a possible region name.
Pair<HRegionInfo, HServerAddress> pair =
MetaReader.getRegion(ct, tableNameOrRegionName);//读出regionInfo和RegionServerAddress
if (pair == null || pair.getSecond() == null) {
LOG.info("No server in .META. for " +
Bytes.toStringBinary(tableNameOrRegionName) + "; pair=" + pair);
} else {
split(pair.getSecond(), pair.getFirst(), splitPoint);//调用方法分裂该region
}
} else {{//如果是tableName
List<Pair<HRegionInfo, HServerAddress>> pairs =
MetaReader.getTableRegionsAndLocations(ct,
Bytes.toString(tableNameOrRegionName));//读出table下的一批region
for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
// May not be a server for a particular row
if (pair.getSecond() == null) continue;
HRegionInfo r = pair.getFirst();
// check for parents
if (r.isSplitParent()) continue;
if (splitPoint != null) {
// if a split point given, only split that particular region
if (!r.containsRow(splitPoint)) continue;
}
split(pair.getSecond(), pair.getFirst(), splitPoint);调用方法分裂这批region
}
2. HbaseAdmin.split(final HServerAddress hsa, final HRegionInfo hri,
byte[] splitPoint)
这只是个代理方法,调起regionserver的远程接口
HRegionInterface rs = this.connection.getHRegionConnection(hsa);
rs.splitRegion(hri, splitPoint);
RegionServer服务端
3.HRegionServer.splitRegion(HRegionInfo regionInfo, byte[] splitPoint)
checkOpen();//检查regionserver是否停止
HRegion region = getRegion(regionInfo.getRegionName());//拿到在线region
region.flushcache();//写memstore到hfile
region.forceSplit(splitPoint);//设置了两个值this.splitRequest=true 和 splitPoint = sp
// force a compaction, split will be side-effect
// TODO: flush/compact/split refactor will make it trivial to do this
// sync/async (and won't require us to do a compaction to split!)
compactSplitThread.requestCompaction(region, "User-triggered split",
CompactSplitThread.PRIORITY_USER);//异步发起一个region的compact操作