-
Notifications
You must be signed in to change notification settings - Fork 3k
AWS: Add check to create staging directory if not exists for S3OutputStream #3175
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
Changes from all commits
30f52b1
05de05e
0ef2b28
523b701
cca5080
4cb6a0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ private void newStream() throws IOException { | |
| stream.close(); | ||
| } | ||
|
|
||
| createStagingDirectoryIfNotExists(); | ||
| currentStagingFile = File.createTempFile("s3fileio-", ".tmp", stagingDirectory); | ||
| currentStagingFile.deleteOnExit(); | ||
| stagingFiles.add(currentStagingFile); | ||
|
|
@@ -328,6 +329,26 @@ private static InputStream uncheckedInputStream(File file) { | |
| } | ||
| } | ||
|
|
||
| private void createStagingDirectoryIfNotExists() throws IOException, SecurityException { | ||
| if (!stagingDirectory.exists()) { | ||
| LOG.info("Staging directory does not exist, trying to create one: {}", | ||
| stagingDirectory.getAbsolutePath()); | ||
| boolean createdStagingDirectory = stagingDirectory.mkdirs(); | ||
| if (createdStagingDirectory) { | ||
| LOG.info("Successfully created staging directory: {}", stagingDirectory.getAbsolutePath()); | ||
| } else { | ||
| if (stagingDirectory.exists()) { | ||
| LOG.info("Successfully created staging directory by another process: {}", | ||
| stagingDirectory.getAbsolutePath()); | ||
| } else { | ||
| throw new IOException( | ||
| "Failed to create staging directory due to some unknown reason: " + stagingDirectory | ||
| .getAbsolutePath()); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else, add a LOG saying "Staging directory {} creation failed, or it is created by another process"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, we can do better than just logging. When creation fails, we can check directory existence again, if it exists then it's created by another process, otherwise it's still an issue, and we can throw an IOException with error message indicating staging directory creation fails for some unknown reasons.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I have made the changes accordingly. |
||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("checkstyle:NoFinalizer") | ||
| @Override | ||
| protected void finalize() throws Throwable { | ||
|
|
||
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.
add a LOG saying something like "staging directoy {} not exist, trying to create one"
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.
Added the logger.