use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class MasterRpcServices method mergeTableRegions.
@Override
public MergeTableRegionsResponse mergeTableRegions(RpcController c, MergeTableRegionsRequest request) throws ServiceException {
try {
server.checkInitialized();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
RegionStates regionStates = server.getAssignmentManager().getRegionStates();
RegionInfo[] regionsToMerge = new RegionInfo[request.getRegionCount()];
for (int i = 0; i < request.getRegionCount(); i++) {
final byte[] encodedNameOfRegion = request.getRegion(i).getValue().toByteArray();
if (request.getRegion(i).getType() != RegionSpecifierType.ENCODED_REGION_NAME) {
LOG.warn("MergeRegions specifier type: expected: " + RegionSpecifierType.ENCODED_REGION_NAME + " actual: region " + i + " =" + request.getRegion(i).getType());
}
RegionState regionState = regionStates.getRegionState(Bytes.toString(encodedNameOfRegion));
if (regionState == null) {
throw new ServiceException(new UnknownRegionException(Bytes.toStringBinary(encodedNameOfRegion)));
}
regionsToMerge[i] = regionState.getRegion();
}
try {
long procId = server.mergeRegions(regionsToMerge, request.getForcible(), request.getNonceGroup(), request.getNonce());
return MergeTableRegionsResponse.newBuilder().setProcId(procId).build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class RawAsyncHBaseAdmin method getRegionLocation.
/**
* Get the region location for the passed region name. The region name may be a full region name
* or encoded region name. If the region does not found, then it'll throw an
* UnknownRegionException wrapped by a {@link CompletableFuture}
* @param regionNameOrEncodedRegionName region name or encoded region name
* @return region location, wrapped by a {@link CompletableFuture}
*/
CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedRegionName) {
if (regionNameOrEncodedRegionName == null) {
return failedFuture(new IllegalArgumentException("Passed region name can't be null"));
}
CompletableFuture<Optional<HRegionLocation>> future;
if (RegionInfo.isEncodedRegionName(regionNameOrEncodedRegionName)) {
String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) {
// old format encodedName, should be meta region
future = connection.registry.getMetaRegionLocations().thenApply(locs -> Stream.of(locs.getRegionLocations()).filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst());
} else {
future = ClientMetaTableAccessor.getRegionLocationWithEncodedName(metaTable, regionNameOrEncodedRegionName);
}
} else {
// Not all regionNameOrEncodedRegionName here is going to be a valid region name,
// it needs to throw out IllegalArgumentException in case tableName is passed in.
RegionInfo regionInfo;
try {
regionInfo = CatalogFamilyFormat.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
} catch (IOException ioe) {
return failedFuture(new IllegalArgumentException(ioe.getMessage()));
}
if (regionInfo.isMetaRegion()) {
future = connection.registry.getMetaRegionLocations().thenApply(locs -> Stream.of(locs.getRegionLocations()).filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId()).findFirst());
} else {
future = ClientMetaTableAccessor.getRegionLocation(metaTable, regionNameOrEncodedRegionName);
}
}
CompletableFuture<HRegionLocation> returnedFuture = new CompletableFuture<>();
addListener(future, (location, err) -> {
if (err != null) {
returnedFuture.completeExceptionally(err);
return;
}
if (!location.isPresent() || location.get().getRegion() == null) {
returnedFuture.completeExceptionally(new UnknownRegionException("Invalid region name or encoded region name: " + Bytes.toStringBinary(regionNameOrEncodedRegionName)));
} else {
returnedFuture.complete(location.get());
}
});
return returnedFuture;
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class TestRegionMergeTransactionOnCluster method testMerge.
/**
* This test tests 1, merging region not online;
* 2, merging same two regions; 3, merging unknown regions.
* They are in one test case so that we don't have to create
* many tables, and these tests are simple.
*/
@Test
public void testMerge() throws Exception {
LOG.info("Starting " + name.getMethodName());
final TableName tableName = TableName.valueOf(name.getMethodName());
final Admin admin = TEST_UTIL.getAdmin();
try {
// Create table and load data.
Table table = createTableAndLoadData(MASTER, tableName);
AssignmentManager am = MASTER.getAssignmentManager();
List<RegionInfo> regions = am.getRegionStates().getRegionsOfTable(tableName);
// Fake offline one region
RegionInfo a = regions.get(0);
RegionInfo b = regions.get(1);
am.unassign(b);
am.offlineRegion(b);
try {
// Merge offline region. Region a is offline here
FutureUtils.get(admin.mergeRegionsAsync(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false));
fail("Offline regions should not be able to merge");
} catch (DoNotRetryRegionException ie) {
System.out.println(ie);
assertTrue(ie instanceof MergeRegionException);
}
try {
// Merge the same region: b and b.
FutureUtils.get(admin.mergeRegionsAsync(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true));
fail("A region should not be able to merge with itself, even forcfully");
} catch (IOException ie) {
assertTrue("Exception should mention regions not online", StringUtils.stringifyException(ie).contains("region to itself") && ie instanceof MergeRegionException);
}
try {
// Merge unknown regions
FutureUtils.get(admin.mergeRegionsAsync(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true));
fail("Unknown region could not be merged");
} catch (IOException ie) {
assertTrue("UnknownRegionException should be thrown", ie instanceof UnknownRegionException);
}
table.close();
} finally {
TEST_UTIL.deleteTable(tableName);
}
}
Aggregations