Hbase region split源代码阅读笔记
客户端
1.HbaseAdmin.split(finalbyte[]tableNameOrRegionName,
finalbyte[]splitPoint)
这个方法首先判断参数是regionName还是tableName;如果是regionName则只分裂该region,如果是tableName则分裂该表下的所有region
if(isRegionName(tableNameOrRegionName)){//如果是regionName
//Itsapossibleregionname.
Pair<HRegionInfo,HServerAddress>pair=
MetaReader.getRegion(ct,tableNameOrRegionName);//读出regionInfo和RegionServerAddress
if(pair==null||pair.getSecond()==null){
LOG.info("Noserverin.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){
//Maynotbeaserverforaparticularrow
if(pair.getSecond()==null)continue;
HRegionInfor=pair.getFirst();
//checkforparents
if(r.isSplitParent())continue;
if(splitPoint!=null){
//ifasplitpointgiven,onlysplitthatparticularregion
if(!r.containsRow(splitPoint))continue;
}
split(pair.getSecond(),pair.getFirst(),splitPoint);调用方法分裂这批region
}
2.HbaseAdmin.split(finalHServerAddresshsa,finalHRegionInfohri,
byte[]splitPoint)
这只是个代理方法,调起regionserver的远程接口
HRegionInterfacers=this.connection.getHRegionConnection(hsa);
rs.splitRegion(hri,splitPoint);
RegionServer服务端
3.HRegionServer.splitRegion(HRegionInforegionInfo,byte[]splitPoint)
checkOpen();//检查regionserver是否停止
HRegionregion=getRegion(regionInfo.getRegionName());//拿到在线region
region.flushcache();//写memstore到hfile
region.forceSplit(splitPoint);//设置了两个值this.splitRequest=true和splitPoint=sp
//forceacompaction,splitwillbeside-effect
//TODO:flush/compact/splitrefactorwillmakeittrivialtodothis
//sync/async(andwon'trequireustodoacompactiontosplit!)
compactSplitThread.requestCompaction(region,"User-triggeredsplit",
CompactSplitThread.PRIORITY_USER);//异步发起一个region的compact操作