Skip to content
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

create parent dir also in parallel downloads, fixes #853 #854

Merged
merged 3 commits into from
Sep 26, 2016

Conversation

pbruski
Copy link
Contributor

@pbruski pbruski commented Sep 23, 2016

No description provided.

truncateDestinationFileIfNecessary();
} else {
if (!parentDirectory.mkdirs()) {
throw new AmazonClientException("Unable to create directory in the path" + parentDirectory.getAbsolutePath());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space or ": " needed in exception message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I copied this from ServiceUtils. I'll fix the other place too.

if (parentDirectory == null || parentDirectory.exists()) {
truncateDestinationFileIfNecessary();
} else {
if (!parentDirectory.mkdirs()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this just an else if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.

@@ -217,7 +224,7 @@ private void combineFiles() throws Exception {
* operation), adjust the file length so that the part starts writing from
* the correct position.
*/
private void truncateDestinationFileIfNecessary() throws IOException {
private void truncateDestinationFileIfNecessary() {
Copy link

@drainx drainx Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the IOException and force up into the general exception?

Copy link
Contributor Author

@pbruski pbruski Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOException was not thrown from this method. It only throws unchecked exceptions.

@kiiadi
Copy link
Contributor

kiiadi commented Sep 23, 2016

Minor optimization but it'd be nice to have the directory creation for both in a single util method so we're consistent with it's handling. Perhaps a createParentDirectory method that both single and multipart downloads can use.

@kiiadi
Copy link
Contributor

kiiadi commented Sep 23, 2016

Actually looking at this again, I don't think we need this. In the most recent version of the SDK we made an update to the multipart download so that file parts are downloaded in the same directory as the target file (ie: dstFile) in this case the parent should already exist. ServiceUtils.downloadToFile gets called in both DownloadCallable and DownloadPartCallable.

If you upgrade to 1.11.37 you should not need this explicit create for multi-part files.

@pbruski
Copy link
Contributor Author

pbruski commented Sep 23, 2016

Hmm, I'd swear I've tested it with the most recent version too and it failed. I'll have a look at it again after the weekend.

@kiiadi
Copy link
Contributor

kiiadi commented Sep 23, 2016

1.11.37 was only released yesterday.

@pbruski
Copy link
Contributor Author

pbruski commented Sep 26, 2016

No, 37 is still broken. What you say about the new behaviour is all true, except that the exception is thrown from the locking code, so potentially before the parent dir gets asynchonously created in the download callables.

@kiiadi kiiadi merged commit 8b2d073 into aws:master Sep 26, 2016
@kiiadi
Copy link
Contributor

kiiadi commented Sep 26, 2016

That makes sense, I guess we could have solved it by just pushing the call to truncateDestinationFileIfNecessary() down into the loop around the Futures - but I like the explicit approach you've gone with.

Looks good to me - this fix should go out with our next release.

@@ -197,7 +196,10 @@ private void downloadInParallel(int partCount) throws Exception {
* Merges all the individual part Files into dstFile
*/
private void combineFiles() throws Exception {
truncateDestinationFileIfNecessary();
if (!ServiceUtils.createParentDirectoryIfNecessary(dstfile)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't fix the problem. futureFiles starts download concurrently, which may happen before this is excuted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The future file get also creates the parent directory if necessary I believe. So which ever one starts first should create the parent directory and hopefully resolve the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the temp file is created before the ServiceUtils parent directory creation is done. So, yeah, the fix is not complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants