Search in sources :

Example 1 with GeneralBulkAssigner

use of org.apache.hadoop.hbase.master.GeneralBulkAssigner 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)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 ServerName (org.apache.hadoop.hbase.ServerName)1 AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)1 BulkAssigner (org.apache.hadoop.hbase.master.BulkAssigner)1 GeneralBulkAssigner (org.apache.hadoop.hbase.master.GeneralBulkAssigner)1 MasterServices (org.apache.hadoop.hbase.master.MasterServices)1 ServerManager (org.apache.hadoop.hbase.master.ServerManager)1 Pair (org.apache.hadoop.hbase.util.Pair)1 MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)1