private Disk getBestDiskCandidate(List<DataNode> dataNodes, Set<DataNode> dataNodesUsed, long replicaCapacityInBytes,
      boolean rackAware, int numChoices) {
    Set<String> rackIdsUsed = new HashSet<>();
    if (rackAware) {
      for (DataNode dataNode : dataNodesUsed) {
        rackIdsUsed.add(dataNode.getRackId());
      }
    }
    int numFound = 0;
    int selectionBound = dataNodes.size();
    Random randomGen = new Random();
    Disk bestDisk = null;
    while ((selectionBound > 0) && (numFound < numChoices)) {
      int selectionIndex = randomGen.nextInt(selectionBound);
      DataNode candidate = dataNodes.get(selectionIndex);
      if (!dataNodesUsed.contains(candidate) && !rackIdsUsed.contains(candidate.getRackId())) {
        Disk diskCandidate = getDiskWithMostUnallocatedRawCapacity(candidate, replicaCapacityInBytes);
        if (diskCandidate != null) {
          if ((bestDisk == null) || (getUnallocatedRawCapacityInBytes(diskCandidate.getDataNode())
              >= getUnallocatedRawCapacityInBytes(bestDisk.getDataNode()))) {
            bestDisk = diskCandidate;
          }
          numFound++;
        }
      }
      selectionBound--;
      Collections.swap(dataNodes, selectionIndex, selectionBound);
    }
    return bestDisk;
  }
Get a sampling of {@code numChoices} random disks from a list of {@link DataNode}s and choose the
{@link Disk} on the {@link DataNode} with the most free space.
NOTE 1: This method will change the ordering of the nodes in {@code dataNodes}
NOTE 2: This method can return null, if a disk with enough free space could not be found.

@param dataNodes the list of {@link DataNode}s to sample from
@param dataNodesUsed the set of {@link DataNode}s to exclude from the sample
@param replicaCapacityInBytes the minimum amount of free space that a disk in the sample should have
@param rackAware if {@code true}, only return disks in nodes that do not share racks with the nodes
                 in {@code dataNodesUsed}
@param numChoices how many disks in the sample to choose between
@return The {@link Disk} on the {@link DataNode} in the sample with the most free space, or {@code null } if a disk
        with enough free space could not be found.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/StaticClusterManager.java