@Test public void testImmediateAssignment() throws Exception { List<ServerName> tmp = getListOfServerNames(randomServers(1, 0)); tmp.add(master); ServerName sn = loadBalancer.randomAssignment(HRegionInfo.FIRST_META_REGIONINFO, tmp); assertEquals(master, sn); HRegionInfo hri = randomRegions(1, -1).get(0); sn = loadBalancer.randomAssignment(hri, tmp); assertNotEquals(master, sn); tmp = new ArrayList<ServerName>(); tmp.add(master); sn = loadBalancer.randomAssignment(hri, tmp); assertEquals(master, sn); for (int[] mock : regionsAndServersMocks) { LOG.debug("testImmediateAssignment with " + mock[0] + " regions and " + mock[1] + " servers"); List<HRegionInfo> regions = randomRegions(mock[0]); List<ServerAndLoad> servers = randomServers(mock[1], 0); List<ServerName> list = getListOfServerNames(servers); Map<HRegionInfo, ServerName> assignments = loadBalancer.immediateAssignment(regions, list); assertImmediateAssignment(regions, list, assignments); returnRegions(regions); returnServers(list); } }
@Override public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers) { metricsBalancer.incrMiscInvocations(); if (servers == null || servers.isEmpty()) { LOG.warn("Wanted to do random assignment but no servers to assign to"); return null; } Map<HRegionInfo, ServerName> assignments = new TreeMap<HRegionInfo, ServerName>(); List<ServerName> backupMasters = normalizeServers(servers); for (HRegionInfo region : regions) { assignments.put(region, randomAssignment(region, servers, backupMasters)); } return assignments; }
BaseLoadBalancer implements LoadBalancer { @Override public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers) { metricsBalancer.incrMiscInvocations(); if (servers == null || servers.isEmpty()) { LOG.warn("Wanted to do random assignment but no servers to assign to"); return null; } Map<HRegionInfo, ServerName> assignments = new TreeMap<HRegionInfo, ServerName>(); List<ServerName> backupMasters = normalizeServers(servers); for (HRegionInfo region : regions) { assignments.put(region, randomAssignment(region, servers, backupMasters)); } return assignments; } }
BaseLoadBalancer implements LoadBalancer { @Override public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers) { metricsBalancer.incrMiscInvocations(); if (servers == null || servers.isEmpty()) { LOG.warn("Wanted to do random assignment but no servers to assign to"); return null; } Map<HRegionInfo, ServerName> assignments = new TreeMap<HRegionInfo, ServerName>(); List<ServerName> backupMasters = normalizeServers(servers); for (HRegionInfo region : regions) { assignments.put(region, randomAssignment(region, servers, backupMasters)); } return assignments; }  }
BaseLoadBalancer implements LoadBalancer { @Override public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers) { metricsBalancer.incrMiscInvocations(); if (servers == null || servers.isEmpty()) { LOG.warn("Wanted to do random assignment but no servers to assign to"); return null; } Map<HRegionInfo, ServerName> assignments = new TreeMap<HRegionInfo, ServerName>(); List<ServerName> backupMasters = normalizeServers(servers); for (HRegionInfo region : regions) { assignments.put(region, randomAssignment(region, servers, backupMasters)); } return assignments; }  @Override void setConf(Configuration conf); void excludeServer(ServerName serverName); Set<ServerName> getExcludedServers(); @Override Configuration getConf(); @Override void setClusterStatus(ClusterStatus st); @Override void setMasterServices(MasterServices masterServices); @Override Map<ServerName, List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions,
      List<ServerName> servers); @Override Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions,
      List<ServerName> servers); @Override ServerName randomAssignment(HRegionInfo regionInfo, List<ServerName> servers); @Override Map<ServerName, List<HRegionInfo>> retainAssignment(Map<HRegionInfo, ServerName> regions,
      List<ServerName> servers); @Override void initialize(); @Override void regionOnline(HRegionInfo regionInfo, ServerName sn); @Override void regionOffline(HRegionInfo regionInfo); @Override boolean isStopped(); @Override void stop(String why); }
BaseLoadBalancer implements LoadBalancer { @Override public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers) { metricsBalancer.incrMiscInvocations(); if (servers == null || servers.isEmpty()) { LOG.warn("Wanted to do random assignment but no servers to assign to"); return null; } Map<HRegionInfo, ServerName> assignments = new TreeMap<HRegionInfo, ServerName>(); List<ServerName> backupMasters = normalizeServers(servers); for (HRegionInfo region : regions) { assignments.put(region, randomAssignment(region, servers, backupMasters)); } return assignments; }  @Override void setConf(Configuration conf); void excludeServer(ServerName serverName); Set<ServerName> getExcludedServers(); @Override Configuration getConf(); @Override void setClusterStatus(ClusterStatus st); @Override void setMasterServices(MasterServices masterServices); @Override Map<ServerName, List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions,
      List<ServerName> servers); @Override Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions,
      List<ServerName> servers); @Override ServerName randomAssignment(HRegionInfo regionInfo, List<ServerName> servers); @Override Map<ServerName, List<HRegionInfo>> retainAssignment(Map<HRegionInfo, ServerName> regions,
      List<ServerName> servers); @Override void initialize(); @Override void regionOnline(HRegionInfo regionInfo, ServerName sn); @Override void regionOffline(HRegionInfo regionInfo); @Override boolean isStopped(); @Override void stop(String why); static final String BACKUP_MASTER_WEIGHT_KEY; static final int DEFAULT_BACKUP_MASTER_WEIGHT; }