diff --git a/cmd/api-errors.go b/cmd/api-errors.go index 3dfd90f26..824007fdc 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -146,6 +146,7 @@ const ( ErrInvalidResourceName ErrServerNotInitialized ErrOperationTimedOut + ErrPartsSizeUnequal // Add new extended error codes here. // Please open a https://github.com/minio/minio/issues before adding // new error codes here. @@ -659,6 +660,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{ Description: "Your metadata headers are not supported.", HTTPStatusCode: http.StatusBadRequest, }, + ErrPartsSizeUnequal: { + Code: "XMinioPartsSizeUnequal", + Description: "All parts except the last part should be of the same size.", + HTTPStatusCode: http.StatusBadRequest, + }, // Add your error structure here. } @@ -755,6 +761,8 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) { apiErr = ErrEntityTooLarge case UnsupportedMetadata: apiErr = ErrUnsupportedMetadata + case PartsSizeUnequal: + apiErr = ErrPartsSizeUnequal default: apiErr = ErrInternalError } diff --git a/cmd/fs-v1-multipart.go b/cmd/fs-v1-multipart.go index f3476ccda..cb0e38e40 100644 --- a/cmd/fs-v1-multipart.go +++ b/cmd/fs-v1-multipart.go @@ -777,6 +777,7 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload return oi, toObjectErr(err, minioMetaMultipartBucket, fsMetaPathMultipart) } + partSize := int64(-1) // Used later to ensure that all parts sizes are same. // Validate all parts and then commit to disk. for i, part := range parts { partIdx := fsMeta.ObjectPartIndex(part.PartNumber) @@ -799,6 +800,20 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload PartETag: part.ETag, }) } + if partSize == -1 { + partSize = fsMeta.Parts[partIdx].Size + } + // TODO: Make necessary changes in future as explained in the below comment. + // All parts except the last part has to be of same size. We are introducing this + // check to see if any clients break. If clients do not break then we can optimize + // multipart PutObjectPart by writing the part at the right offset using pwrite() + // so that we don't need to do background append at all. i.e by the time we get + // CompleteMultipartUpload we already have the full file available which can be + // renamed to the main name-space. + if (i < len(parts)-1) && partSize != fsMeta.Parts[partIdx].Size { + fs.rwPool.Close(fsMetaPathMultipart) + return oi, traceError(PartsSizeUnequal{}) + } } // Wait for any competing PutObject() operation on bucket/object, since same namespace diff --git a/cmd/object-api-errors.go b/cmd/object-api-errors.go index c07ff434f..e1fa8a84a 100644 --- a/cmd/object-api-errors.go +++ b/cmd/object-api-errors.go @@ -341,6 +341,13 @@ func (e InvalidPart) Error() string { return "One or more of the specified parts could not be found. The part may not have been uploaded, or the specified entity tag may not match the part's entity tag." } +// PartsSizeUnequal - All parts except the last part should be of the same size +type PartsSizeUnequal struct{} + +func (e PartsSizeUnequal) Error() string { + return "All parts except the last part should be of the same size" +} + // PartTooSmall - error if part size is less than 5MB. type PartTooSmall struct { PartSize int64