RegionServer端put数据流程分析:
client端通过MultiServerCallable.call调用rs的rpc的multi方法。
regionServer实例ClientProtos.ClientService.BlockingInterface接口。
publicMultiResponse multi(finalRpcControllerrpcc,finalMultiRequest request)
throwsServiceException {
//rpc controller is how we bring in data via the back door; it isunprotobuf'ed data.
//It is also the conduit via which we pass back data.
PayloadCarryingRpcControllercontroller= (PayloadCarryingRpcController)rpcc;
CellScannercellScanner= controller!= null?controller.cellScanner():null;
if(controller!= null)controller.setCellScanner(null);
List<CellScannable>cellsToReturn= null;
MultiResponse.BuilderresponseBuilder= MultiResponse.newBuilder();
RegionActionResult.BuilderregionActionResultBuilder= RegionActionResult.newBuilder();
得到当前提交的数据,数据按region,list的方式传入过来。
for(RegionAction regionAction: request.getRegionActionList()){
this.requestCount.add(regionAction.getActionCount());
regionActionResultBuilder.clear();
HRegion region;
try{
从当前regionserver中的onlnieRegions中得到请求的region.
1.从onlineRegions中取出HRegion实例,如果不为空,按如下流程走,否则:执行到5
2.如果onlineRegions列表中不包含此region,从movedRegions列表中拿到region,region的moved超时是2分钟,
如果movedRegions列表中能拿到此region,同时move时间超时,并从movedRegions列表中移出引region返回null,
否则返回正在moved的region,如果movedRegions中返回的region不为null,throwRegionMovedException
3.从regionsInTransitionInRS中获取此region,如果能拿到,同时拿到的值为true,表示region还在做opening操作。
Throw RegionOpeningException
4.如果以上得到的值都为null,表示此server中没有此region,throw NotServingRegionException
此时基本上只有一个可能,region在做split.或者move到其它server(刚完成move,client请求时不在此server)
5.如果1中拿到region,表示正常,region在此server中。
region= getRegion(regionAction.getRegion());
} catch(IOException e){
regionActionResultBuilder.setException(ResponseConverter.buildException(e));
responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
continue; // For this region it's a failure.
}
检查是否是原子操作:
if(regionAction.hasAtomic()&& regionAction.getAtomic()){
//How does this call happen? It may need some work to play well w/ thesurroundings.
//Need to return an item per Action along w/ Action index. TODO.
Try{
执行原子操作:保证一个region中所有的action的操作的mvcc的值相同,如果有一个操作失败,整体rollback
mutateRows(region,regionAction.getActionList(),cellScanner);
} catch(IOException e){
//As it's atomic, we may expect it's a global failure.
regionActionResultBuilder.setException(ResponseConverter.buildException(e));
}
} else{
//doNonAtomicRegionMutation manages the exception internally
执行非原子操作:见