use of org.apache.hadoop.hbase.client.DoNotRetryRegionException in project hbase by apache.
the class MergeTableRegionsProcedure method checkRegionsToMerge.
/**
* @throws MergeRegionException If unable to merge regions for whatever reasons.
*/
private static void checkRegionsToMerge(MasterProcedureEnv env, final RegionInfo[] regions, final boolean force) throws MergeRegionException {
long count = Arrays.stream(regions).distinct().count();
if (regions.length != count) {
throw new MergeRegionException("Duplicate regions specified; cannot merge a region to " + "itself. Passed in " + regions.length + " but only " + count + " unique.");
}
if (count < 2) {
throw new MergeRegionException("Need two Regions at least to run a Merge");
}
RegionInfo previous = null;
for (RegionInfo ri : regions) {
if (previous != null) {
if (!previous.getTable().equals(ri.getTable())) {
String msg = "Can't merge regions from different tables: " + previous + ", " + ri;
LOG.warn(msg);
throw new MergeRegionException(msg);
}
if (!force && !ri.isAdjacent(previous) && !ri.isOverlap(previous)) {
String msg = "Unable to merge non-adjacent or non-overlapping regions '" + previous.getShortNameToLog() + "', '" + ri.getShortNameToLog() + "' when force=false";
LOG.warn(msg);
throw new MergeRegionException(msg);
}
}
if (ri.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) {
throw new MergeRegionException("Can't merge non-default replicas; " + ri);
}
try {
checkOnline(env, ri);
} catch (DoNotRetryRegionException dnrre) {
throw new MergeRegionException(dnrre);
}
previous = ri;
}
}
use of org.apache.hadoop.hbase.client.DoNotRetryRegionException in project hbase by apache.
the class RegionStateNode method checkOnline.
public void checkOnline() throws DoNotRetryRegionException {
RegionInfo ri = getRegionInfo();
State s = state;
if (s != State.OPEN) {
throw new DoNotRetryRegionException(ri.getEncodedName() + " is not OPEN; state=" + s);
}
if (ri.isSplitParent()) {
throw new DoNotRetryRegionException(ri.getEncodedName() + " is not online (splitParent=true)");
}
if (ri.isSplit()) {
throw new DoNotRetryRegionException(ri.getEncodedName() + " has split=true");
}
if (ri.isOffline()) {
// RegionOfflineException is not instance of DNRIOE so wrap it.
throw new DoNotRetryRegionException(new RegionOfflineException(ri.getEncodedName()));
}
}
use of org.apache.hadoop.hbase.client.DoNotRetryRegionException in project hbase by apache.
the class TestSplitTransactionOnCluster method testSplitRollbackOnRegionClosing.
@Test
public void testSplitRollbackOnRegionClosing() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
// Create table then get the single region for our new table.
Table t = createTableAndWait(tableName, HConstants.CATALOG_FAMILY);
List<HRegion> regions = cluster.getRegions(tableName);
RegionInfo hri = getAndCheckSingleTableRegion(regions);
int tableRegionIndex = ensureTableRegionNotOnSameServerAsMeta(admin, hri);
RegionStates regionStates = cluster.getMaster().getAssignmentManager().getRegionStates();
// Turn off balancer so it doesn't cut in and mess up our placements.
this.admin.balancerSwitch(false, true);
// Turn off the meta scanner so it don't remove parent on us.
cluster.getMaster().setCatalogJanitorEnabled(false);
try {
// Add a bit of load up into the table so splittable.
TESTING_UTIL.loadTable(t, HConstants.CATALOG_FAMILY, false);
// Get region pre-split.
HRegionServer server = cluster.getRegionServer(tableRegionIndex);
printOutRegions(server, "Initial regions: ");
int regionCount = cluster.getRegions(hri.getTable()).size();
regionStates.updateRegionState(hri, RegionState.State.CLOSING);
// split transaction. Catch the exception instead.
try {
FutureUtils.get(this.admin.splitRegionAsync(hri.getRegionName()));
fail();
} catch (DoNotRetryRegionException e) {
// Expected
}
// Wait around a while and assert count of regions remains constant.
for (int i = 0; i < 10; i++) {
Thread.sleep(100);
assertEquals(regionCount, cluster.getRegions(hri.getTable()).size());
}
regionStates.updateRegionState(hri, State.OPEN);
// Now try splitting and it should work.
admin.splitRegionAsync(hri.getRegionName()).get(2, TimeUnit.MINUTES);
// Get daughters
checkAndGetDaughters(tableName);
// OK, so split happened after we cleared the blocking node.
} finally {
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
use of org.apache.hadoop.hbase.client.DoNotRetryRegionException in project hbase by apache.
the class TestRegionMove method testDisableAndMove.
@Test
public void testDisableAndMove() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
// Create a table with more than one region
Table t = TEST_UTIL.createMultiRegionTable(tableName, Bytes.toBytes(F1), 10);
TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
// Write an update to each region
for (RegionInfo regionInfo : admin.getRegions(tableName)) {
byte[] startKey = regionInfo.getStartKey();
// The startKey of the first region is "empty", which would throw an error if we try to
// Put that.
byte[] rowKey = org.apache.hbase.thirdparty.com.google.common.primitives.Bytes.concat(startKey, Bytes.toBytes("1"));
Put p = new Put(rowKey);
p.addColumn(Bytes.toBytes(F1), Bytes.toBytes("q1"), Bytes.toBytes("value"));
t.put(p);
}
// Get a Region which is on the first RS
HRegionServer rs1 = TEST_UTIL.getRSForFirstRegionInTable(tableName);
HRegionServer rs2 = TEST_UTIL.getOtherRegionServer(rs1);
List<RegionInfo> regionsOnRS1ForTable = admin.getRegions(rs1.getServerName()).stream().filter((regionInfo) -> regionInfo.getTable().equals(tableName)).collect(Collectors.toList());
assertTrue("Expected to find at least one region for " + tableName + " on " + rs1.getServerName() + ", but found none", !regionsOnRS1ForTable.isEmpty());
final RegionInfo regionToMove = regionsOnRS1ForTable.get(0);
// Offline the region and then try to move it. Should fail.
admin.unassign(regionToMove.getRegionName(), true);
try {
admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
fail();
} catch (DoNotRetryRegionException e) {
// We got expected exception
}
// Reassign for next stage of test.
admin.assign(regionToMove.getRegionName());
// Disable the table
admin.disableTable(tableName);
try {
// Move the region to the other RS -- should fail
admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
fail();
} catch (DoNotRetryIOException e) {
// We got expected exception
}
}
use of org.apache.hadoop.hbase.client.DoNotRetryRegionException 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