gianm commented on a change in pull request #11879:
URL: https://github.com/apache/druid/pull/11879#discussion_r743970973



##########
File path: core/src/main/java/org/apache/druid/java/util/common/FileUtils.java
##########
@@ -379,6 +379,27 @@ public static File createTempDir(@Nullable final String 
prefix)
     }
   }
 
+  /**
+   * Create "directory" and all intermediate directories as needed. If the 
directory is successfully created, or already
+   * exists, returns quietly. Otherwise, throws an IOException.
+   *
+   * Simpler to use than {@link File#mkdirs()}, and more reliable since it is 
safe from races where two threads try

Review comment:
       For the potential race, I don't know if we have this issue today. I did 
notice it when goofing off with some new code in a branch, but I'm not sure if 
any production code today has a problem here.
   
   I still thought the patch was a good idea for two reasons:
   
   1. There are a bunch of places that don't check the return value of 
`File.mkdirs()`, and switching to this new method would make them fail faster 
if the directory cannot be created, which I thought would generally be good. 
(Otherwise, the errors will happen later and more indirectly, perhaps being 
harder to debug.)
   2. The fix to the race is really simple, so I didn't see why _not_ include 
it. (The fix is to do `mkdirs() || isDirectory()` instead of just `mkdirs()`).
   
   As to `org.apache.commons.io.FileUtils.forceMkdir()`, I didn't notice that 
method until now, so thanks for pointing it out. It looks almost identical to 
the one in this PR, except it skips the initial `isDirectory()` check. But it's 
still race-safe because it does have the final `isDirectory()` check. And 
actually, I think the initial `isDirectory()` check is pointless anyway, since 
`mkdirs()` will exit `false()` quickly if the directory already exists. So I 
just pushed a new commit that removes it.




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