Shockang commented on a change in pull request #33101:
URL: https://github.com/apache/spark/pull/33101#discussion_r659423768



##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -310,15 +306,17 @@ private[spark] object Utils extends Logging {
     while (dir == null) {
       attempts += 1
       if (attempts > maxAttempts) {
-        throw new IOException("Failed to create a temp directory (under " + 
root + ") after " +
-          maxAttempts + " attempts!")
+        throw new IOException(s"Failed to create a temp directory (under 
$root) after " +
+           s"$maxAttempts attempts!")
       }
       try {
         dir = new File(root, namePrefix + "-" + UUID.randomUUID.toString)
-        if (dir.exists() || !dir.mkdirs()) {
-          dir = null
-        }
-      } catch { case e: SecurityException => dir = null; }
+        // SPARK-35907 Instead of File#mkdirs, Files#createDirectories is 
expected.
+        Files.createDirectories(dir.toPath)
+      } catch { case e: Exception =>

Review comment:
       > nit. This could cause a regression because catching `Exception` can 
hide lots of things. Is there a way to narrow down this?
   
   Ignoring the exception directly will cause users to be confused about the 
creation failure, and Files#createDirectories will throw more meaningful 
exception information, but SecurityException  is not enough to meet the needs.I 
will take a more appropriate approach.

##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -285,16 +285,12 @@ private[spark] object Utils extends Logging {
    */
   def createDirectory(dir: File): Boolean = {
     try {
-      // This sporadically fails - not sure why ... !dir.exists() && 
!dir.mkdirs()
-      // So attempting to create and then check if directory was created or 
not.
-      dir.mkdirs()
-      if ( !dir.exists() || !dir.isDirectory) {
-        logError(s"Failed to create directory " + dir)
-      }
-      dir.isDirectory
+      // SPARK-35907 Instead of File#mkdirs, Files#createDirectories is 
expected.

Review comment:
       > Shall we remove this line? Since `mkdirs` is removed already, we may 
look weird after this PR.
   
   OK, I will provide more appropriate comments.

##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -285,16 +285,12 @@ private[spark] object Utils extends Logging {
    */
   def createDirectory(dir: File): Boolean = {
     try {
-      // This sporadically fails - not sure why ... !dir.exists() && 
!dir.mkdirs()
-      // So attempting to create and then check if directory was created or 
not.
-      dir.mkdirs()
-      if ( !dir.exists() || !dir.isDirectory) {
-        logError(s"Failed to create directory " + dir)
-      }
-      dir.isDirectory
+      // SPARK-35907 Instead of File#mkdirs, Files#createDirectories is 
expected.
+      Files.createDirectories(dir.toPath)
+      true
     } catch {
       case e: Exception =>
-        logError(s"Failed to create directory " + dir, e)
+        logError(s"Failed to create directory $dir", e)

Review comment:
       > This is reasonable. But, in general, I discourage adding irrelevant 
changes like this. To have a minimal and coherent PR content is the best, 
@Shockang .
   
   What you said is right, let me restore it, it makes sense to minimize the 
modification points.




-- 
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