// Repeatedly add DataNode copies equal to the number of their weights
private void buildWeightList(
      List<TDataNodeInfo> onlineDataNodes, List<TRegionReplicaSet> allocatedRegions) {
    // TODO: The remaining disk capacity of DataNode can also be calculated into the weightList
    int maximumRegionNum = 0;
    Map<TDataNodeLocation, Integer> countMap = new HashMap<>();
    for (TDataNodeInfo dataNodeInfo : onlineDataNodes) {
      maxId = Math.max(maxId, dataNodeInfo.getLocation().getDataNodeId());
      countMap.put(dataNodeInfo.getLocation(), 0);
    }
    for (TRegionReplicaSet regionReplicaSet : allocatedRegions) {
      for (TDataNodeLocation dataNodeLocation : regionReplicaSet.getDataNodeLocations()) {
        countMap.computeIfPresent(dataNodeLocation, (dataNode, count) -> (count + 1));
        maximumRegionNum = Math.max(maximumRegionNum, countMap.get(dataNodeLocation));
      }
    }
    weightList = new ArrayList<>();
    for (Map.Entry<TDataNodeLocation, Integer> countEntry : countMap.entrySet()) {
      int weight = maximumRegionNum - countEntry.getValue() + 1;
      // Repeatedly add DataNode copies equal to the number of their weights
      for (int repeat = 0; repeat < weight; repeat++) {
        weightList.add(countEntry.getKey().deepCopy());
      }
    }
  }
for (Map.Entry<TDataNodeLocation, Integer> countEntry : countMap.entrySet()) {
int weight = maximumRegionNum - countEntry.getValue() + 1;
// Repeatedly add DataNode copies equal to the number of their weights
for (int repeat = 0; repeat < weight; repeat++) {
weightList.add(countEntry.getKey().deepCopy());
}
for (TRegionReplicaSet regionReplicaSet : allocatedRegions) {
for (TDataNodeLocation dataNodeLocation : regionReplicaSet.getDataNodeLocations()) {
countMap.computeIfPresent(dataNodeLocation, (dataNode, count) -> (count + 1));
maximumRegionNum = Math.max(maximumRegionNum, countMap.get(dataNodeLocation));
}
}
weightList = new ArrayList<>();
for (Map.Entry<TDataNodeLocation, Integer> countEntry : countMap.entrySet()) {
int weight = maximumRegionNum - countEntry.getValue() + 1;
// Repeatedly add DataNode copies equal to the number of their weights
for (int repeat = 0; repeat < weight; repeat++) {
weightList.add(countEntry.getKey().deepCopy());
}
}
}
private void buildWeightList(
List<TDataNodeInfo> onlineDataNodes, List<TRegionReplicaSet> allocatedRegions) {
// TODO: The remaining disk capacity of DataNode can also be calculated into the weightList
int maximumRegionNum = 0;
Map<TDataNodeLocation, Integer> countMap = new HashMap<>();
for (TDataNodeInfo dataNodeInfo : onlineDataNodes) {
maxId = Math.max(maxId, dataNodeInfo.getLocation().getDataNodeId());
countMap.put(dataNodeInfo.getLocation(), 0);
}
for (TRegionReplicaSet regionReplicaSet : allocatedRegions) {
for (TDataNodeLocation dataNodeLocation : regionReplicaSet.getDataNodeLocations()) {
countMap.computeIfPresent(dataNodeLocation, (dataNode, count) -> (count + 1));
maximumRegionNum = Math.max(maximumRegionNum, countMap.get(dataNodeLocation));
}
}
weightList = new ArrayList<>();
for (Map.Entry<TDataNodeLocation, Integer> countEntry : countMap.entrySet()) {
int weight = maximumRegionNum - countEntry.getValue() + 1;
// Repeatedly add DataNode copies equal to the number of their weights
for (int repeat = 0; repeat < weight; repeat++) {
weightList.add(countEntry.getKey().deepCopy());
}
}
}