private ServerName[] multiRackCase(ServerName primaryRS, String primaryRack) throws IOException {

    List<ServerName> favoredNodes = Lists.newArrayList(primaryRS);
    // Create the secondary and tertiary pair
    ServerName secondaryRS = generateMissingFavoredNodeMultiRack(favoredNodes);
    favoredNodes.add(secondaryRS);
    String secondaryRack = getRackOfServer(secondaryRS);

    ServerName tertiaryRS;
    if (primaryRack.equals(secondaryRack)) {
      tertiaryRS = generateMissingFavoredNode(favoredNodes);
    } else {
      // Try to place tertiary in secondary RS rack else place on primary rack.
      tertiaryRS = getOneRandomServer(secondaryRack, Sets.newHashSet(secondaryRS));
      if (tertiaryRS == null) {
        tertiaryRS = getOneRandomServer(primaryRack, Sets.newHashSet(primaryRS));
      }
      // We couldn't find anything in secondary rack, get any FN
      if (tertiaryRS == null) {
        tertiaryRS = generateMissingFavoredNode(Lists.newArrayList(primaryRS, secondaryRS));
      }
    }
    return new ServerName[] { secondaryRS, tertiaryRS };
  }
Place secondary and tertiary nodes in a multi rack case. If there are only two racks, then we
try the place the secondary and tertiary on different rack than primary. But if the other rack
has only one region server, then we place primary and tertiary on one rack and secondary on
another. The aim is two distribute the three favored nodes on >= 2 racks. TODO: see how we can
use generateMissingFavoredNodeMultiRack API here
@param primaryRS   The primary favored node.
@param primaryRack The rack of the primary favored node.
@return Array containing secondary and tertiary favored nodes.
@throws IOException Signals that an I/O exception has occurred.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java