protected final long getMaxCost(BalancerClusterState cluster) {
    // max cost is the case where every region replica is hosted together regardless of host
    Int2IntCounterMap colocatedReplicaCounts =
      new Int2IntCounterMap(cluster.numRegions, Hashing.DEFAULT_LOAD_FACTOR, 0);
    for (int i = 0; i < cluster.regionIndexToPrimaryIndex.length; i++) {
      colocatedReplicaCounts.getAndIncrement(cluster.regionIndexToPrimaryIndex[i]);
    }
    // compute numReplicas from the sorted array
    return costPerGroup(colocatedReplicaCounts);
  }
A cost function for region replicas. We give a high cost for hosting replicas of the same region
in the same server, host or rack. We do not prevent the case though, since if numReplicas >
numRegionServers, we still want to keep the replica open.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionReplicaGroupingCostFunction.java