code: private boolean getGoodNode(Set<Node> candidateNodes,
                                boolean considerLoad,
                                long blockSize,
                                List<DatanodeDescriptor> results) {
      List<DatanodeDescriptor> sorted = new ArrayList<DatanodeDescriptor>();
      for (Node n : candidateNodes) {
        sorted.add((DatanodeDescriptor)n);
      }
      final long blocksize = blockSize;
      Collections.sort(sorted, new Comparator<DatanodeDescriptor>() {
        public int compare(DatanodeDescriptor n1, DatanodeDescriptor n2) {
          long ret = (n2.getRemaining() - (n2.getBlocksScheduled() * blocksize)) -
                     (n1.getRemaining() - (n1.getBlocksScheduled() * blocksize));
          return ret == 0 ? 0 : (ret > 0) ? 1 : -1;
        }
      });
      // Also, add some randomness. We are doing so because it seems
      // that if there are many copies scheduled at the same time, namenode
      // does not have the uptodate information. So, we need to add some
      // randomness so that there is not a lot of copies targeted to
      // the same node, which will overload the hosts and may lead to
      // timeouts.
      int count = sorted.size() / 2;
      Collections.shuffle(sorted.subList(0, count));
      for (DatanodeDescriptor n : sorted) {
        if (this.isGoodTarget((DatanodeDescriptor)n,
                              blocksize,
                              1, // MaxTargerPerLoc (per rack)
                              considerLoad,
                              results)) {
          results.add((DatanodeDescriptor)n);
          return true;
        }
      }
      return false;
    }
docs: Helper function to find a good node. Returns true if found.