+ (regionAHasMergeQualifier ? region_a.getEncodedName() : region_b
.getEncodedName()) + " has merge qualifier");
return;
}
RegionStates regionStates = masterServices.getAssignmentManager()
.getRegionStates();
ServerName region_a_location = regionStates.getRegionServerOfRegion(region_a);
ServerName region_b_location = regionStates.getRegionServerOfRegion(region_b);
if (region_a_location == null || region_b_location == null) {
LOG.info("Skip merging regions " + region_a.getRegionNameAsString()
+ ", " + region_b.getRegionNameAsString() + ", because region "
+ (region_a_location == null ? region_a.getEncodedName() : region_b
.getEncodedName()) + " is not online now");
return;
}
long startTime = EnvironmentEdgeManager.currentTimeMillis();
boolean onSameRS = region_a_location.equals(region_b_location);
// Make sure regions are on the same regionserver before send merge
// regions request to regionserver
if (!onSameRS) {
// Move region_b to region a's location, switch region_a and region_b if
// region_a's load lower than region_b's, so we will always move lower
// load region
RegionLoad loadOfRegionA = masterServices.getServerManager()
.getLoad(region_a_location).getRegionsLoad()
.get(region_a.getRegionName());
RegionLoad loadOfRegionB = masterServices.getServerManager()
.getLoad(region_b_location).getRegionsLoad()
.get(region_b.getRegionName());
if (loadOfRegionA != null && loadOfRegionB != null
&& loadOfRegionA.getRequestsCount() < loadOfRegionB
.getRequestsCount()) {
// switch region_a and region_b
HRegionInfo tmpRegion = this.region_a;
this.region_a = this.region_b;
this.region_b = tmpRegion;
ServerName tmpLocation = region_a_location;
region_a_location = region_b_location;
region_b_location = tmpLocation;
}
RegionPlan regionPlan = new RegionPlan(region_b, region_b_location,
region_a_location);
masterServices.getAssignmentManager().balance(regionPlan);
while (!masterServices.isStopped()) {
try {
Thread.sleep(20);
region_b_location = masterServices.getAssignmentManager()
.getRegionStates().getRegionServerOfRegion(region_b);
onSameRS = region_a_location.equals(region_b_location);
if (onSameRS || !regionStates.isRegionInTransition(region_b)) {
// Regions are on the same RS, or region_b is not in
// RegionInTransition any more
break;
}
if ((EnvironmentEdgeManager.currentTimeMillis() - startTime) > timeout) break;