@Override
  BalanceAction generate(BalancerClusterState cluster) {
    int rackIndex = pickRandomRack(cluster);
    if (cluster.numRacks <= 1 || rackIndex == -1) {
      return super.generate(cluster);
    }

    int regionIndex = selectCoHostedRegionPerGroup(cluster.colocatedReplicaCountsPerRack[rackIndex],
      cluster.regionsPerRack[rackIndex], cluster.regionIndexToPrimaryIndex);

    // if there are no pairs of region replicas co-hosted, default to random generator
    if (regionIndex == -1) {
      // default to randompicker
      return randomGenerator.generate(cluster);
    }

    int serverIndex = cluster.regionIndexToServerIndex[regionIndex];
    int toRackIndex = pickOtherRandomRack(cluster, rackIndex);

    int rand = ThreadLocalRandom.current().nextInt(cluster.serversPerRack[toRackIndex].length);
    int toServerIndex = cluster.serversPerRack[toRackIndex][rand];
    int toRegionIndex = pickRandomRegion(cluster, toServerIndex, 0.9f);
    return getAction(serverIndex, regionIndex, toServerIndex, toRegionIndex);
  }
Generates candidates which moves the replicas out of the rack for co-hosted region replicas in
the same rack
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionReplicaRackCandidateGenerator.java