@Test public void testPlacePrimaryRSAsRoundRobin() { primaryRSPlacement(6, null, 10, 10, 10); primaryRSPlacement(600, null, 10, 10, 10); }
void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) { List<String> rackList = new ArrayList<String>(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); int serverIndex = firstServerIndex; for (HRegionInfo regionInfo : regions) { List<ServerName> currentServerList; String rackName; while (true) { rackName = rackList.get(rackIndex); numIterations++; currentServerList = rackToRegionServerMap.get(rackName); if (serverIndex >= currentServerList.size()) { if (numIterations % rackList.size() == 0) { if (++serverIndex >= maxRackSize) serverIndex = 0; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } else break; } ServerName currentServer = currentServerList.get(serverIndex); primaryRSMap.put(regionInfo, currentServer); List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer); if (regionsForServer == null) { regionsForServer = new ArrayList<HRegionInfo>(); assignmentMap.put(currentServer, regionsForServer); } regionsForServer.add(regionInfo); if (numIterations % rackList.size() == 0) { ++serverIndex; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } }
FavoredNodeAssignmentHelper { void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) { List<String> rackList = new ArrayList<String>(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); int serverIndex = firstServerIndex; for (HRegionInfo regionInfo : regions) { List<ServerName> currentServerList; String rackName; while (true) { rackName = rackList.get(rackIndex); numIterations++; currentServerList = rackToRegionServerMap.get(rackName); if (serverIndex >= currentServerList.size()) { if (numIterations % rackList.size() == 0) { if (++serverIndex >= maxRackSize) serverIndex = 0; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } else break; } ServerName currentServer = currentServerList.get(serverIndex); primaryRSMap.put(regionInfo, currentServer); List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer); if (regionsForServer == null) { regionsForServer = new ArrayList<HRegionInfo>(); assignmentMap.put(currentServer, regionsForServer); } regionsForServer.add(regionInfo); if (numIterations % rackList.size() == 0) { ++serverIndex; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } } }
FavoredNodeAssignmentHelper { void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) { List<String> rackList = new ArrayList<String>(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); int serverIndex = firstServerIndex; for (HRegionInfo regionInfo : regions) { List<ServerName> currentServerList; String rackName; while (true) { rackName = rackList.get(rackIndex); numIterations++; currentServerList = rackToRegionServerMap.get(rackName); if (serverIndex >= currentServerList.size()) { if (numIterations % rackList.size() == 0) { if (++serverIndex >= maxRackSize) serverIndex = 0; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } else break; } ServerName currentServer = currentServerList.get(serverIndex); primaryRSMap.put(regionInfo, currentServer); List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer); if (regionsForServer == null) { regionsForServer = new ArrayList<HRegionInfo>(); assignmentMap.put(currentServer, regionsForServer); } regionsForServer.add(regionInfo); if (numIterations % rackList.size() == 0) { ++serverIndex; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } } FavoredNodeAssignmentHelper(final List<ServerName> servers, Configuration conf);  FavoredNodeAssignmentHelper(final List<ServerName> servers,
      final RackManager rackManager); }
FavoredNodeAssignmentHelper { void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) { List<String> rackList = new ArrayList<String>(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); int serverIndex = firstServerIndex; for (HRegionInfo regionInfo : regions) { List<ServerName> currentServerList; String rackName; while (true) { rackName = rackList.get(rackIndex); numIterations++; currentServerList = rackToRegionServerMap.get(rackName); if (serverIndex >= currentServerList.size()) { if (numIterations % rackList.size() == 0) { if (++serverIndex >= maxRackSize) serverIndex = 0; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } else break; } ServerName currentServer = currentServerList.get(serverIndex); primaryRSMap.put(regionInfo, currentServer); List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer); if (regionsForServer == null) { regionsForServer = new ArrayList<HRegionInfo>(); assignmentMap.put(currentServer, regionsForServer); } regionsForServer.add(regionInfo); if (numIterations % rackList.size() == 0) { ++serverIndex; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } } FavoredNodeAssignmentHelper(final List<ServerName> servers, Configuration conf);  FavoredNodeAssignmentHelper(final List<ServerName> servers,
      final RackManager rackManager); static void updateMetaWithFavoredNodesInfo(
      Map<HRegionInfo, List<ServerName>> regionToFavoredNodes,
      CatalogTracker catalogTracker); static void updateMetaWithFavoredNodesInfo(
      Map<HRegionInfo, List<ServerName>> regionToFavoredNodes,
      Configuration conf); static ServerName[] getFavoredNodesList(byte[] favoredNodes); static byte[] getFavoredNodes(List<ServerName> serverAddrList); Map<HRegionInfo, ServerName[]> placeSecondaryAndTertiaryWithRestrictions(
      Map<HRegionInfo, ServerName> primaryRSMap); void initialize(); static String getFavoredNodesAsString(List<ServerName> nodes); }
FavoredNodeAssignmentHelper { void placePrimaryRSAsRoundRobin(Map<ServerName, List<HRegionInfo>> assignmentMap, Map<HRegionInfo, ServerName> primaryRSMap, List<HRegionInfo> regions) { List<String> rackList = new ArrayList<String>(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); int serverIndex = firstServerIndex; for (HRegionInfo regionInfo : regions) { List<ServerName> currentServerList; String rackName; while (true) { rackName = rackList.get(rackIndex); numIterations++; currentServerList = rackToRegionServerMap.get(rackName); if (serverIndex >= currentServerList.size()) { if (numIterations % rackList.size() == 0) { if (++serverIndex >= maxRackSize) serverIndex = 0; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } else break; } ServerName currentServer = currentServerList.get(serverIndex); primaryRSMap.put(regionInfo, currentServer); List<HRegionInfo> regionsForServer = assignmentMap.get(currentServer); if (regionsForServer == null) { regionsForServer = new ArrayList<HRegionInfo>(); assignmentMap.put(currentServer, regionsForServer); } regionsForServer.add(regionInfo); if (numIterations % rackList.size() == 0) { ++serverIndex; } if ((++rackIndex) >= rackList.size()) { rackIndex = 0; } } } FavoredNodeAssignmentHelper(final List<ServerName> servers, Configuration conf);  FavoredNodeAssignmentHelper(final List<ServerName> servers,
      final RackManager rackManager); static void updateMetaWithFavoredNodesInfo(
      Map<HRegionInfo, List<ServerName>> regionToFavoredNodes,
      CatalogTracker catalogTracker); static void updateMetaWithFavoredNodesInfo(
      Map<HRegionInfo, List<ServerName>> regionToFavoredNodes,
      Configuration conf); static ServerName[] getFavoredNodesList(byte[] favoredNodes); static byte[] getFavoredNodes(List<ServerName> serverAddrList); Map<HRegionInfo, ServerName[]> placeSecondaryAndTertiaryWithRestrictions(
      Map<HRegionInfo, ServerName> primaryRSMap); void initialize(); static String getFavoredNodesAsString(List<ServerName> nodes); static final byte [] FAVOREDNODES_QUALIFIER; final static short FAVORED_NODES_NUM; }