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);
}
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();
}
Aggregations