code: private boolean getGoodNode(
        HashMap<String, HashSet<Node>> candidateNodesByRacks,
        boolean considerLoad,
        long blockSize,
        List<DatanodeDescriptor> results) {
      List<Map.Entry<String, HashSet<Node>>> sorted =
        new ArrayList<Map.Entry<String, HashSet<Node>>>();
      for (Map.Entry<String, HashSet<Node>> entry :
             candidateNodesByRacks.entrySet()) {
        sorted.add(entry);
      }
      Collections.sort(sorted, new RackComparator(blockSize));
      int count = sorted.size() / 4;
      Collections.shuffle(sorted.subList(0, count));
      for (Map.Entry<String, HashSet<Node>> e : sorted) {
        if (getGoodNode(e.getValue(), considerLoad, blockSize, results)) {
          return true;
        }
      }
      return false;
    }
docs: Helper function to choose less occupied racks first.