code: @Override
    protected DatanodeDescriptor chooseTarget(int numOfReplicas,
        DatanodeDescriptor writer, HashMap<Node, Node> excludedNodes,
        long blocksize, int maxNodesPerRack, List<DatanodeDescriptor> results,
        boolean newBlock) {
  
      if (numOfReplicas == 0 || clusterMap.getNumOfLeaves() == 0) {
        return writer;
      }
  
      int numOfResults = results.size();
      if (writer == null && !newBlock) {
        writer = results.get(0);
      }
  
      try {
        if (numOfResults == 0) {
          writer = chooseLocalNode(writer, excludedNodes, blocksize,
              maxNodesPerRack, results);
          if (--numOfReplicas == 0) {
            return writer;
          }
        }
        if (numOfResults <= 1) {
          // If we have a replication factor of 2, place both replicas on the
          // same rack.
          if (numOfReplicas == 1) {
            chooseLocalRack(results.get(0), excludedNodes, blocksize,
                maxNodesPerRack, results);
          } else {
            chooseFirstInRemoteRack(results.get(0), excludedNodes, blocksize,
                maxNodesPerRack, results);
          }
          if (--numOfReplicas == 0) {
            return writer;
          }
        }
        chooseRemainingReplicas(numOfReplicas, excludedNodes, blocksize,
              maxNodesPerRack, results);
      } catch (NotEnoughReplicasException e) {
        LOG.warn("Not able to place enough replicas, still in need of "
                + numOfReplicas);
      }
      return writer;
    }
docs: /* choose <i>numOfReplicas</i> from all data nodes