RegionState regionStateA = assignmentManager.getRegionStates()
.getRegionState(Bytes.toString(encodedNameOfRegionA));
RegionState regionStateB = assignmentManager.getRegionStates()
.getRegionState(Bytes.toString(encodedNameOfRegionB));
if (regionStateA == null || regionStateB == null) {
throw new ServiceException(new UnknownRegionException(
Bytes.toStringBinary(regionStateA == null ? encodedNameOfRegionA
: encodedNameOfRegionB)));
}
if (!regionStateA.isOpened() || !regionStateB.isOpened()) {
throw new ServiceException(new MergeRegionException(
"Unable to merge regions not online " + regionStateA + ", " + regionStateB));
}
HRegionInfo regionInfoA = regionStateA.getRegion();
HRegionInfo regionInfoB = regionStateB.getRegion();
if (regionInfoA.compareTo(regionInfoB) == 0) {
throw new ServiceException(new MergeRegionException(
"Unable to merge a region to itself " + regionInfoA + ", " + regionInfoB));
}
if (!forcible && !HRegionInfo.areAdjacent(regionInfoA, regionInfoB)) {
throw new ServiceException(new MergeRegionException(
"Unable to merge not adjacent regions "
+ regionInfoA.getRegionNameAsString() + ", "
+ regionInfoB.getRegionNameAsString()
+ " where forcible = " + forcible));
}
try {
dispatchMergingRegions(regionInfoA, regionInfoB, forcible);
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
return DispatchMergingRegionsResponse.newBuilder().build();
}