-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(s3): retry failed multipart uploads with decreased concurrency #53419
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
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 |
|---|---|---|
|
|
@@ -119,28 +119,54 @@ protected function writeSingle(string $urn, StreamInterface $stream, array $meta | |
| protected function writeMultiPart(string $urn, StreamInterface $stream, array $metaData): void { | ||
| $mimetype = $metaData['mimetype'] ?? null; | ||
| unset($metaData['mimetype']); | ||
| $uploader = new MultipartUploader($this->getConnection(), $stream, [ | ||
| 'bucket' => $this->bucket, | ||
| 'concurrency' => $this->concurrency, | ||
| 'key' => $urn, | ||
| 'part_size' => $this->uploadPartSize, | ||
| 'params' => [ | ||
| 'ContentType' => $mimetype, | ||
| 'Metadata' => $this->buildS3Metadata($metaData), | ||
| 'StorageClass' => $this->storageClass, | ||
| ] + $this->getSSECParameters(), | ||
| ]); | ||
|
|
||
| try { | ||
| $uploader->upload(); | ||
| } catch (S3MultipartUploadException $e) { | ||
| $attempts = 0; | ||
| $uploaded = false; | ||
| $concurrency = $this->concurrency; | ||
| $exception = null; | ||
| $state = null; | ||
|
|
||
| // retry multipart upload once with concurrency at half on failure | ||
| while (!$uploaded && $attempts <= 1) { | ||
| $uploader = new MultipartUploader($this->getConnection(), $stream, [ | ||
| 'bucket' => $this->bucket, | ||
| 'concurrency' => $concurrency, | ||
| 'key' => $urn, | ||
| 'part_size' => $this->uploadPartSize, | ||
| 'state' => $state, | ||
| 'params' => [ | ||
| 'ContentType' => $mimetype, | ||
| 'Metadata' => $this->buildS3Metadata($metaData), | ||
| 'StorageClass' => $this->storageClass, | ||
| ] + $this->getSSECParameters(), | ||
| ]); | ||
|
|
||
| try { | ||
| $uploader->upload(); | ||
| $uploaded = true; | ||
| } catch (S3MultipartUploadException $e) { | ||
| $exception = $e; | ||
|
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. Is that necessary? If so, you can also simply rename the variable name in the But I would probably do without to reduce the amount of changed line. In any cases, let's not have two variables with the same content.
Member
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. I think it makes the code more understandable, as you expect the variable from the
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. Right, I missed the declaration above. It is a bit convoluted, but alright. |
||
| $attempts++; | ||
|
|
||
| if ($concurrency > 1) { | ||
| $concurrency = round($concurrency / 2); | ||
| } | ||
|
|
||
| if ($stream->isSeekable()) { | ||
| $stream->rewind(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!$uploaded) { | ||
| // if anything goes wrong with multipart, make sure that you don´t poison and | ||
| // slow down s3 bucket with orphaned fragments | ||
| $uploadInfo = $e->getState()->getId(); | ||
| if ($e->getState()->isInitiated() && (array_key_exists('UploadId', $uploadInfo))) { | ||
| $uploadInfo = $exception->getState()->getId(); | ||
| if ($exception->getState()->isInitiated() && (array_key_exists('UploadId', $uploadInfo))) { | ||
| $this->getConnection()->abortMultipartUpload($uploadInfo); | ||
| } | ||
| throw new \OCA\DAV\Connector\Sabre\Exception\BadGateway('Error while uploading to S3 bucket', 0, $e); | ||
|
|
||
| throw new \OCA\DAV\Connector\Sabre\Exception\BadGateway('Error while uploading to S3 bucket', 0, $exception); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.