|
|
@ -22,6 +22,7 @@ import ( |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"sync" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -109,13 +110,26 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload |
|
|
|
if !isUploadIDExists(xl.storage, bucket, object, uploadID) { |
|
|
|
if !isUploadIDExists(xl.storage, bucket, object, uploadID) { |
|
|
|
return "", InvalidUploadID{UploadID: uploadID} |
|
|
|
return "", InvalidUploadID{UploadID: uploadID} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate s3 compatible md5sum for complete multipart.
|
|
|
|
|
|
|
|
s3MD5, err := completeMultipartMD5(parts...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var metadata = MultipartObjectInfo{} |
|
|
|
var metadata = MultipartObjectInfo{} |
|
|
|
var md5Sums []string |
|
|
|
var errs = make([]error, len(parts)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Waitgroup to wait for go-routines.
|
|
|
|
|
|
|
|
var wg = &sync.WaitGroup{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through all parts, validate them and then commit to disk.
|
|
|
|
for _, part := range parts { |
|
|
|
for _, part := range parts { |
|
|
|
// Construct part suffix.
|
|
|
|
// Construct part suffix.
|
|
|
|
partSuffix := fmt.Sprintf("%.5d.%s", part.PartNumber, part.ETag) |
|
|
|
partSuffix := fmt.Sprintf("%.5d.%s", part.PartNumber, part.ETag) |
|
|
|
multipartPartFile := path.Join(mpartMetaPrefix, bucket, object, uploadID, partSuffix) |
|
|
|
multipartPartFile := path.Join(mpartMetaPrefix, bucket, object, uploadID, partSuffix) |
|
|
|
fi, err := xl.storage.StatFile(minioMetaBucket, multipartPartFile) |
|
|
|
var fi FileInfo |
|
|
|
|
|
|
|
fi, err = xl.storage.StatFile(minioMetaBucket, multipartPartFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if err == errFileNotFound { |
|
|
|
if err == errFileNotFound { |
|
|
|
return "", InvalidPart{} |
|
|
|
return "", InvalidPart{} |
|
|
@ -129,22 +143,48 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload |
|
|
|
Size: fi.Size, |
|
|
|
Size: fi.Size, |
|
|
|
}) |
|
|
|
}) |
|
|
|
metadata.Size += fi.Size |
|
|
|
metadata.Size += fi.Size |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through and atomically rename the parts to their actual location.
|
|
|
|
|
|
|
|
for index, part := range parts { |
|
|
|
|
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
go func(index int, part completePart) { |
|
|
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
partSuffix := fmt.Sprintf("%.5d.%s", part.PartNumber, part.ETag) |
|
|
|
|
|
|
|
multipartPartFile := path.Join(mpartMetaPrefix, bucket, object, uploadID, partSuffix) |
|
|
|
|
|
|
|
tmpMultipartObjSuffix := path.Join(tmpMetaPrefix, bucket, object, partNumToPartFileName(part.PartNumber)) |
|
|
|
|
|
|
|
rErr := xl.storage.RenameFile(minioMetaBucket, multipartPartFile, minioMetaBucket, tmpMultipartObjSuffix) |
|
|
|
|
|
|
|
if rErr != nil { |
|
|
|
|
|
|
|
errs[index] = rErr |
|
|
|
|
|
|
|
log.Errorf("Unable to rename file %s to %s, failed with %s", multipartPartFile, tmpMultipartObjSuffix, rErr) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
multipartObjSuffix := path.Join(object, partNumToPartFileName(part.PartNumber)) |
|
|
|
|
|
|
|
rErr = xl.storage.RenameFile(minioMetaBucket, tmpMultipartObjSuffix, bucket, multipartObjSuffix) |
|
|
|
|
|
|
|
if rErr != nil { |
|
|
|
|
|
|
|
if dErr := xl.storage.DeleteFile(minioMetaBucket, tmpMultipartObjSuffix); dErr != nil { |
|
|
|
|
|
|
|
errs[index] = dErr |
|
|
|
|
|
|
|
log.Errorf("Unable to delete file %s, failed with %s", tmpMultipartObjSuffix, dErr) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Debugf("Delete file succeeded on %s", tmpMultipartObjSuffix) |
|
|
|
|
|
|
|
errs[index] = rErr |
|
|
|
|
|
|
|
log.Errorf("Unable to rename file %s to %s, failed with %s", tmpMultipartObjSuffix, multipartObjSuffix, rErr) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}(index, part) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
multipartObjSuffix := path.Join(object, partNumToPartFileName(part.PartNumber)) |
|
|
|
// Wait for all the renames to finish.
|
|
|
|
err = xl.storage.RenameFile(minioMetaBucket, multipartPartFile, bucket, multipartObjSuffix) |
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through errs list and return first error.
|
|
|
|
|
|
|
|
for _, err := range errs { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
return "", toObjectErr(err, bucket, object) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Save md5sum for future response.
|
|
|
|
|
|
|
|
md5Sums = append(md5Sums, part.ETag) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Calculate and save s3 compatible md5sum.
|
|
|
|
// Save successfully calculated md5sum.
|
|
|
|
s3MD5, err := completeMultipartMD5(md5Sums...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
metadata.MD5Sum = s3MD5 |
|
|
|
metadata.MD5Sum = s3MD5 |
|
|
|
// Save modTime as well as the current time.
|
|
|
|
// Save modTime as well as the current time.
|
|
|
|
metadata.ModTime = time.Now().UTC() |
|
|
|
metadata.ModTime = time.Now().UTC() |
|
|
|