Search in sources :

Example 11 with RegionStates

use of org.apache.hadoop.hbase.master.RegionStates in project hbase by apache.

the class TestSplitTransactionOnCluster method testMasterRestartAtRegionSplitPendingCatalogJanitor.

/**
   * Verifies HBASE-5806.  Here the case is that splitting is completed but before the
   * CJ could remove the parent region the master is killed and restarted.
   * @throws IOException
   * @throws InterruptedException
   * @throws NodeExistsException
   * @throws KeeperException
   */
@Test(timeout = 300000)
public void testMasterRestartAtRegionSplitPendingCatalogJanitor() throws IOException, InterruptedException, NodeExistsException, KeeperException, ServiceException {
    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);
    HRegionInfo hri = getAndCheckSingleTableRegion(regions);
    int tableRegionIndex = ensureTableRegionNotOnSameServerAsMeta(admin, hri);
    // Turn off balancer so it doesn't cut in and mess up our placements.
    this.admin.setBalancerRunning(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: ");
        this.admin.splitRegion(hri.getRegionName());
        checkAndGetDaughters(tableName);
        HMaster master = abortAndWaitForMaster();
        this.admin = TESTING_UTIL.getAdmin();
        // Update the region to be offline and split, so that HRegionInfo#equals
        // returns true in checking rebuilt region states map.
        hri.setOffline(true);
        hri.setSplit(true);
        RegionStates regionStates = master.getAssignmentManager().getRegionStates();
        assertTrue("Split parent should be in SPLIT state", regionStates.isRegionInState(hri, State.SPLIT));
        ServerName regionServerOfRegion = regionStates.getRegionServerOfRegion(hri);
        assertTrue(regionServerOfRegion == null);
    } finally {
        this.admin.setBalancerRunning(true, false);
        cluster.getMaster().setCatalogJanitorEnabled(true);
        t.close();
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) RegionStates(org.apache.hadoop.hbase.master.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 12 with RegionStates

use of org.apache.hadoop.hbase.master.RegionStates in project hbase by apache.

the class TestSplitTransactionOnCluster method testSplitRegionWithNoStoreFiles.

/**
   * If a table has regions that have no store files in a region, they should split successfully
   * into two regions with no store files.
   */
@Test(timeout = 60000)
public void testSplitRegionWithNoStoreFiles() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    // Create table then get the single region for our new table.
    createTableAndWait(tableName, HConstants.CATALOG_FAMILY);
    List<HRegion> regions = cluster.getRegions(tableName);
    HRegionInfo hri = getAndCheckSingleTableRegion(regions);
    ensureTableRegionNotOnSameServerAsMeta(admin, hri);
    int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionInfo().getRegionName());
    HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
    // Turn off balancer so it doesn't cut in and mess up our placements.
    this.admin.setBalancerRunning(false, true);
    // Turn off the meta scanner so it don't remove parent on us.
    cluster.getMaster().setCatalogJanitorEnabled(false);
    try {
        // Precondition: we created a table with no data, no store files.
        printOutRegions(regionServer, "Initial regions: ");
        Configuration conf = cluster.getConfiguration();
        HBaseFsck.debugLsr(conf, new Path("/"));
        Path rootDir = FSUtils.getRootDir(conf);
        FileSystem fs = TESTING_UTIL.getDFSCluster().getFileSystem();
        Map<String, Path> storefiles = FSUtils.getTableStoreFilePathMap(null, fs, rootDir, tableName);
        assertEquals("Expected nothing but found " + storefiles.toString(), storefiles.size(), 0);
        // find a splittable region.  Refresh the regions list
        regions = cluster.getRegions(tableName);
        final HRegion region = findSplittableRegion(regions);
        assertTrue("not able to find a splittable region", region != null);
        // Now split.
        try {
            requestSplitRegion(regionServer, region, Bytes.toBytes("row2"));
        } catch (IOException e) {
            fail("Split execution should have succeeded with no exceptions thrown");
        }
        // Postcondition: split the table with no store files into two regions, but still have not
        // store files
        List<HRegion> daughters = cluster.getRegions(tableName);
        assertTrue(daughters.size() == 2);
        // check dirs
        HBaseFsck.debugLsr(conf, new Path("/"));
        Map<String, Path> storefilesAfter = FSUtils.getTableStoreFilePathMap(null, fs, rootDir, tableName);
        assertEquals("Expected nothing but found " + storefilesAfter.toString(), storefilesAfter.size(), 0);
        // split parent
        hri = region.getRegionInfo();
        AssignmentManager am = cluster.getMaster().getAssignmentManager();
        RegionStates regionStates = am.getRegionStates();
        long start = EnvironmentEdgeManager.currentTime();
        while (!regionStates.isRegionInState(hri, State.SPLIT)) {
            assertFalse("Timed out in waiting split parent to be in state SPLIT", EnvironmentEdgeManager.currentTime() - start > 60000);
            Thread.sleep(500);
        }
        // We should not be able to assign it again
        am.assign(hri, true);
        assertFalse("Split region can't be assigned", regionStates.isRegionInTransition(hri));
        assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
        // We should not be able to unassign it either
        am.unassign(hri, null);
        assertFalse("Split region can't be unassigned", regionStates.isRegionInTransition(hri));
        assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
    } finally {
        admin.setBalancerRunning(true, false);
        cluster.getMaster().setCatalogJanitorEnabled(true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.RegionStates) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Example 13 with RegionStates

use of org.apache.hadoop.hbase.master.RegionStates 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();
    // 10min
    final int syncWaitTimeout = 10 * 60000;
    try {
        // Create table and load data.
        Table table = createTableAndLoadData(MASTER, tableName);
        RegionStates regionStates = MASTER.getAssignmentManager().getRegionStates();
        List<HRegionInfo> regions = regionStates.getRegionsOfTable(tableName);
        // Fake offline one region
        HRegionInfo a = regions.get(0);
        HRegionInfo b = regions.get(1);
        regionStates.regionOffline(a);
        try {
            // Merge offline region. Region a is offline here
            admin.mergeRegionsAsync(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false).get(syncWaitTimeout, TimeUnit.MILLISECONDS);
            fail("Offline regions should not be able to merge");
        } catch (ExecutionException ie) {
            System.out.println(ie);
            assertTrue("Exception should mention regions not online", StringUtils.stringifyException(ie.getCause()).contains("regions not online") && ie.getCause() instanceof MergeRegionException);
        }
        try {
            // Merge the same region: b and b.
            admin.mergeRegionsAsync(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);
            fail("A region should not be able to merge with itself, even forcifully");
        } catch (IOException ie) {
            assertTrue("Exception should mention regions not online", StringUtils.stringifyException(ie).contains("region to itself") && ie instanceof MergeRegionException);
        }
        try {
            // Merge unknown regions
            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 : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) RegionStates(org.apache.hadoop.hbase.master.RegionStates) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 14 with RegionStates

use of org.apache.hadoop.hbase.master.RegionStates in project hbase by apache.

the class TestHBaseFsckOneRS method testSplitDaughtersNotInMeta.

/**
   * Split crashed after write to hbase:meta finished for the parent region, but
   * failed to write daughters (pre HBASE-7721 codebase)
   */
@Test(timeout = 75000)
public void testSplitDaughtersNotInMeta() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService);
    try {
        setupTable(tableName);
        assertEquals(ROWKEYS.length, countRows());
        // make sure data in regions, if in wal only there is no data loss
        admin.flush(tableName);
        try (RegionLocator rl = connection.getRegionLocator(tbl.getName())) {
            HRegionLocation location = rl.getRegionLocation(Bytes.toBytes("B"));
            HRegionInfo hri = location.getRegionInfo();
            // Disable CatalogJanitor to prevent it from cleaning up the parent region
            // after split.
            admin.enableCatalogJanitor(false);
            // do a regular split
            byte[] regionName = location.getRegionInfo().getRegionName();
            admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
            TestEndToEndSplitTransaction.blockUntilRegionSplit(conf, 60000, regionName, true);
            PairOfSameType<HRegionInfo> daughters = MetaTableAccessor.getDaughterRegions(meta.get(new Get(regionName)));
            // Delete daughter regions from meta, but not hdfs, unassign it.
            ServerName firstSN = rl.getRegionLocation(daughters.getFirst().getStartKey()).getServerName();
            ServerName secondSN = rl.getRegionLocation(daughters.getSecond().getStartKey()).getServerName();
            undeployRegion(connection, firstSN, daughters.getFirst());
            undeployRegion(connection, secondSN, daughters.getSecond());
            List<Delete> deletes = new ArrayList<>(2);
            deletes.add(new Delete(daughters.getFirst().getRegionName()));
            deletes.add(new Delete(daughters.getSecond().getRegionName()));
            meta.delete(deletes);
            // Remove daughters from regionStates
            RegionStates regionStates = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
            regionStates.deleteRegion(daughters.getFirst());
            regionStates.deleteRegion(daughters.getSecond());
            HBaseFsck hbck = doFsck(conf, false);
            assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, //no LINGERING_SPLIT_PARENT
            HBaseFsck.ErrorReporter.ERROR_CODE.HOLE_IN_REGION_CHAIN });
            // now fix it. The fix should not revert the region split, but add daughters to META
            hbck = doFsck(conf, true, true, false, false, false, false, false, false, false, false, false, false, null);
            assertErrors(hbck, new HBaseFsck.ErrorReporter.ERROR_CODE[] { HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.NOT_IN_META_OR_DEPLOYED, HBaseFsck.ErrorReporter.ERROR_CODE.HOLE_IN_REGION_CHAIN });
            // assert that the split hbase:meta entry is still there.
            Get get = new Get(hri.getRegionName());
            Result result = meta.get(get);
            assertNotNull(result);
            assertNotNull(MetaTableAccessor.getHRegionInfo(result));
            assertEquals(ROWKEYS.length, countRows());
            // assert that we still have the split regions
            //SPLITS + 1 is # regions
            assertEquals(rl.getStartKeys().length, SPLITS.length + 1 + 1);
            // pre-split.
            //should be fixed by now
            assertNoErrors(doFsck(conf, false));
        }
    } finally {
        admin.enableCatalogJanitor(true);
        meta.close();
        cleanupTable(tableName);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) RegionStates(org.apache.hadoop.hbase.master.RegionStates) Get(org.apache.hadoop.hbase.client.Get) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 15 with RegionStates

