コード例 #1
0
ファイル: BalancerTestBase.java プロジェクト: dkhwangbo/hbase
  /**
   * This assumes the RegionPlan HSI instances are the same ones in the map, so actually no need to
   * even pass in the map, but I think it's clearer.
   *
   * @param list
   * @param plans
   * @return
   */
  protected List<ServerAndLoad> reconcile(
      List<ServerAndLoad> list,
      List<RegionPlan> plans,
      Map<ServerName, List<HRegionInfo>> servers) {
    List<ServerAndLoad> result = new ArrayList<ServerAndLoad>(list.size());

    Map<ServerName, ServerAndLoad> map = new HashMap<ServerName, ServerAndLoad>(list.size());
    for (ServerAndLoad sl : list) {
      map.put(sl.getServerName(), sl);
    }
    if (plans != null) {
      for (RegionPlan plan : plans) {
        ServerName source = plan.getSource();

        updateLoad(map, source, -1);
        ServerName destination = plan.getDestination();
        updateLoad(map, destination, +1);

        servers.get(source).remove(plan.getRegionInfo());
        servers.get(destination).add(plan.getRegionInfo());
      }
    }
    result.clear();
    result.addAll(map.values());
    return result;
  }
コード例 #2
0
ファイル: BalancerTestBase.java プロジェクト: dkhwangbo/hbase
 protected TreeMap<ServerName, List<HRegionInfo>> mockUniformClusterServers(int[] mockCluster) {
   int numServers = mockCluster.length;
   TreeMap<ServerName, List<HRegionInfo>> servers = new TreeMap<ServerName, List<HRegionInfo>>();
   for (int i = 0; i < numServers; i++) {
     int numRegions = mockCluster[i];
     ServerAndLoad sal = randomServer(0);
     List<HRegionInfo> regions = uniformRegions(numRegions);
     servers.put(sal.getServerName(), regions);
   }
   return servers;
 }