Search in sources :

Example 26 with HBaseIOException

use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.

the class FavoredStochasticBalancer method retainAssignment.

/**
 * Reuse BaseLoadBalancer's retainAssignment, but generate favored nodes when its missing.
 */
@Override
@NonNull
public Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOException {
    Map<ServerName, List<RegionInfo>> assignmentMap = Maps.newHashMap();
    Map<ServerName, List<RegionInfo>> result = super.retainAssignment(regions, servers);
    if (result.isEmpty()) {
        LOG.warn("Nothing to assign to, probably no servers or no regions");
        return result;
    }
    // Lets check if favored nodes info is in META, if not generate now.
    FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(servers, getConf());
    helper.initialize();
    LOG.debug("Generating favored nodes for regions missing them.");
    Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap();
    try {
        for (Map.Entry<ServerName, List<RegionInfo>> entry : result.entrySet()) {
            ServerName sn = entry.getKey();
            ServerName primary = ServerName.valueOf(sn.getHostname(), sn.getPort(), NON_STARTCODE);
            for (RegionInfo hri : entry.getValue()) {
                if (FavoredNodesManager.isFavoredNodeApplicable(hri)) {
                    List<ServerName> favoredNodes = fnm.getFavoredNodes(hri);
                    if (favoredNodes == null || favoredNodes.size() < FAVORED_NODES_NUM) {
                        LOG.debug("Generating favored nodes for: " + hri + " with primary: " + primary);
                        ServerName[] secondaryAndTertiaryNodes = helper.getSecondaryAndTertiary(hri, primary);
                        if (secondaryAndTertiaryNodes != null && secondaryAndTertiaryNodes.length == 2) {
                            List<ServerName> newFavoredNodes = Lists.newArrayList();
                            newFavoredNodes.add(primary);
                            newFavoredNodes.add(ServerName.valueOf(secondaryAndTertiaryNodes[0].getHostname(), secondaryAndTertiaryNodes[0].getPort(), NON_STARTCODE));
                            newFavoredNodes.add(ServerName.valueOf(secondaryAndTertiaryNodes[1].getHostname(), secondaryAndTertiaryNodes[1].getPort(), NON_STARTCODE));
                            regionFNMap.put(hri, newFavoredNodes);
                            addRegionToMap(assignmentMap, hri, sn);
                        } else {
                            throw new HBaseIOException("Cannot generate secondary/tertiary FN for " + hri + " generated " + (secondaryAndTertiaryNodes != null ? secondaryAndTertiaryNodes : " nothing"));
                        }
                    } else {
                        List<ServerName> onlineFN = getOnlineFavoredNodes(servers, favoredNodes);
                        if (onlineFN.isEmpty()) {
                            // All favored nodes are dead, lets assign it to BOGUS
                            addRegionToMap(assignmentMap, hri, BOGUS_SERVER_NAME);
                        } else {
                            // Is primary not on FN? Less likely, but we can still take care of this.
                            if (FavoredNodesPlan.getFavoredServerPosition(favoredNodes, sn) != null) {
                                addRegionToMap(assignmentMap, hri, sn);
                            } else {
                                ServerName destination = onlineFN.get(ThreadLocalRandom.current().nextInt(onlineFN.size()));
                                LOG.warn("Region: " + hri + " not hosted on favored nodes: " + favoredNodes + " current: " + sn + " moving to: " + destination);
                                addRegionToMap(assignmentMap, hri, destination);
                            }
                        }
                    }
                } else {
                    addRegionToMap(assignmentMap, hri, sn);
                }
            }
        }
        if (!regionFNMap.isEmpty()) {
            LOG.debug("Updating FN in meta for missing regions, count: " + regionFNMap.size());
            fnm.updateFavoredNodes(regionFNMap);
        }
    } catch (IOException e) {
        throw new HBaseIOException("Cannot generate/update FN for regions: " + regionFNMap.keySet());
    }
    return assignmentMap;
}
Also used : FavoredNodeAssignmentHelper(org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) HashMap(java.util.HashMap) Map(java.util.Map) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 27 with HBaseIOException

use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.

the class FavoredStochasticBalancer method randomAssignment.

/**
 * If we have favored nodes for a region, we will return one of the FN as destination. If
 * favored nodes are not present for a region, we will generate and return one of the FN as
 * destination. If we can't generate anything, lets fallback.
 */
@Override
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers) throws HBaseIOException {
    ServerName destination = null;
    if (!FavoredNodesManager.isFavoredNodeApplicable(regionInfo)) {
        return super.randomAssignment(regionInfo, servers);
    }
    metricsBalancer.incrMiscInvocations();
    Configuration conf = getConf();
    List<ServerName> favoredNodes = fnm.getFavoredNodes(regionInfo);
    if (favoredNodes == null || favoredNodes.isEmpty()) {
        // Generate new favored nodes and return primary
        FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(servers, conf);
        helper.initialize();
        try {
            favoredNodes = helper.generateFavoredNodes(regionInfo);
            updateFavoredNodesForRegion(regionInfo, favoredNodes);
        } catch (IOException e) {
            LOG.warn("Encountered exception while doing favored-nodes (random)assignment " + e);
            throw new HBaseIOException(e);
        }
    }
    List<ServerName> onlineServers = getOnlineFavoredNodes(servers, favoredNodes);
    if (onlineServers.size() > 0) {
        destination = onlineServers.get(ThreadLocalRandom.current().nextInt(onlineServers.size()));
    }
    boolean alwaysAssign = conf.getBoolean(FAVORED_ALWAYS_ASSIGN_REGIONS, true);
    if (destination == null && alwaysAssign) {
        LOG.warn("Can't generate FN for region: " + regionInfo + " falling back");
        destination = super.randomAssignment(regionInfo, servers);
    }
    return destination;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FavoredNodeAssignmentHelper(org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 28 with HBaseIOException

use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.

the class HMaster method createProcedureExecutor.

private void createProcedureExecutor() throws IOException {
    MasterProcedureEnv procEnv = new MasterProcedureEnv(this);
    procedureStore = new RegionProcedureStore(this, masterRegion, new MasterProcedureEnv.FsUtilsLeaseRecovery(this));
    procedureStore.registerListener(new ProcedureStoreListener() {

        @Override
        public void abortProcess() {
            abort("The Procedure Store lost the lease", null);
        }
    });
    MasterProcedureScheduler procedureScheduler = procEnv.getProcedureScheduler();
    procedureExecutor = new ProcedureExecutor<>(conf, procEnv, procedureStore, procedureScheduler);
    configurationManager.registerObserver(procEnv);
    int cpus = Runtime.getRuntime().availableProcessors();
    final int numThreads = conf.getInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, Math.max((cpus > 0 ? cpus / 4 : 0), MasterProcedureConstants.DEFAULT_MIN_MASTER_PROCEDURE_THREADS));
    final boolean abortOnCorruption = conf.getBoolean(MasterProcedureConstants.EXECUTOR_ABORT_ON_CORRUPTION, MasterProcedureConstants.DEFAULT_EXECUTOR_ABORT_ON_CORRUPTION);
    procedureStore.start(numThreads);
    // Just initialize it but do not start the workers, we will start the workers later by calling
    // startProcedureExecutor. See the javadoc for finishActiveMasterInitialization for more
    // details.
    procedureExecutor.init(numThreads, abortOnCorruption);
    if (!procEnv.getRemoteDispatcher().start()) {
        throw new HBaseIOException("Failed start of remote dispatcher");
    }
}
Also used : HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionProcedureStore(org.apache.hadoop.hbase.procedure2.store.region.RegionProcedureStore) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterProcedureScheduler(org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler) ProcedureStoreListener(org.apache.hadoop.hbase.procedure2.store.ProcedureStore.ProcedureStoreListener) RSGroupAdminEndpoint(org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint)

Example 29 with HBaseIOException

use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.

the class AsyncNonMetaRegionLocator method onScanNext.

// return whether we should stop the scan
private boolean onScanNext(TableName tableName, LocateRequest req, Result result) {
    RegionLocations locs = CatalogFamilyFormat.getRegionLocations(result);
    if (LOG.isDebugEnabled()) {
        LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName, Bytes.toStringBinary(req.row), req.locateType, locs);
    }
    // remove HRegionLocation with null location, i.e, getServerName returns null.
    if (locs != null) {
        locs = locs.removeElementsWithNullLocation();
    }
    // let's fail the request.
    if (locs == null || locs.getDefaultRegionLocation() == null) {
        complete(tableName, req, null, new HBaseIOException(String.format("No location found for '%s', row='%s', locateType=%s", tableName, Bytes.toStringBinary(req.row), req.locateType)));
        return true;
    }
    HRegionLocation loc = locs.getDefaultRegionLocation();
    RegionInfo info = loc.getRegion();
    if (info == null) {
        complete(tableName, req, null, new HBaseIOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s", tableName, Bytes.toStringBinary(req.row), req.locateType)));
        return true;
    }
    if (info.isSplitParent()) {
        return false;
    }
    complete(tableName, req, locs, null);
    return true;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) AsyncRegionLocatorHelper.createRegionLocations(org.apache.hadoop.hbase.client.AsyncRegionLocatorHelper.createRegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 30 with HBaseIOException

use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.

the class FavoredNodeAssignmentHelper method generateFavoredNodes.

/*
   * Generate favored nodes for a region.
   *
   * Choose a random server as primary and then choose secondary and tertiary FN so its spread
   * across two racks.
   */
public List<ServerName> generateFavoredNodes(RegionInfo hri) throws IOException {
    List<ServerName> favoredNodesForRegion = new ArrayList<>(FAVORED_NODES_NUM);
    ServerName primary = servers.get(ThreadLocalRandom.current().nextInt(servers.size()));
    favoredNodesForRegion.add(ServerName.valueOf(primary.getAddress(), ServerName.NON_STARTCODE));
    Map<RegionInfo, ServerName> primaryRSMap = new HashMap<>(1);
    primaryRSMap.put(hri, primary);
    Map<RegionInfo, ServerName[]> secondaryAndTertiaryRSMap = placeSecondaryAndTertiaryRS(primaryRSMap);
    ServerName[] secondaryAndTertiaryNodes = secondaryAndTertiaryRSMap.get(hri);
    if (secondaryAndTertiaryNodes != null && secondaryAndTertiaryNodes.length == 2) {
        for (ServerName sn : secondaryAndTertiaryNodes) {
            favoredNodesForRegion.add(ServerName.valueOf(sn.getAddress(), ServerName.NON_STARTCODE));
        }
        return favoredNodesForRegion;
    } else {
        throw new HBaseIOException("Unable to generate secondary and tertiary favored nodes.");
    }
}
Also used : HashMap(java.util.HashMap) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Aggregations

HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)36 IOException (java.io.IOException)19 ServerName (org.apache.hadoop.hbase.ServerName)17 ArrayList (java.util.ArrayList)13 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)13 List (java.util.List)8 HashMap (java.util.HashMap)7 InterruptedIOException (java.io.InterruptedIOException)5 Map (java.util.Map)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)5 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)5 Test (org.junit.Test)5 TreeMap (java.util.TreeMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 ExecutionException (java.util.concurrent.ExecutionException)3 RegionLocations (org.apache.hadoop.hbase.RegionLocations)3 TableName (org.apache.hadoop.hbase.TableName)3 FavoredNodeAssignmentHelper (org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper)3 RSGroupAdminEndpoint (org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint)3