-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(s3): improve error on move/copy operations when bucket quota exceeded #59939
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| use GuzzleHttp\Psr7\Utils; | ||
| use OC\Files\Stream\SeekableHttpStream; | ||
| use OCA\DAV\Connector\Sabre\Exception\BadGateway; | ||
| use OCP\Files\EntityTooLargeException; | ||
| use Psr\Http\Message\StreamInterface; | ||
|
|
||
| trait S3ObjectTrait { | ||
|
|
@@ -94,6 +95,24 @@ private function buildS3Metadata(array $metadata): array { | |
| return $result; | ||
| } | ||
|
|
||
| private function isStorageFullException(\Throwable $e) { | ||
| while ($e !== null) { | ||
| if ($e instanceof AwsException) { | ||
| // MinIO: dedicated error code for storage-full | ||
|
Member
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. I was only able to test this with rustfs so far. The MinIO error code is taken from the MinIO code search. Would be good to put a breakpoint here and debug with AWS S3 and other S3 providers if possible, in order to find out their exact error code/message and adjust the conditions here.
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. Amazon S3 buckets have no maximum size or object count limit. There is an EntityTooLarge error for individual PutObject requests > 5GB. Multipart uploads can be up to 50TB now. |
||
| if ($e->getAwsErrorCode() === 'XMinioStorageFull') { | ||
| return true; | ||
| } | ||
| // RustFS: returns generic error code but with a recognisable message | ||
| if (str_starts_with($e->getAwsErrorMessage() ?? '', 'Bucket quota exceeded.')) { | ||
| return true; | ||
| } | ||
| } | ||
| $e = $e->getPrevious(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Single object put helper | ||
| * | ||
|
|
@@ -121,7 +140,14 @@ protected function writeSingle(string $urn, StreamInterface $stream, array $meta | |
| $args['ContentLength'] = $size; | ||
| } | ||
|
|
||
| $this->getConnection()->putObject($args); | ||
| try { | ||
| $this->getConnection()->putObject($args); | ||
| } catch (AwsException $e) { | ||
| if ($this->isStorageFullException($e)) { | ||
| throw new EntityTooLargeException('Quota exceeded on S3 storage', 0, $e); | ||
| } | ||
| throw $e; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -198,6 +224,10 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, array $m | |
| $this->getConnection()->abortMultipartUpload($uploadInfo); | ||
| } | ||
|
|
||
| if ($this->isStorageFullException($exception)) { | ||
| throw new EntityTooLargeException('Quota exceeded on S3 storage', 0, $exception); | ||
| } | ||
|
|
||
| throw new BadGateway('Error while uploading to S3 bucket', 0, $exception); | ||
| } | ||
| } | ||
|
|
@@ -290,12 +320,24 @@ public function copyObject($from, $to, array $options = []) { | |
| 'params' => $this->getServerSideEncryptionParameters() + $this->getServerSideEncryptionParameters(true), | ||
| 'source_metadata' => $sourceMetadata | ||
| ], $options)); | ||
| $copy->copy(); | ||
| try { | ||
| $copy->copy(); | ||
| } catch (\Throwable $e) { | ||
| if ($this->isStorageFullException($e)) { | ||
| throw new EntityTooLargeException('Quota exceeded on S3 storage', 0, $e); | ||
| } | ||
| } | ||
| } else { | ||
| $this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to, 'private', array_merge([ | ||
| 'params' => $this->getServerSideEncryptionParameters() + $this->getServerSideEncryptionParameters(true), | ||
| 'mup_threshold' => PHP_INT_MAX, | ||
| ], $options)); | ||
| try { | ||
| $this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to, 'private', array_merge([ | ||
| 'params' => $this->getServerSideEncryptionParameters() + $this->getServerSideEncryptionParameters(true), | ||
| 'mup_threshold' => PHP_INT_MAX, | ||
| ], $options)); | ||
| } catch (AwsException $e) { | ||
| if ($this->isStorageFullException($e)) { | ||
| throw new EntityTooLargeException('Quota exceeded on S3 storage', 0, $e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
I would recommend the error here being "file too large" versus quota specifically. The conditions we're adding here are for bucket quota, but also bubbling "EntityTooLarge" which could happen under multiple, future conditions. This message is a lot more re-usable just indicating a size issue in general.