Search in sources :

Example 1 with DoNotRetryRegionException

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;
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException)

Example 2 with DoNotRetryRegionException

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()));
    }
}
Also used : RegionState(org.apache.hadoop.hbase.master.RegionState) State(org.apache.hadoop.hbase.master.RegionState.State) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) RegionOfflineException(org.apache.hadoop.hbase.client.RegionOfflineException)

Example 3 with DoNotRetryRegionException

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();
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) Test(org.junit.Test)

Example 4 with DoNotRetryRegionException

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
    }
}
Also used : BeforeClass(org.junit.BeforeClass) TestName(org.junit.rules.TestName) Configuration(org.apache.hadoop.conf.Configuration) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Put(org.apache.hadoop.hbase.client.Put) TestCase.fail(junit.framework.TestCase.fail) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Table(org.apache.hadoop.hbase.client.Table) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Table(org.apache.hadoop.hbase.client.Table) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 5 with DoNotRetryRegionException

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);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Aggregations

DoNotRetryRegionException (org.apache.hadoop.hbase.client.DoNotRetryRegionException)6 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)6 TableName (org.apache.hadoop.hbase.TableName)4 Table (org.apache.hadoop.hbase.client.Table)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Admin (org.apache.hadoop.hbase.client.Admin)2 MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)2 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 TestCase.fail (junit.framework.TestCase.fail)1 Configuration (org.apache.hadoop.conf.Configuration)1 Coprocessor (org.apache.hadoop.hbase.Coprocessor)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)1 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)1 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)1 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)1