Search in sources :

Example 6 with AssignmentManager

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

the class TestAdmin2 method testMoveToPreviouslyAssignedRS.

@Test(timeout = 300000)
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Admin localAdmin = createTable(tableName);
    List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
    HRegionInfo hri = tableRegions.get(0);
    AssignmentManager am = master.getAssignmentManager();
    assertTrue("Region " + hri.getRegionNameAsString() + " should be assigned properly", am.waitForAssignment(hri));
    ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
    localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
    assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Test(org.junit.Test)

Example 7 with AssignmentManager

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

the class CreateTableProcedure method assignRegions.

protected static void assignRegions(final MasterProcedureEnv env, final TableName tableName, final List<HRegionInfo> regions) throws IOException {
    ProcedureSyncWait.waitRegionServers(env);
    // Mark the table as Enabling
    env.getMasterServices().getTableStateManager().setTableState(tableName, TableState.State.ENABLING);
    // Trigger immediate assignment of the regions in round-robin fashion
    final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager();
    ModifyRegionUtils.assignRegions(assignmentManager, regions);
    // Enable table
    env.getMasterServices().getTableStateManager().setTableState(tableName, TableState.State.ENABLED);
}
Also used : AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager)

Example 8 with AssignmentManager

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

the class EnableTableProcedure method markRegionsOnline.

/**
   * Mark offline regions of the table online
   * @param env MasterProcedureEnv
   * @param tableName the target table
   * @return whether the operation is fully completed or being interrupted.
   * @throws IOException
   */
private static boolean markRegionsOnline(final MasterProcedureEnv env, final TableName tableName) throws IOException {
    final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager();
    final MasterServices masterServices = env.getMasterServices();
    final ServerManager serverManager = masterServices.getServerManager();
    boolean done = false;
    // Get the regions of this table. We're done when all listed
    // tables are onlined.
    List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations;
    if (TableName.META_TABLE_NAME.equals(tableName)) {
        tableRegionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(masterServices.getZooKeeper());
    } else {
        tableRegionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(masterServices.getConnection(), tableName);
    }
    int countOfRegionsInTable = tableRegionsAndLocations.size();
    Map<HRegionInfo, ServerName> regionsToAssign = regionsToAssignWithServerName(env, tableRegionsAndLocations);
    // need to potentially create some regions for the replicas
    List<HRegionInfo> unrecordedReplicas = AssignmentManager.replicaRegionsNotRecordedInMeta(new HashSet<>(regionsToAssign.keySet()), masterServices);
    Map<ServerName, List<HRegionInfo>> srvToUnassignedRegs = assignmentManager.getBalancer().roundRobinAssignment(unrecordedReplicas, serverManager.getOnlineServersList());
    if (srvToUnassignedRegs != null) {
        for (Map.Entry<ServerName, List<HRegionInfo>> entry : srvToUnassignedRegs.entrySet()) {
            for (HRegionInfo h : entry.getValue()) {
                regionsToAssign.put(h, entry.getKey());
            }
        }
    }
    int offlineRegionsCount = regionsToAssign.size();
    LOG.info("Table '" + tableName + "' has " + countOfRegionsInTable + " regions, of which " + offlineRegionsCount + " are offline.");
    if (offlineRegionsCount == 0) {
        return true;
    }
    List<ServerName> onlineServers = serverManager.createDestinationServersList();
    Map<ServerName, List<HRegionInfo>> bulkPlan = env.getMasterServices().getAssignmentManager().getBalancer().retainAssignment(regionsToAssign, onlineServers);
    if (bulkPlan != null) {
        LOG.info("Bulk assigning " + offlineRegionsCount + " region(s) across " + bulkPlan.size() + " server(s), retainAssignment=true");
        BulkAssigner ba = new GeneralBulkAssigner(masterServices, bulkPlan, assignmentManager, true);
        try {
            if (ba.bulkAssign()) {
                done = true;
            }
        } catch (InterruptedException e) {
            LOG.warn("Enable operation was interrupted when enabling table '" + tableName + "'");
            // Preserve the interrupt.
            Thread.currentThread().interrupt();
        }
    } else {
        LOG.info("Balancer was unable to find suitable servers for table " + tableName + ", leaving unassigned");
    }
    return done;
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) GeneralBulkAssigner(org.apache.hadoop.hbase.master.GeneralBulkAssigner) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MasterServices(org.apache.hadoop.hbase.master.MasterServices) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ServerName(org.apache.hadoop.hbase.ServerName) BulkAssigner(org.apache.hadoop.hbase.master.BulkAssigner) GeneralBulkAssigner(org.apache.hadoop.hbase.master.GeneralBulkAssigner) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.hadoop.hbase.util.Pair)

Example 9 with AssignmentManager

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

the class ProcedureSyncWait method waitRegionInTransition.

protected static void waitRegionInTransition(final MasterProcedureEnv env, final List<HRegionInfo> regions) throws IOException, CoordinatedStateException {
    final AssignmentManager am = env.getMasterServices().getAssignmentManager();
    final RegionStates states = am.getRegionStates();
    for (final HRegionInfo region : regions) {
        ProcedureSyncWait.waitFor(env, "regions " + region.getRegionNameAsString() + " in transition", new ProcedureSyncWait.Predicate<Boolean>() {

            @Override
            public Boolean evaluate() throws IOException {
                if (states.isRegionInState(region, State.FAILED_OPEN)) {
                    am.regionOffline(region);
                }
                return !states.isRegionInTransition(region);
            }
        });
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionStates(org.apache.hadoop.hbase.master.RegionStates) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) InterruptedIOException(java.io.InterruptedIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) IOException(java.io.IOException)

Example 10 with AssignmentManager

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

the class RegionLocationFinder method scheduleFullRefresh.

/**
   * Refresh all the region locations.
   *
   * @return true if user created regions got refreshed.
   */
private boolean scheduleFullRefresh() {
    // Protect from anything being null while starting up.
    if (services == null) {
        return false;
    }
    AssignmentManager am = services.getAssignmentManager();
    if (am == null) {
        return false;
    }
    RegionStates regionStates = am.getRegionStates();
    if (regionStates == null) {
        return false;
    }
    Set<HRegionInfo> regions = regionStates.getRegionAssignments().keySet();
    boolean includesUserTables = false;
    for (final HRegionInfo hri : regions) {
        cache.refresh(hri);
        includesUserTables = includesUserTables || !hri.isSystemTable();
    }
    return includesUserTables;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionStates(org.apache.hadoop.hbase.master.RegionStates) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager)

Aggregations

AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)24 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 ServerName (org.apache.hadoop.hbase.ServerName)6 TableName (org.apache.hadoop.hbase.TableName)6 RegionStates (org.apache.hadoop.hbase.master.RegionStates)6 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)4 RegionState (org.apache.hadoop.hbase.master.RegionState)4 BeforeClass (org.junit.BeforeClass)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HMaster (org.apache.hadoop.hbase.master.HMaster)3 MasterWalManager (org.apache.hadoop.hbase.master.MasterWalManager)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 List (java.util.List)2 Map (java.util.Map)2