Skip to content

Commit

Permalink
fix: last chunk is retriable
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyn committed Jan 12, 2021
1 parent ebb5fb2 commit d39094b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -120,6 +120,14 @@ public void run() {
// For completeness, this case is not possible because it would require retrying
// a 400 status code which is not allowed.
//
// Case 7: remoteNextByteOffset==-1 && last == true
// Upload is complete and retry occurred in the "last" chunk. Data sent was
// received by the service.
//
// Case 8: remoteNextByteOffset==-1 && last == false
// Upload was completed by another client because this retry did not occur
// during the last chunk.
//
// Get remote offset from API
long remoteNextByteOffset =
getOptions().getStorageRpcV1().getCurrentUploadOffset(getUploadId());
Expand Down Expand Up @@ -154,7 +162,8 @@ && driftOffset < getChunkSize()) {
// Continue to next chunk
retrying = false;
return;
} else {
} else if (localNextByteOffset < remoteNextByteOffset
&& driftOffset > getChunkSize()) {
// Case 5
StringBuilder sb = new StringBuilder();
sb.append(
Expand All @@ -167,6 +176,13 @@ && driftOffset < getChunkSize()) {
sb.append("remoteNextByteOffset: ").append(remoteNextByteOffset).append('\n');
sb.append("driftOffset: ").append(driftOffset).append("\n\n");
throw new StorageException(0, sb.toString());
} else if (remoteNextByteOffset == -1 && last) {
// Case 7
retrying = false;
return;
} else if (remoteNextByteOffset == -1 && !last) {
// Case 8
throw new StorageException(0, "Resumable upload is already complete.");
}
}
// Request was successful and retrying state is now disabled.
Expand Down
Expand Up @@ -766,7 +766,7 @@ public long getCurrentUploadOffset(String uploadId) {
response = httpRequest.execute();
int code = response.getStatusCode();
if (code == 201 || code == 200) {
throw new StorageException(0, "Resumable upload is already complete.");
return -1;
}
StringBuilder sb = new StringBuilder();
sb.append("Not sure what occurred. Here's debugging information:\n");
Expand Down

0 comments on commit d39094b

Please sign in to comment.