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

Fix multipart upload pause #1536

Merged
merged 3 commits into from
Mar 30, 2020
Merged

Fix multipart upload pause #1536

merged 3 commits into from
Mar 30, 2020

Conversation

raphkim
Copy link
Contributor

@raphkim raphkim commented Mar 29, 2020

Issue #, if available:
#1500

Description of changes:
TransferUtility#pause(int) was not behaving correctly when uploading a multipart (> 5MB) item. This was due to interruption detection (due to pause) code returning early before actually canceling the individual UploadPartTask tasks in the upload. The same result would have been seen for TransferUtility#cancel(int) for a large upload.

Additionally to fixing the above bug, this PR also contains fix to mitigate the effects of race condition observed when pausing multipart upload and resuming it instantly. Previously, the transfer state would be set to PAUSED or CANCELED as soon as the method was called even before all of the task was interrupted. Now PENDING_PAUSE and PENDING_CANCEL (already present in the codebase but unused) states are used to make sure that the task is successfully interrupted before the state is updated to its final state.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@raphkim raphkim added s3 Issues with the AWS Android SDK for Simple Storage Service (S3). Pull Request labels Mar 29, 2020
@raphkim raphkim self-assigned this Mar 29, 2020

public final class PauseTransferIntegrationTest extends S3IntegrationTestBase {

private static final String bucketName = "amazon-transfer-util-integ-test-" + new Date().getTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we name it like BUCKET_NAME to be consistent with convention and rest of the codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea oops. A mistake that was copy + pasted from my previous mistake. will fix them

@@ -144,8 +144,6 @@ public Boolean call() {
*/
updater.updateState(download.id, TransferState.WAITING_FOR_NETWORK);
LOGGER.debug("Network Connection Interrupted: " + "Moving the TransferState to WAITING_FOR_NETWORK");
ProgressEvent resetEvent = new ProgressEvent(0);
resetEvent.setEventCode(ProgressEvent.RESET_EVENT_CODE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be resetting the progress upon loss of network and then pass reserEvent to the progressListener?

@@ -310,8 +315,6 @@ private Boolean uploadSinglePartAndWaitForCompletion() {
*/
updater.updateState(upload.id, TransferState.WAITING_FOR_NETWORK);
LOGGER.debug("Network Connection Interrupted: " + "Moving the TransferState to WAITING_FOR_NETWORK");
ProgressEvent resetEvent = new ProgressEvent(0);
resetEvent.setEventCode(ProgressEvent.RESET_EVENT_CODE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. If eventCode is not being used anywhere should we consider removing it altogether from the ProgressEvent class?

if (TransferState.PAUSED.equals(download.state)) {
LOGGER.info("Transfer is " + download.state);
ProgressEvent resetEvent = new ProgressEvent(0);
resetEvent.setEventCode(ProgressEvent.RESET_EVENT_CODE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we not resetting on pause on anymore? If so, do we need to update documentation?

Copy link
Contributor Author

@raphkim raphkim Mar 29, 2020

Choose a reason for hiding this comment

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

if you look closely, the lines i removed were noops. Im not sure if the original intent was to pass in a new ProgressEvent(0) with reset flag, but this resetEvent object never gets used and a new progress event without flag is reinstantiated instead. Perhaps a different bug, but I didn't want to introduce yet another behavior change in this PR.

@raphkim
Copy link
Contributor Author

raphkim commented Mar 30, 2020

This PR contained removal of some lines that SEEMED to be doing something important but was actually not doing anything:

ProgressEvent resetEvent = new ProgressEvent(0);
resetEvent.setEventCode(ProgressEvent.RESET_EVENT_CODE);
progressListener.progressChanged(new ProgressEvent(0));

The first two lines don't do anything, since resetEvent is not used anywhere after this bit of code.

This is probably an important issue of its own that requires its own investigation, so I decided to leave the redundant lines for now to revisit in the future with a separate PR.

Copy link
Contributor

@TrekSoft TrekSoft left a comment

Choose a reason for hiding this comment

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

Cat15

@TrekSoft TrekSoft merged commit 8fb3c87 into aws-amplify:develop Mar 30, 2020
@raphkim raphkim deleted the pause branch March 31, 2020 08:11
awsmobilesdk pushed a commit to awsmobilesdk/aws-sdk-android that referenced this pull request Apr 12, 2020
* Fix multipart upload interruption (pause/cancel)

* Change constant name according to convention

* Re-add reset code lines to avoid confusion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants