Search in sources :

Example 56 with ServerName

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

the class FavoredNodeAssignmentHelper method placePrimaryRSAsRoundRobin.

// Place the regions round-robin across the racks picking one server from each
// rack at a time. Start with a random rack, and a random server from every rack.
// If a rack doesn't have enough servers it will go to the next rack and so on.
// for choosing a primary.
// For example, if 4 racks (r1 .. r4) with 8 servers (s1..s8) each, one possible
// placement could be r2:s5, r3:s5, r4:s5, r1:s5, r2:s6, r3:s6..
// If there were fewer servers in one rack, say r3, which had 3 servers, one possible
// placement could be r2:s5, <skip-r3>, r4:s5, r1:s5, r2:s6, <skip-r3> ...
// The regions should be distributed proportionately to the racksizes
void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) {
    List<String> rackList = new ArrayList<>(rackToRegionServerMap.size());
    rackList.addAll(rackToRegionServerMap.keySet());
    int rackIndex = random.nextInt(rackList.size());
    int maxRackSize = 0;
    for (Map.Entry<String, List<ServerName>> r : rackToRegionServerMap.entrySet()) {
        if (r.getValue().size() > maxRackSize) {
            maxRackSize = r.getValue().size();
        }
    }
    int numIterations = 0;
    int firstServerIndex = random.nextInt(maxRackSize);
    // Initialize the current processing host index.
    int serverIndex = firstServerIndex;
    for (HRegionInfo regionInfo : regions) {
        List<ServerName> currentServerList;
        String rackName;
        while (true) {
            rackName = rackList.get(rackIndex);
            numIterations++;
            // Get the server list for the current rack
            currentServerList = rackToRegionServerMap.get(rackName);
            if (serverIndex >= currentServerList.size()) {
                //not enough machines in this rack
                if (numIterations % rackList.size() == 0) {
                    if (++serverIndex >= maxRackSize)
                        serverIndex = 0;
                }
                if ((++rackIndex) >= rackList.size()) {
                    // reset the rack index to 0
                    rackIndex = 0;
                }
            } else
                break;
        }
        // Get the current process region server
        ServerName currentServer = currentServerList.get(serverIndex);
        // Place the current region with the current primary region server
        primaryRSMap.put(regionInfo, currentServer);
        if (assignmentMap != null) {
            List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer);
            if (regionsForServer == null) {
                regionsForServer = new ArrayList<>();
                assignmentMap.put(currentServer, regionsForServer);
            }
            regionsForServer.add(regionInfo);
        }
        // Set the next processing index
        if (numIterations % rackList.size() == 0) {
            ++serverIndex;
        }
        if ((++rackIndex) >= rackList.size()) {
            // reset the rack index to 0
            rackIndex = 0;
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 57 with ServerName

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

the class FavoredNodeAssignmentHelper method singleRackCase.

private ServerName[] singleRackCase(HRegionInfo regionInfo, ServerName primaryRS, String primaryRack) throws IOException {
    // Single rack case: have to pick the secondary and tertiary
    // from the same rack
    List<ServerName> serverList = getServersFromRack(primaryRack);
    if ((serverList == null) || (serverList.size() <= 2)) {
        // on any server;
        return null;
    } else {
        // Randomly select two region servers from the server list and make sure
        // they are not overlap with the primary region server;
        Set<ServerName> serverSkipSet = new HashSet<>();
        serverSkipSet.add(primaryRS);
        // Place the secondary RS
        ServerName secondaryRS = getOneRandomServer(primaryRack, serverSkipSet);
        // Skip the secondary for the tertiary placement
        serverSkipSet.add(secondaryRS);
        ServerName tertiaryRS = getOneRandomServer(primaryRack, serverSkipSet);
        if (secondaryRS == null || tertiaryRS == null) {
            LOG.error("Cannot place the secondary, tertiary favored node for region " + regionInfo.getRegionNameAsString());
        }
        // Create the secondary and tertiary pair
        ServerName[] favoredNodes = new ServerName[2];
        favoredNodes[0] = secondaryRS;
        favoredNodes[1] = tertiaryRS;
        return favoredNodes;
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) HashSet(java.util.HashSet)

Example 58 with ServerName

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

the class FavoredNodeAssignmentHelper method generateMissingFavoredNodeSingleRack.

/*
   * Generate FN for a single rack scenario, don't generate from one of the excluded nodes. Helps
   * when we would like to find a replacement node.
   */
private ServerName generateMissingFavoredNodeSingleRack(List<ServerName> favoredNodes, List<ServerName> excludeNodes) throws IOException {
    ServerName newServer = null;
    Set<ServerName> excludeFNSet = Sets.newHashSet(favoredNodes);
    if (excludeNodes != null && excludeNodes.size() > 0) {
        excludeFNSet.addAll(excludeNodes);
    }
    if (favoredNodes.size() < FAVORED_NODES_NUM) {
        newServer = this.getOneRandomServer(this.uniqueRackList.get(0), excludeFNSet);
    }
    return newServer;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 59 with ServerName

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

the class FavoredNodeLoadBalancer method segregateRegionsAndAssignRegionsWithFavoredNodes.

private Pair<Map<ServerName, List<HRegionInfo>>, List<HRegionInfo>> segregateRegionsAndAssignRegionsWithFavoredNodes(List<HRegionInfo> regions, List<ServerName> availableServers) {
    Map<ServerName, List<HRegionInfo>> assignmentMapForFavoredNodes = new HashMap<>(regions.size() / 2);
    List<HRegionInfo> regionsWithNoFavoredNodes = new ArrayList<>(regions.size() / 2);
    for (HRegionInfo region : regions) {
        List<ServerName> favoredNodes = fnm.getFavoredNodes(region);
        ServerName primaryHost = null;
        ServerName secondaryHost = null;
        ServerName tertiaryHost = null;
        if (favoredNodes != null) {
            for (ServerName s : favoredNodes) {
                ServerName serverWithLegitStartCode = availableServersContains(availableServers, s);
                if (serverWithLegitStartCode != null) {
                    FavoredNodesPlan.Position position = FavoredNodesPlan.getFavoredServerPosition(favoredNodes, s);
                    if (Position.PRIMARY.equals(position)) {
                        primaryHost = serverWithLegitStartCode;
                    } else if (Position.SECONDARY.equals(position)) {
                        secondaryHost = serverWithLegitStartCode;
                    } else if (Position.TERTIARY.equals(position)) {
                        tertiaryHost = serverWithLegitStartCode;
                    }
                }
            }
            assignRegionToAvailableFavoredNode(assignmentMapForFavoredNodes, region, primaryHost, secondaryHost, tertiaryHost);
        }
        if (primaryHost == null && secondaryHost == null && tertiaryHost == null) {
            //all favored nodes unavailable
            regionsWithNoFavoredNodes.add(region);
        }
    }
    return new Pair<>(assignmentMapForFavoredNodes, regionsWithNoFavoredNodes);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Position(org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position) Pair(org.apache.hadoop.hbase.util.Pair)

Example 60 with ServerName

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

the class FavoredNodeLoadBalancer method getInheritedFNForDaughter.

private Set<ServerName> getInheritedFNForDaughter(FavoredNodeAssignmentHelper helper, List<ServerName> parentFavoredNodes, Position primary, Position secondary) throws IOException {
    Set<ServerName> daughterFN = Sets.newLinkedHashSet();
    if (parentFavoredNodes.size() >= primary.ordinal()) {
        daughterFN.add(parentFavoredNodes.get(primary.ordinal()));
    }
    if (parentFavoredNodes.size() >= secondary.ordinal()) {
        daughterFN.add(parentFavoredNodes.get(secondary.ordinal()));
    }
    while (daughterFN.size() < FavoredNodeAssignmentHelper.FAVORED_NODES_NUM) {
        ServerName newNode = helper.generateMissingFavoredNode(Lists.newArrayList(daughterFN));
        daughterFN.add(newNode);
    }
    return daughterFN;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22