Search in sources :

Example 6 with AssignmentManager

use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.

the class RestoreSnapshotProcedure method addRegionsToInMemoryStates.

/**
 * Add regions to in-memory states
 * @param regionInfos regions to add
 * @param env MasterProcedureEnv
 * @param regionReplication the number of region replications
 */
private void addRegionsToInMemoryStates(List<RegionInfo> regionInfos, MasterProcedureEnv env, int regionReplication) {
    AssignmentManager am = env.getAssignmentManager();
    for (RegionInfo regionInfo : regionInfos) {
        if (regionInfo.isSplit()) {
            am.getRegionStates().updateRegionState(regionInfo, RegionState.State.SPLIT);
        } else {
            am.getRegionStates().updateRegionState(regionInfo, RegionState.State.CLOSED);
            // For region replicas
            for (int i = 1; i < regionReplication; i++) {
                RegionInfo regionInfoForReplica = RegionReplicaUtil.getRegionInfoForReplica(regionInfo, i);
                am.getRegionStates().updateRegionState(regionInfoForReplica, RegionState.State.CLOSED);
            }
        }
    }
}
Also used : AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 7 with AssignmentManager

use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.

the class HBaseTestingUtil method predicateNoRegionsInTransition.

/**
 * Returns a {@link Predicate} for checking that there are no regions in transition in master
 */
public ExplainingPredicate<IOException> predicateNoRegionsInTransition() {
    return new ExplainingPredicate<IOException>() {

        @Override
        public String explainFailure() throws IOException {
            final RegionStates regionStates = getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
            return "found in transition: " + regionStates.getRegionsInTransition().toString();
        }

        @Override
        public boolean evaluate() throws IOException {
            HMaster master = getMiniHBaseCluster().getMaster();
            if (master == null)
                return false;
            AssignmentManager am = master.getAssignmentManager();
            if (am == null)
                return false;
            return !am.hasRegionsInTransition();
        }
    };
}
Also used : RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate)

Example 8 with AssignmentManager

use of org.apache.hadoop.hbase.master.assignment.AssignmentManager 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
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);
    RegionInfo 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.balancerSwitch(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 = CommonFSUtils.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(), 0, storefiles.size());
        // 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 no
        // store files
        List<HRegion> daughters = cluster.getRegions(tableName);
        assertEquals(2, daughters.size());
        // check dirs
        HBaseFsck.debugLsr(conf, new Path("/"));
        Map<String, Path> storefilesAfter = FSUtils.getTableStoreFilePathMap(null, fs, rootDir, tableName);
        assertEquals("Expected nothing but found " + storefilesAfter.toString(), 0, storefilesAfter.size());
        // split parent
        hri = region.getRegionInfo();
        AssignmentManager am = cluster.getMaster().getAssignmentManager();
        RegionStates regionStates = am.getRegionStates();
        long start = EnvironmentEdgeManager.currentTime();
        while (!regionStates.isRegionInState(hri, State.SPLIT)) {
            LOG.debug("Waiting for SPLIT state on: " + hri);
            assertFalse("Timed out in waiting split parent to be in state SPLIT", EnvironmentEdgeManager.currentTime() - start > 60000);
            Thread.sleep(500);
        }
        assertTrue(regionStates.isRegionInState(daughters.get(0).getRegionInfo(), State.OPEN));
        assertTrue(regionStates.isRegionInState(daughters.get(1).getRegionInfo(), State.OPEN));
        // We should not be able to assign it again
        try {
            am.assign(hri);
        } catch (DoNotRetryIOException e) {
        // Expected
        }
        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
        try {
            am.unassign(hri);
            fail("Should have thrown exception");
        } catch (DoNotRetryIOException e) {
        // Expected
        }
        assertFalse("Split region can't be unassigned", regionStates.isRegionInTransition(hri));
        assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
    } finally {
        admin.balancerSwitch(true, false);
        cluster.getMaster().setCatalogJanitorEnabled(true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Example 9 with AssignmentManager

use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.

the class TestReopenTableRegionsProcedureInfiniteLoop method testInfiniteLoop.

@Test
public void testInfiniteLoop() throws IOException {
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    AssignmentManager am = master.getAssignmentManager();
    ProcedureExecutor<MasterProcedureEnv> exec = master.getMasterProcedureExecutor();
    RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0);
    RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo);
    long procId;
    ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME);
    regionNode.lock();
    try {
        procId = exec.submitProcedure(proc);
        UTIL.waitFor(30000, () -> proc.hasLock());
        TransitRegionStateProcedure trsp = TransitRegionStateProcedure.reopen(exec.getEnvironment(), regionInfo);
        regionNode.setProcedure(trsp);
        exec.submitProcedure(trsp);
    } finally {
        regionNode.unlock();
    }
    UTIL.waitFor(60000, () -> exec.isFinished(procId));
}
Also used : TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 10 with AssignmentManager

use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.

the class TestHBaseFsckMOB method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MasterSyncCoprocessor.class.getName());
    conf.setInt("hbase.regionserver.handler.count", 2);
    conf.setInt("hbase.regionserver.metahandler.count", 30);
    conf.setInt("hbase.htable.threads.max", POOL_SIZE);
    conf.setInt("hbase.hconnection.threads.max", 2 * POOL_SIZE);
    conf.setInt("hbase.hbck.close.timeout", 2 * REGION_ONLINE_TIMEOUT);
    conf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 8 * REGION_ONLINE_TIMEOUT);
    TEST_UTIL.startMiniCluster(1);
    tableExecutorService = new ThreadPoolExecutor(1, POOL_SIZE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), new ThreadFactoryBuilder().setNameFormat("testhbck-pool-%d").setDaemon(true).setUncaughtExceptionHandler(Threads.LOGGING_EXCEPTION_HANDLER).build());
    hbfsckExecutorService = new ScheduledThreadPoolExecutor(POOL_SIZE);
    AssignmentManager assignmentManager = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
    regionStates = assignmentManager.getRegionStates();
    connection = TEST_UTIL.getConnection();
    admin = connection.getAdmin();
    admin.balancerSwitch(false, true);
    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SynchronousQueue(java.util.concurrent.SynchronousQueue) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ThreadFactoryBuilder(org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BeforeClass(org.junit.BeforeClass)

Aggregations

AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)30 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)13 Test (org.junit.Test)13 TableName (org.apache.hadoop.hbase.TableName)10 HMaster (org.apache.hadoop.hbase.master.HMaster)10 IOException (java.io.IOException)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ServerName (org.apache.hadoop.hbase.ServerName)7 RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)6 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)5 ArrayList (java.util.ArrayList)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 List (java.util.List)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)3 Admin (org.apache.hadoop.hbase.client.Admin)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ExecutionException (java.util.concurrent.ExecutionException)2