2016-05-20 23:48:47 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
2016-10-02 18:51:49 -04:00
|
|
|
"hash"
|
2016-05-20 23:48:47 -04:00
|
|
|
"io"
|
2016-07-08 23:34:27 -04:00
|
|
|
"io/ioutil"
|
2016-05-20 23:48:47 -04:00
|
|
|
"path"
|
2016-05-24 16:35:43 -04:00
|
|
|
"strings"
|
2016-05-20 23:48:47 -04:00
|
|
|
"time"
|
2016-05-24 16:35:43 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/mimedb"
|
2016-12-19 22:32:55 -05:00
|
|
|
"github.com/minio/sha256-simd"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// listMultipartUploads - lists all multipart uploads.
|
|
|
|
func (xl xlObjects) listMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, error) {
|
|
|
|
result := ListMultipartsInfo{
|
|
|
|
IsTruncated: true,
|
|
|
|
MaxUploads: maxUploads,
|
|
|
|
KeyMarker: keyMarker,
|
|
|
|
Prefix: prefix,
|
|
|
|
Delimiter: delimiter,
|
|
|
|
}
|
|
|
|
|
|
|
|
recursive := true
|
|
|
|
if delimiter == slashSeparator {
|
|
|
|
recursive = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not using path.Join() as it strips off the trailing '/'.
|
2016-11-22 16:15:06 -05:00
|
|
|
multipartPrefixPath := pathJoin(bucket, prefix)
|
2016-06-01 19:43:31 -04:00
|
|
|
if prefix == "" {
|
|
|
|
// Should have a trailing "/" if prefix is ""
|
|
|
|
// For ex. multipartPrefixPath should be "multipart/bucket/" if prefix is ""
|
|
|
|
multipartPrefixPath += slashSeparator
|
|
|
|
}
|
|
|
|
multipartMarkerPath := ""
|
|
|
|
if keyMarker != "" {
|
2016-11-22 16:15:06 -05:00
|
|
|
multipartMarkerPath = pathJoin(bucket, keyMarker)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
var uploads []uploadMetadata
|
|
|
|
var err error
|
|
|
|
var eof bool
|
|
|
|
// List all upload ids for the keyMarker starting from
|
|
|
|
// uploadIDMarker first.
|
|
|
|
if uploadIDMarker != "" {
|
2016-11-09 13:58:41 -05:00
|
|
|
// hold lock on keyMarker path
|
2016-12-10 19:15:12 -05:00
|
|
|
keyMarkerLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, keyMarker))
|
2016-11-09 13:58:41 -05:00
|
|
|
keyMarkerLock.RLock()
|
2016-07-21 03:27:08 -04:00
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uploads, _, err = listMultipartUploadIDs(bucket, keyMarker, uploadIDMarker, maxUploads, disk)
|
2016-07-08 01:10:27 -04:00
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
keyMarkerLock.RUnlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return ListMultipartsInfo{}, err
|
|
|
|
}
|
|
|
|
maxUploads = maxUploads - len(uploads)
|
|
|
|
}
|
2016-07-07 12:06:35 -04:00
|
|
|
var walkerCh chan treeWalkResult
|
|
|
|
var walkerDoneCh chan struct{}
|
2016-08-17 14:36:33 -04:00
|
|
|
heal := false // true only for xl.ListObjectsHeal
|
2016-06-01 19:43:31 -04:00
|
|
|
// Validate if we need to list further depending on maxUploads.
|
|
|
|
if maxUploads > 0 {
|
2016-11-22 16:15:06 -05:00
|
|
|
walkerCh, walkerDoneCh = xl.listPool.Release(listParams{minioMetaMultipartBucket, recursive, multipartMarkerPath, multipartPrefixPath, heal})
|
2016-05-30 00:05:00 -04:00
|
|
|
if walkerCh == nil {
|
|
|
|
walkerDoneCh = make(chan struct{})
|
2016-07-17 18:16:52 -04:00
|
|
|
isLeaf := xl.isMultipartUpload
|
2016-09-15 16:43:40 -04:00
|
|
|
listDir := listDirFactory(isLeaf, xlTreeWalkIgnoredErrs, xl.getLoadBalancedDisks()...)
|
2016-11-22 16:15:06 -05:00
|
|
|
walkerCh = startTreeWalk(minioMetaMultipartBucket, multipartPrefixPath, multipartMarkerPath, recursive, listDir, isLeaf, walkerDoneCh)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
// Collect uploads until we have reached maxUploads count to 0.
|
|
|
|
for maxUploads > 0 {
|
2016-05-30 00:05:00 -04:00
|
|
|
walkResult, ok := <-walkerCh
|
2016-06-01 19:43:31 -04:00
|
|
|
if !ok {
|
|
|
|
// Closed channel.
|
|
|
|
eof = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
// For any walk error return right away.
|
|
|
|
if walkResult.err != nil {
|
|
|
|
// File not found or Disk not found is a valid case.
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(walkResult.err, xlTreeWalkIgnoredErrs...) {
|
2016-06-01 19:43:31 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return ListMultipartsInfo{}, err
|
|
|
|
}
|
2016-11-22 16:15:06 -05:00
|
|
|
entry := strings.TrimPrefix(walkResult.entry, retainSlash(bucket))
|
2016-06-01 19:43:31 -04:00
|
|
|
// For an entry looking like a directory, store and
|
|
|
|
// continue the loop not need to fetch uploads.
|
|
|
|
if strings.HasSuffix(walkResult.entry, slashSeparator) {
|
|
|
|
uploads = append(uploads, uploadMetadata{
|
|
|
|
Object: entry,
|
|
|
|
})
|
|
|
|
maxUploads--
|
|
|
|
if maxUploads == 0 {
|
2016-05-30 00:05:00 -04:00
|
|
|
eof = true
|
|
|
|
break
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var newUploads []uploadMetadata
|
|
|
|
var end bool
|
|
|
|
uploadIDMarker = ""
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// For the new object entry we get all its
|
|
|
|
// pending uploadIDs.
|
2016-12-10 19:15:12 -05:00
|
|
|
entryLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, entry))
|
2016-11-09 13:58:41 -05:00
|
|
|
entryLock.RLock()
|
2016-06-02 19:34:15 -04:00
|
|
|
var disk StorageAPI
|
2016-07-21 03:27:08 -04:00
|
|
|
for _, disk = range xl.getLoadBalancedDisks() {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-03 01:49:27 -04:00
|
|
|
newUploads, end, err = listMultipartUploadIDs(bucket, entry, uploadIDMarker, maxUploads, disk)
|
2016-07-08 01:10:27 -04:00
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
entryLock.RUnlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, xlTreeWalkIgnoredErrs...) {
|
2016-06-01 19:43:31 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return ListMultipartsInfo{}, err
|
|
|
|
}
|
|
|
|
uploads = append(uploads, newUploads...)
|
|
|
|
maxUploads -= len(newUploads)
|
2016-05-30 00:05:00 -04:00
|
|
|
if end && walkResult.end {
|
2016-06-01 19:43:31 -04:00
|
|
|
eof = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// For all received uploads fill in the multiparts result.
|
|
|
|
for _, upload := range uploads {
|
|
|
|
var objectName string
|
|
|
|
var uploadID string
|
|
|
|
if strings.HasSuffix(upload.Object, slashSeparator) {
|
|
|
|
// All directory entries are common prefixes.
|
|
|
|
uploadID = "" // For common prefixes, upload ids are empty.
|
|
|
|
objectName = upload.Object
|
|
|
|
result.CommonPrefixes = append(result.CommonPrefixes, objectName)
|
|
|
|
} else {
|
|
|
|
uploadID = upload.UploadID
|
|
|
|
objectName = upload.Object
|
|
|
|
result.Uploads = append(result.Uploads, upload)
|
|
|
|
}
|
|
|
|
result.NextKeyMarker = objectName
|
|
|
|
result.NextUploadIDMarker = uploadID
|
|
|
|
}
|
2016-07-07 12:06:35 -04:00
|
|
|
|
|
|
|
if !eof {
|
|
|
|
// Save the go-routine state in the pool so that it can continue from where it left off on
|
|
|
|
// the next request.
|
2016-08-17 14:36:33 -04:00
|
|
|
xl.listPool.Set(listParams{bucket, recursive, result.NextKeyMarker, prefix, heal}, walkerCh, walkerDoneCh)
|
2016-07-07 12:06:35 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
result.IsTruncated = !eof
|
|
|
|
// Result is not truncated, reset the markers.
|
|
|
|
if !result.IsTruncated {
|
|
|
|
result.NextKeyMarker = ""
|
|
|
|
result.NextUploadIDMarker = ""
|
|
|
|
}
|
|
|
|
return result, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// ListMultipartUploads - lists all the pending multipart uploads on a
|
|
|
|
// bucket. Additionally takes 'prefix, keyMarker, uploadIDmarker and a
|
|
|
|
// delimiter' which allows us to list uploads match a particular
|
|
|
|
// prefix or lexically starting from 'keyMarker' or delimiting the
|
|
|
|
// output to get a directory like listing.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible ListMultipartUploads API. The resulting
|
|
|
|
// ListMultipartsInfo structure is unmarshalled directly into XML and
|
|
|
|
// replied back to the client.
|
|
|
|
func (xl xlObjects) ListMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (ListMultipartsInfo, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkListMultipartArgs(bucket, prefix, keyMarker, uploadIDMarker, delimiter, xl); err != nil {
|
|
|
|
return ListMultipartsInfo{}, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
return xl.listMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads)
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// newMultipartUpload - wrapper for initializing a new multipart
|
2016-10-24 20:37:18 -04:00
|
|
|
// request; returns a unique upload id.
|
2016-06-01 19:43:31 -04:00
|
|
|
//
|
|
|
|
// Internally this function creates 'uploads.json' associated for the
|
2016-10-24 20:37:18 -04:00
|
|
|
// incoming object at
|
|
|
|
// '.minio.sys/multipart/bucket/object/uploads.json' on all the
|
|
|
|
// disks. `uploads.json` carries metadata regarding on-going multipart
|
|
|
|
// operation(s) on the object.
|
|
|
|
func (xl xlObjects) newMultipartUpload(bucket string, object string, meta map[string]string) (string, error) {
|
2016-07-08 18:28:09 -04:00
|
|
|
xlMeta := newXLMetaV1(object, xl.dataBlocks, xl.parityBlocks)
|
2016-05-20 23:48:47 -04:00
|
|
|
// If not set default to "application/octet-stream"
|
|
|
|
if meta["content-type"] == "" {
|
2016-05-24 16:35:43 -04:00
|
|
|
contentType := "application/octet-stream"
|
2016-08-17 16:26:08 -04:00
|
|
|
if objectExt := path.Ext(object); objectExt != "" {
|
2016-05-24 16:35:43 -04:00
|
|
|
content, ok := mimedb.DB[strings.ToLower(strings.TrimPrefix(objectExt, "."))]
|
|
|
|
if ok {
|
|
|
|
contentType = content.ContentType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta["content-type"] = contentType
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 19:42:31 -04:00
|
|
|
xlMeta.Stat.ModTime = time.Now().UTC()
|
2016-05-20 23:48:47 -04:00
|
|
|
xlMeta.Meta = meta
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// This lock needs to be held for any changes to the directory
|
|
|
|
// contents of ".minio.sys/multipart/object/"
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2016-11-09 13:58:41 -05:00
|
|
|
objectMPartPathLock.Lock()
|
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-11-22 19:52:37 -05:00
|
|
|
uploadID := mustGetUUID()
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
2016-11-20 17:25:43 -05:00
|
|
|
tempUploadIDPath := uploadID
|
2016-06-02 19:34:15 -04:00
|
|
|
// Write updated `xl.json` to all disks.
|
2016-11-20 17:25:43 -05:00
|
|
|
if err := writeSameXLMetadata(xl.storageDisks, minioMetaTmpBucket, tempUploadIDPath, xlMeta, xl.writeQuorum, xl.readQuorum); err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaTmpBucket, tempUploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-10-24 20:37:18 -04:00
|
|
|
// delete the tmp path later in case we fail to rename (ignore
|
|
|
|
// returned errors) - this will be a no-op in case of a rename
|
|
|
|
// success.
|
2016-11-20 17:25:43 -05:00
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, tempUploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
|
|
|
|
// Attempt to rename temp upload object to actual upload path
|
|
|
|
// object
|
2016-11-22 16:15:06 -05:00
|
|
|
if rErr := renameObject(xl.storageDisks, minioMetaTmpBucket, tempUploadIDPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum); rErr != nil {
|
|
|
|
return "", toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
initiated := time.Now().UTC()
|
|
|
|
// Create or update 'uploads.json'
|
2016-11-22 18:29:39 -05:00
|
|
|
if err := xl.addUploadID(bucket, object, uploadID, initiated); err != nil {
|
2016-10-24 20:37:18 -04:00
|
|
|
return "", err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-10-24 20:37:18 -04:00
|
|
|
// Return success.
|
|
|
|
return uploadID, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// NewMultipartUpload - initialize a new multipart upload, returns a
|
|
|
|
// unique id. The unique id returned here is of UUID form, for each
|
|
|
|
// subsequent request each UUID is unique.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible initiate multipart API.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) NewMultipartUpload(bucket, object string, meta map[string]string) (string, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkNewMultipartArgs(bucket, object, xl); err != nil {
|
|
|
|
return "", err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
// No metadata is set, allocate a new one.
|
|
|
|
if meta == nil {
|
|
|
|
meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
return xl.newMultipartUpload(bucket, object, meta)
|
|
|
|
}
|
|
|
|
|
2016-07-05 04:04:50 -04:00
|
|
|
// PutObjectPart - reads incoming stream and internally erasure codes
|
|
|
|
// them. This call is similar to single put operation but it is part
|
2016-08-05 01:01:58 -04:00
|
|
|
// of the multipart transaction.
|
2016-07-05 04:04:50 -04:00
|
|
|
//
|
|
|
|
// Implements S3 compatible Upload Part API.
|
2016-10-02 18:51:49 -04:00
|
|
|
func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string, sha256sum string) (string, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkPutObjectPartArgs(bucket, object, xl); err != nil {
|
|
|
|
return "", err
|
2016-07-05 04:04:50 -04:00
|
|
|
}
|
2016-05-27 04:12:44 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
var partsMetadata []xlMetaV1
|
|
|
|
var errs []error
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := pathJoin(bucket, object, uploadID)
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// pre-check upload id lock.
|
2016-12-10 19:15:12 -05:00
|
|
|
preUploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket, uploadIDPath)
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RLock()
|
2016-07-11 20:24:49 -04:00
|
|
|
// Validates if upload ID exists.
|
2016-05-20 23:48:47 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs = readAllXLMetadata(xl.storageDisks, minioMetaMultipartBucket,
|
2016-07-11 20:24:49 -04:00
|
|
|
uploadIDPath)
|
2016-07-13 03:29:48 -04:00
|
|
|
if !isDiskQuorum(errs, xl.writeQuorum) {
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", toObjectErr(traceError(errXLWriteQuorum), bucket, object)
|
2016-06-27 13:01:09 -04:00
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2016-05-30 14:26:10 -04:00
|
|
|
|
2016-05-25 19:42:31 -04:00
|
|
|
// List all online disks.
|
2016-07-14 17:59:01 -04:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.storageDisks, partsMetadata, errs)
|
2016-07-12 18:20:31 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2016-07-14 17:59:01 -04:00
|
|
|
|
|
|
|
onlineDisks = getOrderedDisks(xlMeta.Erasure.Distribution, onlineDisks)
|
2016-09-02 02:10:50 -04:00
|
|
|
_ = getOrderedPartsMetadata(xlMeta.Erasure.Distribution, partsMetadata)
|
2016-05-26 22:55:48 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
// Need a unique name for the part being written in minioMetaBucket to
|
|
|
|
// accommodate concurrent PutObjectPart requests
|
2016-07-12 18:20:31 -04:00
|
|
|
|
2016-06-28 00:42:33 -04:00
|
|
|
partSuffix := fmt.Sprintf("part.%d", partID)
|
2016-11-22 19:52:37 -05:00
|
|
|
tmpPart := mustGetUUID()
|
|
|
|
tmpPartPath := path.Join(tmpPart, partSuffix)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
// Initialize md5 writer.
|
|
|
|
md5Writer := md5.New()
|
|
|
|
|
2016-10-02 18:51:49 -04:00
|
|
|
writers := []io.Writer{md5Writer}
|
|
|
|
|
|
|
|
var sha256Writer hash.Hash
|
|
|
|
if sha256sum != "" {
|
|
|
|
sha256Writer = sha256.New()
|
|
|
|
writers = append(writers, sha256Writer)
|
|
|
|
}
|
|
|
|
|
|
|
|
mw := io.MultiWriter(writers...)
|
|
|
|
|
2016-10-18 14:13:25 -04:00
|
|
|
var lreader io.Reader
|
2016-07-01 17:33:28 -04:00
|
|
|
// Limit the reader to its provided size > 0.
|
|
|
|
if size > 0 {
|
|
|
|
// This is done so that we can avoid erroneous clients sending
|
|
|
|
// more data than the set content size.
|
2016-10-01 12:37:40 -04:00
|
|
|
lreader = io.LimitReader(data, size)
|
2016-10-18 14:13:25 -04:00
|
|
|
} else {
|
|
|
|
// else we read till EOF.
|
|
|
|
lreader = data
|
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Construct a tee reader for md5sum.
|
2016-10-02 18:51:49 -04:00
|
|
|
teeReader := io.TeeReader(lreader, mw)
|
2016-05-29 18:38:14 -04:00
|
|
|
|
2016-10-20 01:52:03 -04:00
|
|
|
// Delete the temporary object part. If PutObjectPart succeeds there would be nothing to delete.
|
2016-11-21 19:34:57 -05:00
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, tmpPart)
|
2016-10-20 01:52:03 -04:00
|
|
|
|
2016-10-29 15:44:44 -04:00
|
|
|
if size > 0 {
|
|
|
|
for _, disk := range onlineDisks {
|
|
|
|
if disk != nil {
|
|
|
|
actualSize := xl.sizeOnDisk(size, xlMeta.Erasure.BlockSize, xlMeta.Erasure.DataBlocks)
|
2016-11-20 17:25:43 -05:00
|
|
|
disk.PrepareFile(minioMetaTmpBucket, tmpPartPath, actualSize)
|
2016-10-29 15:44:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Erasure code data and write across all disks.
|
2016-11-20 17:25:43 -05:00
|
|
|
sizeWritten, checkSums, err := erasureCreateFile(onlineDisks, minioMetaTmpBucket, tmpPartPath, teeReader, xlMeta.Erasure.BlockSize, xl.dataBlocks, xl.parityBlocks, bitRotAlgo, xl.writeQuorum)
|
2016-07-18 22:06:48 -04:00
|
|
|
if err != nil {
|
2016-07-19 02:56:16 -04:00
|
|
|
return "", toObjectErr(err, bucket, object)
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-10-20 01:52:03 -04:00
|
|
|
|
2016-07-18 22:06:48 -04:00
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
|
|
|
if sizeWritten < size {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(IncompleteBody{})
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
|
|
|
// For size == -1, perhaps client is sending in chunked encoding
|
|
|
|
// set the size as size that was actually written.
|
2016-06-02 20:09:47 -04:00
|
|
|
if size == -1 {
|
2016-07-01 17:33:28 -04:00
|
|
|
size = sizeWritten
|
2016-06-02 20:09:47 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2016-05-29 18:38:14 -04:00
|
|
|
// Calculate new md5sum.
|
2016-05-20 23:48:47 -04:00
|
|
|
newMD5Hex := hex.EncodeToString(md5Writer.Sum(nil))
|
|
|
|
if md5Hex != "" {
|
|
|
|
if newMD5Hex != md5Hex {
|
2016-06-01 19:43:31 -04:00
|
|
|
// Returns md5 mismatch.
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BadDigest{md5Hex, newMD5Hex})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
}
|
2016-05-29 03:42:09 -04:00
|
|
|
|
2016-10-02 18:51:49 -04:00
|
|
|
if sha256sum != "" {
|
|
|
|
newSHA256sum := hex.EncodeToString(sha256Writer.Sum(nil))
|
|
|
|
if newSHA256sum != sha256sum {
|
|
|
|
return "", traceError(SHA256Mismatch{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// post-upload check (write) lock
|
2016-12-10 19:15:12 -05:00
|
|
|
postUploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket, uploadIDPath)
|
2016-11-09 13:58:41 -05:00
|
|
|
postUploadIDLock.Lock()
|
|
|
|
defer postUploadIDLock.Unlock()
|
2016-07-11 20:24:49 -04:00
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Validate again if upload ID still exists.
|
2016-05-30 14:26:10 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-30 14:26:10 -04:00
|
|
|
}
|
|
|
|
|
2016-05-29 18:38:14 -04:00
|
|
|
// Rename temporary part file to its final location.
|
2016-05-31 23:23:31 -04:00
|
|
|
partPath := path.Join(uploadIDPath, partSuffix)
|
2016-11-22 16:15:06 -05:00
|
|
|
err = renamePart(onlineDisks, minioMetaTmpBucket, tmpPartPath, minioMetaMultipartBucket, partPath, xl.writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return "", toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-26 06:15:01 -04:00
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Read metadata again because it might be updated with parallel upload of another part.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs = readAllXLMetadata(onlineDisks, minioMetaMultipartBucket, uploadIDPath)
|
2016-07-13 03:29:48 -04:00
|
|
|
if !isDiskQuorum(errs, xl.writeQuorum) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", toObjectErr(traceError(errXLWriteQuorum), bucket, object)
|
2016-07-11 20:24:49 -04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Get current highest version based on re-read partsMetadata.
|
|
|
|
onlineDisks, modTime = listOnlineDisks(onlineDisks, partsMetadata, errs)
|
2016-07-11 20:24:49 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err = pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2016-07-11 20:24:49 -04:00
|
|
|
|
2016-05-26 06:15:01 -04:00
|
|
|
// Once part is successfully committed, proceed with updating XL metadata.
|
2016-07-12 18:20:31 -04:00
|
|
|
xlMeta.Stat.ModTime = time.Now().UTC()
|
2016-06-17 14:57:51 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Add the current part.
|
2016-05-26 06:15:01 -04:00
|
|
|
xlMeta.AddObjectPart(partID, partSuffix, newMD5Hex, size)
|
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
for index, disk := range onlineDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
partsMetadata[index].Parts = xlMeta.Parts
|
2016-07-28 05:20:34 -04:00
|
|
|
partsMetadata[index].Erasure.AddCheckSumInfo(checkSumInfo{
|
|
|
|
Name: partSuffix,
|
|
|
|
Hash: checkSums[index],
|
|
|
|
Algorithm: bitRotAlgo,
|
|
|
|
})
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write all the checksum metadata.
|
2016-11-22 19:52:37 -05:00
|
|
|
newUUID := mustGetUUID()
|
2016-11-20 17:25:43 -05:00
|
|
|
tempXLMetaPath := newUUID
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-07-19 22:24:32 -04:00
|
|
|
// Writes a unique `xl.json` each disk carrying new checksum related information.
|
2016-11-20 17:25:43 -05:00
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempXLMetaPath, partsMetadata, xl.writeQuorum); err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaTmpBucket, tempXLMetaPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-11-22 16:15:06 -05:00
|
|
|
rErr := commitXLMetadata(onlineDisks, minioMetaTmpBucket, tempXLMetaPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum)
|
2016-05-28 18:13:15 -04:00
|
|
|
if rErr != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return "", toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return success.
|
2016-05-20 23:48:47 -04:00
|
|
|
return newMD5Hex, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// listObjectParts - wrapper reading `xl.json` for a given object and
|
|
|
|
// uploadID. Lists all the parts captured inside `xl.json` content.
|
|
|
|
func (xl xlObjects) listObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, error) {
|
2016-05-20 23:48:47 -04:00
|
|
|
result := ListPartsInfo{}
|
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
xlParts, err := xl.readXLMetaParts(minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return ListPartsInfo{}, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
|
|
|
// Populate the result stub.
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
result.MaxParts = maxParts
|
|
|
|
|
|
|
|
// For empty number of parts or maxParts as zero, return right here.
|
2016-09-09 01:38:18 -04:00
|
|
|
if len(xlParts) == 0 || maxParts == 0 {
|
2016-05-25 00:24:20 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit output to maxPartsList.
|
|
|
|
if maxParts > maxPartsList {
|
|
|
|
maxParts = maxPartsList
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Only parts with higher part numbers will be listed.
|
2016-09-09 01:38:18 -04:00
|
|
|
partIdx := objectPartIndex(xlParts, partNumberMarker)
|
|
|
|
parts := xlParts
|
2016-05-25 00:24:20 -04:00
|
|
|
if partIdx != -1 {
|
2016-09-09 01:38:18 -04:00
|
|
|
parts = xlParts[partIdx+1:]
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
count := maxParts
|
2016-05-25 00:24:20 -04:00
|
|
|
for _, part := range parts {
|
2016-05-25 04:33:39 -04:00
|
|
|
var fi FileInfo
|
2016-06-07 21:15:04 -04:00
|
|
|
fi, err = xl.statPart(bucket, object, uploadID, part.Name)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2016-06-07 21:15:04 -04:00
|
|
|
return ListPartsInfo{}, toObjectErr(err, minioMetaBucket, path.Join(uploadID, part.Name))
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
result.Parts = append(result.Parts, partInfo{
|
2016-05-25 00:24:20 -04:00
|
|
|
PartNumber: part.Number,
|
2016-05-20 23:48:47 -04:00
|
|
|
ETag: part.ETag,
|
|
|
|
LastModified: fi.ModTime,
|
2016-05-28 03:18:58 -04:00
|
|
|
Size: part.Size,
|
2016-05-20 23:48:47 -04:00
|
|
|
})
|
|
|
|
count--
|
|
|
|
if count == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If listed entries are more than maxParts, we set IsTruncated as true.
|
|
|
|
if len(parts) > len(result.Parts) {
|
|
|
|
result.IsTruncated = true
|
|
|
|
// Make sure to fill next part number marker if IsTruncated is
|
|
|
|
// true for subsequent listing.
|
|
|
|
nextPartNumberMarker := result.Parts[len(result.Parts)-1].PartNumber
|
|
|
|
result.NextPartNumberMarker = nextPartNumberMarker
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// ListObjectParts - lists all previously uploaded parts for a given
|
|
|
|
// object and uploadID. Takes additional input of part-number-marker
|
|
|
|
// to indicate where the listing should begin from.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible ListObjectParts API. The resulting
|
|
|
|
// ListPartsInfo structure is unmarshalled directly into XML and
|
|
|
|
// replied back to the client.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (ListPartsInfo, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkListPartsArgs(bucket, object, xl); err != nil {
|
|
|
|
return ListPartsInfo{}, err
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold lock so that there is no competing
|
|
|
|
// abort-multipart-upload or complete-multipart-upload.
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2016-11-09 13:58:41 -05:00
|
|
|
uploadIDLock.Lock()
|
|
|
|
defer uploadIDLock.Unlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
|
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListPartsInfo{}, traceError(InvalidUploadID{UploadID: uploadID})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
result, err := xl.listObjectParts(bucket, object, uploadID, partNumberMarker, maxParts)
|
|
|
|
return result, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// CompleteMultipartUpload - completes an ongoing multipart
|
|
|
|
// transaction after receiving all the parts indicated by the client.
|
|
|
|
// Returns an md5sum calculated by concatenating all the individual
|
|
|
|
// md5sums of all the parts.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Complete multipart API.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, uploadID string, parts []completePart) (string, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkCompleteMultipartArgs(bucket, object, xl); err != nil {
|
|
|
|
return "", err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Hold lock so that
|
2016-11-09 13:58:41 -05:00
|
|
|
//
|
2016-05-20 23:48:47 -04:00
|
|
|
// 1) no one aborts this multipart upload
|
2016-11-09 13:58:41 -05:00
|
|
|
//
|
|
|
|
// 2) no one does a parallel complete-multipart-upload on this
|
|
|
|
// multipart upload
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2016-11-09 13:58:41 -05:00
|
|
|
uploadIDLock.Lock()
|
|
|
|
defer uploadIDLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-05-28 00:50:09 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-28 00:50:09 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
// Calculate s3 compatible md5sum for complete multipart.
|
2016-11-10 10:41:02 -05:00
|
|
|
s3MD5, err := getCompleteMultipartMD5(parts)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := pathJoin(bucket, object, uploadID)
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs := readAllXLMetadata(xl.storageDisks, minioMetaMultipartBucket, uploadIDPath)
|
2016-06-27 13:01:09 -04:00
|
|
|
// Do we have writeQuorum?.
|
2016-07-13 03:29:48 -04:00
|
|
|
if !isDiskQuorum(errs, xl.writeQuorum) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", toObjectErr(traceError(errXLWriteQuorum), bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.storageDisks, partsMetadata, errs)
|
2016-07-14 17:59:01 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Calculate full object size.
|
2016-05-20 23:48:47 -04:00
|
|
|
var objectSize int64
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
// Order online disks in accordance with distribution order.
|
|
|
|
onlineDisks = getOrderedDisks(xlMeta.Erasure.Distribution, onlineDisks)
|
|
|
|
|
|
|
|
// Order parts metadata in accordance with distribution order.
|
|
|
|
partsMetadata = getOrderedPartsMetadata(xlMeta.Erasure.Distribution, partsMetadata)
|
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Save current xl meta for validation.
|
|
|
|
var currentXLMeta = xlMeta
|
|
|
|
|
|
|
|
// Allocate parts similar to incoming slice.
|
|
|
|
xlMeta.Parts = make([]objectPartInfo, len(parts))
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Validate each part and then commit to disk.
|
2016-05-20 23:48:47 -04:00
|
|
|
for i, part := range parts {
|
2016-09-09 01:38:18 -04:00
|
|
|
partIdx := objectPartIndex(currentXLMeta.Parts, part.PartNumber)
|
2016-06-19 17:51:20 -04:00
|
|
|
// All parts should have same part number.
|
2016-05-25 00:24:20 -04:00
|
|
|
if partIdx == -1 {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(InvalidPart{})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
|
|
|
// All parts should have same ETag as previously generated.
|
2016-05-25 00:24:20 -04:00
|
|
|
if currentXLMeta.Parts[partIdx].ETag != part.ETag {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BadDigest{})
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// All parts except the last part has to be atleast 5MB.
|
2016-05-25 00:24:20 -04:00
|
|
|
if (i < len(parts)-1) && !isMinAllowedPartSize(currentXLMeta.Parts[partIdx].Size) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(PartTooSmall{
|
2016-06-28 17:51:49 -04:00
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
PartSize: currentXLMeta.Parts[partIdx].Size,
|
|
|
|
PartETag: part.ETag,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-06-19 17:51:20 -04:00
|
|
|
// Last part could have been uploaded as 0bytes, do not need
|
|
|
|
// to save it in final `xl.json`.
|
|
|
|
if (i == len(parts)-1) && currentXLMeta.Parts[partIdx].Size == 0 {
|
|
|
|
xlMeta.Parts = xlMeta.Parts[:i] // Skip the part.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Save for total object size.
|
|
|
|
objectSize += currentXLMeta.Parts[partIdx].Size
|
|
|
|
|
|
|
|
// Add incoming parts.
|
|
|
|
xlMeta.Parts[i] = objectPartInfo{
|
|
|
|
Number: part.PartNumber,
|
|
|
|
ETag: part.ETag,
|
|
|
|
Size: currentXLMeta.Parts[partIdx].Size,
|
2016-06-28 00:42:33 -04:00
|
|
|
Name: fmt.Sprintf("part.%d", part.PartNumber),
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if an object is present as one of the parent dir.
|
|
|
|
if xl.parentDirIsObject(bucket, path.Dir(object)) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", toObjectErr(traceError(errFileAccessDenied), bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the final object size and modtime.
|
|
|
|
xlMeta.Stat.Size = objectSize
|
|
|
|
xlMeta.Stat.ModTime = time.Now().UTC()
|
|
|
|
|
|
|
|
// Save successfully calculated md5sum.
|
|
|
|
xlMeta.Meta["md5Sum"] = s3MD5
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath = path.Join(bucket, object, uploadID)
|
2016-11-20 17:25:43 -05:00
|
|
|
tempUploadIDPath := uploadID
|
2016-05-31 23:23:31 -04:00
|
|
|
|
|
|
|
// Update all xl metadata, make sure to not modify fields like
|
|
|
|
// checksum which are different on each disks.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index].Stat = xlMeta.Stat
|
|
|
|
partsMetadata[index].Meta = xlMeta.Meta
|
|
|
|
partsMetadata[index].Parts = xlMeta.Parts
|
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Write unique `xl.json` for each disk.
|
2016-11-20 17:25:43 -05:00
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempUploadIDPath, partsMetadata, xl.writeQuorum); err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaTmpBucket, tempUploadIDPath)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
2016-11-22 16:15:06 -05:00
|
|
|
rErr := commitXLMetadata(onlineDisks, minioMetaTmpBucket, tempUploadIDPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum)
|
2016-05-28 18:13:15 -04:00
|
|
|
if rErr != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return "", toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
defer func() {
|
2016-12-08 23:35:07 -05:00
|
|
|
if xl.objCacheEnabled {
|
|
|
|
// A new complete multipart upload invalidates any
|
|
|
|
// previously cached object in memory.
|
|
|
|
xl.objCache.Delete(path.Join(bucket, object))
|
2016-07-08 23:34:27 -04:00
|
|
|
|
2016-12-08 23:35:07 -05:00
|
|
|
// Prefetch the object from disk by triggering a fake GetObject call
|
|
|
|
// Unlike a regular single PutObject, multipart PutObject is comes in
|
|
|
|
// stages and it is harder to cache.
|
|
|
|
go xl.GetObject(bucket, object, 0, objectSize, ioutil.Discard)
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
}()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename if an object already exists to temporary location.
|
2016-11-22 19:52:37 -05:00
|
|
|
uniqueID := mustGetUUID()
|
2016-06-20 09:18:47 -04:00
|
|
|
if xl.isObject(bucket, object) {
|
2016-07-27 14:57:08 -04:00
|
|
|
// NOTE: Do not use online disks slice here.
|
|
|
|
// The reason is that existing object should be purged
|
|
|
|
// regardless of `xl.json` status and rolled back in case of errors.
|
2016-11-20 17:25:43 -05:00
|
|
|
err = renameObject(xl.storageDisks, bucket, object, minioMetaTmpBucket, uniqueID, xl.writeQuorum)
|
2016-06-20 09:18:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", toObjectErr(err, bucket, object)
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-10 09:13:16 -04:00
|
|
|
// Remove parts that weren't present in CompleteMultipartUpload request.
|
2016-05-28 16:23:08 -04:00
|
|
|
for _, curpart := range currentXLMeta.Parts {
|
2016-09-09 01:38:18 -04:00
|
|
|
if objectPartIndex(xlMeta.Parts, curpart.Number) == -1 {
|
2016-05-28 16:23:08 -04:00
|
|
|
// Delete the missing part files. e.g,
|
|
|
|
// Request 1: NewMultipart
|
|
|
|
// Request 2: PutObjectPart 1
|
|
|
|
// Request 3: PutObjectPart 2
|
|
|
|
// Request 4: CompleteMultipartUpload --part 2
|
|
|
|
// N.B. 1st part is not present. This part should be removed from the storage.
|
|
|
|
xl.removeObjectPart(bucket, object, uploadID, curpart.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename the multipart object to final location.
|
2016-11-22 16:15:06 -05:00
|
|
|
if err = renameObject(onlineDisks, minioMetaMultipartBucket, uploadIDPath, bucket, object, xl.writeQuorum); err != nil {
|
2016-05-20 23:48:47 -04:00
|
|
|
return "", toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Delete the previously successfully renamed object.
|
2016-11-20 17:25:43 -05:00
|
|
|
xl.deleteObject(minioMetaTmpBucket, uniqueID)
|
2016-05-29 03:42:09 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold the lock so that two parallel
|
|
|
|
// complete-multipart-uploads do not leave a stale
|
|
|
|
// uploads.json behind.
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2016-11-09 13:58:41 -05:00
|
|
|
objectMPartPathLock.Lock()
|
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-10-30 12:27:29 -04:00
|
|
|
// remove entry from uploads.json with quorum
|
2016-11-22 18:29:39 -05:00
|
|
|
if err = xl.removeUploadID(bucket, object, uploadID); err != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return "", toObjectErr(err, minioMetaMultipartBucket, path.Join(bucket, object))
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return md5sum.
|
|
|
|
return s3MD5, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// abortMultipartUpload - wrapper for purging an ongoing multipart
|
|
|
|
// transaction, deletes uploadID entry from `uploads.json` and purges
|
2016-09-06 23:31:50 -04:00
|
|
|
// the directory at '.minio.sys/multipart/bucket/object/uploadID' holding
|
2016-06-01 19:43:31 -04:00
|
|
|
// all the upload parts.
|
|
|
|
func (xl xlObjects) abortMultipartUpload(bucket, object, uploadID string) (err error) {
|
|
|
|
// Cleanup all uploaded parts.
|
|
|
|
if err = cleanupUploadedParts(bucket, object, uploadID, xl.storageDisks...); err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// hold lock so we don't compete with a complete, or abort
|
|
|
|
// multipart request.
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2016-11-09 13:58:41 -05:00
|
|
|
objectMPartPathLock.Lock()
|
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-10-30 12:27:29 -04:00
|
|
|
|
|
|
|
// remove entry from uploads.json with quorum
|
2016-11-22 18:29:39 -05:00
|
|
|
if err = xl.removeUploadID(bucket, object, uploadID); err != nil {
|
2016-06-01 19:43:31 -04:00
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Successfully purged.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AbortMultipartUpload - aborts an ongoing multipart operation
|
|
|
|
// signified by the input uploadID. This is an atomic operation
|
|
|
|
// doesn't require clients to initiate multiple such requests.
|
|
|
|
//
|
|
|
|
// All parts are purged from all disks and reference to the uploadID
|
|
|
|
// would be removed from the system, rollback is not possible on this
|
|
|
|
// operation.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Abort multipart API, slight difference is
|
|
|
|
// that this is an atomic idempotent operation. Subsequent calls have
|
|
|
|
// no affect and further requests to the same uploadID would not be honored.
|
|
|
|
func (xl xlObjects) AbortMultipartUpload(bucket, object, uploadID string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkAbortMultipartArgs(bucket, object, xl); err != nil {
|
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold lock so that there is no competing
|
|
|
|
// complete-multipart-upload or put-object-part.
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2016-11-09 13:58:41 -05:00
|
|
|
uploadIDLock.Lock()
|
|
|
|
defer uploadIDLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-05-28 16:23:08 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-28 16:23:08 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
err := xl.abortMultipartUpload(bucket, object, uploadID)
|
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|