sunchao commented on code in PR #46678:
URL: https://github.com/apache/spark/pull/46678#discussion_r1618208196


##########
core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala:
##########
@@ -218,12 +218,17 @@ private[spark] class SparkHadoopUtil extends Logging {
    * that file.
    */
   def listLeafStatuses(fs: FileSystem, baseStatus: FileStatus): 
Seq[FileStatus] = {
-    def recurse(status: FileStatus): Seq[FileStatus] = {
-      val (directories, leaves) = 
fs.listStatus(status.getPath).partition(_.isDirectory)
-      (leaves ++ directories.flatMap(f => listLeafStatuses(fs, 
f))).toImmutableArraySeq
+    val locatedFileStatusIt = fs.listFiles(baseStatus.getPath, true)
+    getFileStatusSeq(locatedFileStatusIt)
+  }
+
+  private[spark] def getFileStatusSeq(ri: RemoteIterator[LocatedFileStatus]): 
Seq[FileStatus] = {
+    val scalaIterator: Iterator[LocatedFileStatus] = new 
Iterator[LocatedFileStatus] {
+      override def hasNext: Boolean = ri.hasNext
+      override def next(): LocatedFileStatus = ri.next()
     }
 
-    if (baseStatus.isDirectory) recurse(baseStatus) else Seq(baseStatus)
+    scalaIterator.toSeq.map(identity)

Review Comment:
   Hmm why `.map(identity)`?



##########
core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala:
##########
@@ -219,8 +220,20 @@ private[spark] class SparkHadoopUtil extends Logging {
    */
   def listLeafStatuses(fs: FileSystem, baseStatus: FileStatus): 
Seq[FileStatus] = {

Review Comment:
   Hmm for HDFS at least `listFiles` needs to call 
[`listLocatedStatus`](https://github.com/apache/hadoop/blob/branch-3.4.0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L2387)
 which needs to fetch block locations and hence is more expensive than 
`listStatus`. 



##########
core/src/main/scala/org/apache/spark/util/Utils.scala:
##########
@@ -687,8 +687,22 @@ private[spark] object Utils
         in.close()
       }
     } else {
-      fs.listStatus(path).foreach { fileStatus =>
-        fetchHcfsFile(fileStatus.getPath(), dest, fs, conf, hadoopConf, 
fileOverwrite)
+      lazy val fsHasPathCapability = {

Review Comment:
   why `lazy val`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to