Search in sources :

Example 1 with Position

use of org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position 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 2 with Position

use of org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position in project hbase by apache.

the class TestRegionPlacement method getNumRegionisOnPrimaryRS.

/**
   * Check whether regions are assigned to servers consistent with the explicit
   * hints that are persisted in the hbase:meta table.
   * Also keep track of the number of the regions are assigned to the
   * primary region server.
   * @return the number of regions are assigned to the primary region server
   * @throws IOException
   */
private int getNumRegionisOnPrimaryRS() throws IOException {
    final AtomicInteger regionOnPrimaryNum = new AtomicInteger(0);
    final AtomicInteger totalRegionNum = new AtomicInteger(0);
    LOG.info("The start of region placement verification");
    MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {

        public boolean visit(Result result) throws IOException {
            try {
                @SuppressWarnings("deprecation") HRegionInfo info = MetaTableAccessor.getHRegionInfo(result);
                if (info.getTable().getNamespaceAsString().equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) {
                    return true;
                }
                byte[] server = result.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
                byte[] favoredNodes = result.getValue(HConstants.CATALOG_FAMILY, FavoredNodeAssignmentHelper.FAVOREDNODES_QUALIFIER);
                // Add the favored nodes into assignment plan
                ServerName[] favoredServerList = FavoredNodeAssignmentHelper.getFavoredNodesList(favoredNodes);
                favoredNodesAssignmentPlan.put(info, favoredServerList);
                Position[] positions = Position.values();
                if (info != null) {
                    totalRegionNum.incrementAndGet();
                    if (server != null) {
                        ServerName serverName = ServerName.valueOf(Bytes.toString(server), -1);
                        if (favoredNodes != null) {
                            String placement = "[NOT FAVORED NODE]";
                            for (int i = 0; i < favoredServerList.length; i++) {
                                if (favoredServerList[i].equals(serverName)) {
                                    placement = positions[i].toString();
                                    if (i == Position.PRIMARY.ordinal()) {
                                        regionOnPrimaryNum.incrementAndGet();
                                    }
                                    break;
                                }
                            }
                            LOG.info(info.getRegionNameAsString() + " on " + serverName + " " + placement);
                        } else {
                            LOG.info(info.getRegionNameAsString() + " running on " + serverName + " but there is no favored region server");
                        }
                    } else {
                        LOG.info(info.getRegionNameAsString() + " not assigned to any server");
                    }
                }
                return true;
            } catch (RuntimeException e) {
                LOG.error("Result=" + result);
                throw e;
            }
        }
    };
    MetaTableAccessor.fullScanRegions(CONNECTION, visitor);
    LOG.info("There are " + regionOnPrimaryNum.intValue() + " out of " + totalRegionNum.intValue() + " regions running on the primary" + " region servers");
    return regionOnPrimaryNum.intValue();
}
Also used : Position(org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) Result(org.apache.hadoop.hbase.client.Result) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 ServerName (org.apache.hadoop.hbase.ServerName)2 Position (org.apache.hadoop.hbase.favored.FavoredNodesPlan.Position)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MetaTableAccessor (org.apache.hadoop.hbase.MetaTableAccessor)1 Result (org.apache.hadoop.hbase.client.Result)1 Pair (org.apache.hadoop.hbase.util.Pair)1