Search in sources :

Example 6 with MergeRegionException

use of org.apache.hadoop.hbase.exceptions.MergeRegionException 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

MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)6 TableName (org.apache.hadoop.hbase.TableName)4 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)4 IOException (java.io.IOException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 DoNotRetryRegionException (org.apache.hadoop.hbase.client.DoNotRetryRegionException)2 RegionState (org.apache.hadoop.hbase.master.RegionState)2 Test (org.junit.Test)2 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 Admin (org.apache.hadoop.hbase.client.Admin)1 Table (org.apache.hadoop.hbase.client.Table)1 CatalogJanitor (org.apache.hadoop.hbase.master.CatalogJanitor)1 RegionStates (org.apache.hadoop.hbase.master.RegionStates)1 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)1 MasterProcedureUtil (org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil)1 MergeTableRegionsProcedure (org.apache.hadoop.hbase.master.procedure.MergeTableRegionsProcedure)1 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)1