code: public DatanodeDescriptor chooseReplicaToDelete(FSInodeInfo inode,
        Block block, short replicationFactor,
        Collection<DatanodeDescriptor> first,
        Collection<DatanodeDescriptor> second) {
  
      List<DatanodeDescriptor> nodes = new ArrayList<DatanodeDescriptor>();
  
      if (first != null) {
        nodes.addAll(first);
      }
      if (second != null) {
        nodes.addAll(second);
      }
  
      DatanodeDescriptor[] best = findBest(nodes);
  
      boolean saved_two_racks = false;
  
      if (best[0] != null && best[1] != null) {
        saved_two_racks = true;
      }
  
      for (DatanodeDescriptor n : nodes) {
        if (saved_two_racks &&
            !n.equals(best[0]) && !n.equals(best[1]) && !n.equals(best[2])) {
          return n;
        }
  
        if (!saved_two_racks &&
            (
                (best[0] != null && // different from best[0]'s rack
                    !best[0].getNetworkLocation().equals(n.getNetworkLocation()))
  
                    ||
  
                (best[1] != null && // different from best[1]'s rack
                    !best[1].getNetworkLocation().equals(n.getNetworkLocation()))
  
            ) ) {
          saved_two_racks = true; // just skipped (saved) one machine
                                  // in a different rack
        }
      }
  
      return super.chooseReplicaToDelete(inode, block, replicationFactor,
                                                                  first, second);
    }
docs: {@inheritDoc}