use of org.apache.hadoop.hbase.master.RegionStates in project hbase by apache.

the class MergeTableRegionsProcedure method setRegionStateToRevertMerging.

/**
   * Rollback the region state change
   * @param env MasterProcedureEnv
   * @throws IOException
   */
private void setRegionStateToRevertMerging(final MasterProcedureEnv env) throws IOException {
    RegionStateTransition.Builder transition = RegionStateTransition.newBuilder();
    transition.setTransitionCode(TransitionCode.MERGE_REVERTED);
    transition.addRegionInfo(HRegionInfo.convert(mergedRegionInfo));
    transition.addRegionInfo(HRegionInfo.convert(regionsToMerge[0]));
    transition.addRegionInfo(HRegionInfo.convert(regionsToMerge[1]));
    String msg = env.getMasterServices().getAssignmentManager().onRegionTransition(getServerName(env), transition.build());
    if (msg != null) {
        // If daughter regions are online, the msg is coming from RPC retry.  Ignore it.
        RegionStates regionStates = getAssignmentManager(env).getRegionStates();
        if (!regionStates.isRegionOnline(regionsToMerge[0]) || !regionStates.isRegionOnline(regionsToMerge[1])) {
            throw new IOException("Failed to update region state for " + getRegionsToMergeListFullNameString() + " as part of operation for reverting merge.  Error message: " + msg);
        }
    }
}
Also used : RegionStates(org.apache.hadoop.hbase.master.RegionStates) InterruptedIOException(java.io.InterruptedIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) RegionStateTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition)

Aggregations

RegionStates (org.apache.hadoop.hbase.master.RegionStates)19 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 TableName (org.apache.hadoop.hbase.TableName)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 Table (org.apache.hadoop.hbase.client.Table)7 ServerName (org.apache.hadoop.hbase.ServerName)6 AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)6 InterruptedIOException (java.io.InterruptedIOException)5 HMaster (org.apache.hadoop.hbase.master.HMaster)4 ArrayList (java.util.ArrayList)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)3 RegionState (org.apache.hadoop.hbase.master.RegionState)3 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)2 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)2 Result (org.apache.hadoop.hbase.client.Result)2 MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)2 HashMap (java.util.HashMap)1 List (java.util.List)1