-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-35907][CORE] Instead of File#mkdirs, Files#createDirectories is expected. #33101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d1c2ce1
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang c66fa90
Merge branch 'master' into SPARK-35907
Shockang 71bd12f
scalastyle
Shockang d5ef110
scalastyle:File line length exceeds 100 characters
Shockang 30b3515
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang 9e3511b
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang 000920d
Merge branch 'SPARK-35907' of github.com:Shockang/spark into SPARK-35907
Shockang 411f69d
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang 435d125
Optimize comments and exception handling
Shockang 1890ca9
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang b367ea6
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang 983bb36
[SPARK-35907] Instead of File#mkdirs, Files#createDirectories is expe…
Shockang a958a5e
Take the comment provided by Ngone51
Shockang 6d123ba
Take the comment provided by Ngone51
Shockang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ngone51 I understand you requested this check to be brought back in your previous comment, but it doesn't seem right to me. Based on the Javadoc for createDirectories, the contract is that the directory will be created successfully, or an exception will be thrown. Keeping the
exists/isDirectorychecks after is redundant. If we're worried about a JDK bug as described here, why do we trust the implementation ofFile#exists()andFile#isDirectory()but notFiles.createDirectories()? IMO the whole point of switching fromFileto the NIO APIs is that they have more sensible semantics and so we don't need to jump through hoops like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find such a contract there, but only " Unlike the createDirectory method, an exception is not thrown if the directory could not be created because it already exists."...
It's not about which method we should trust but which way is safer to go. If there's such a contract as you mentioned, I agree we don't need the check. Otherwise, I think it's safer to follow the original way to avoid suffering from the old issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word "contract" is not used, but I think that is rarely the case in method descriptions. For example none of the methods on
Datasetexplicitly state contracts or guarantees, but we are expected to assume that the method will do what it says it does, and indicate an error condition using an exception otherwise. My impression here is that the weird semantics ofFile#mkdirs()are translating into FUD about the potential shortcomings ofFiles.createDirectories()and that, if the method were taken without that historical context, we wouldn't be worrying about it.This all being said, it's only three lines of code extra, so of course it is no big detriment to be on the safe side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you in terms of safety and minimizing modification points.Do you have any questions with my current code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shockang Could you leave a comment above the check to give the historical context, e.g.,
"The check was required by File#mkdirs() because it could sporadically fail silently. After switching to Files.createDirectories(), ideally, there should no longer be silent fails. But the check is kept for the safety concern. We can remove the check when we're sure that Files.createDirectories() would never fail silently."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just wanted to explain my viewpoint. Current code is fine. I agree with @Ngone51 that a comment is helpful to explain the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment looks perfect. Thank you very much for your comments.