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"
|
|
|
|
"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-06-01 19:43:31 -04:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
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 '/'.
|
|
|
|
multipartPrefixPath := pathJoin(mpartMetaPrefix, bucket, prefix)
|
|
|
|
if prefix == "" {
|
|
|
|
// Should have a trailing "/" if prefix is ""
|
|
|
|
// For ex. multipartPrefixPath should be "multipart/bucket/" if prefix is ""
|
|
|
|
multipartPrefixPath += slashSeparator
|
|
|
|
}
|
|
|
|
multipartMarkerPath := ""
|
|
|
|
if keyMarker != "" {
|
|
|
|
multipartMarkerPath = pathJoin(mpartMetaPrefix, bucket, keyMarker)
|
|
|
|
}
|
|
|
|
var uploads []uploadMetadata
|
|
|
|
var err error
|
|
|
|
var eof bool
|
|
|
|
// List all upload ids for the keyMarker starting from
|
|
|
|
// uploadIDMarker first.
|
|
|
|
if uploadIDMarker != "" {
|
2016-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
|
|
|
nsMutex.RLock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, keyMarker), opsID)
|
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
|
|
|
|
}
|
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.RUnlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, keyMarker), opsID)
|
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-08-17 14:36:33 -04:00
|
|
|
walkerCh, walkerDoneCh = xl.listPool.Release(listParams{minioMetaBucket, 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-07-21 03:27:08 -04:00
|
|
|
listDir := listDirFactory(isLeaf, xl.getLoadBalancedDisks()...)
|
2016-07-17 18:16:52 -04:00
|
|
|
walkerCh = startTreeWalk(minioMetaBucket, 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-07-08 01:10:27 -04:00
|
|
|
if isErrIgnored(walkResult.err, walkResultIgnoredErrs) {
|
2016-06-01 19:43:31 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return ListMultipartsInfo{}, err
|
|
|
|
}
|
|
|
|
entry := strings.TrimPrefix(walkResult.entry, retainSlash(pathJoin(mpartMetaPrefix, bucket)))
|
|
|
|
// 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
|
|
|
|
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// For the new object entry we get all its pending uploadIDs.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.RLock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, entry), opsID)
|
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
|
|
|
|
}
|
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.RUnlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, entry), opsID)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
2016-07-08 01:10:27 -04:00
|
|
|
if isErrIgnored(err, walkResultIgnoredErrs) {
|
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) {
|
|
|
|
result := ListMultipartsInfo{}
|
|
|
|
|
|
|
|
// Verify if bucket is valid.
|
2016-05-20 23:48:47 -04:00
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListMultipartsInfo{}, traceError(BucketNameInvalid{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListMultipartsInfo{}, traceError(BucketNotFound{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
if !IsValidObjectPrefix(prefix) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListMultipartsInfo{}, traceError(ObjectNameInvalid{Bucket: bucket, Object: prefix})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
// Verify if delimiter is anything other than '/', which we do not support.
|
|
|
|
if delimiter != "" && delimiter != slashSeparator {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListMultipartsInfo{}, traceError(UnsupportedDelimiter{
|
2016-06-01 19:43:31 -04:00
|
|
|
Delimiter: delimiter,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
// Verify if marker has prefix.
|
|
|
|
if keyMarker != "" && !strings.HasPrefix(keyMarker, prefix) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListMultipartsInfo{}, traceError(InvalidMarkerPrefixCombination{
|
2016-06-01 19:43:31 -04:00
|
|
|
Marker: keyMarker,
|
|
|
|
Prefix: prefix,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
if uploadIDMarker != "" {
|
|
|
|
if strings.HasSuffix(keyMarker, slashSeparator) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return result, traceError(InvalidUploadIDKeyCombination{
|
2016-06-01 19:43:31 -04:00
|
|
|
UploadIDMarker: uploadIDMarker,
|
|
|
|
KeyMarker: keyMarker,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
id, err := uuid.Parse(uploadIDMarker)
|
|
|
|
if err != nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
return result, traceError(err)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
if id.IsZero() {
|
2016-08-25 12:39:01 -04:00
|
|
|
return result, traceError(MalformedUploadID{
|
2016-06-01 19:43:31 -04:00
|
|
|
UploadID: uploadIDMarker,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04: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
|
|
|
|
// request, returns back a unique upload id.
|
|
|
|
//
|
|
|
|
// Internally this function creates 'uploads.json' associated for the
|
2016-09-06 23:31:50 -04:00
|
|
|
// incoming object at '.minio.sys/multipart/bucket/object/uploads.json' on
|
2016-06-01 19:43:31 -04:00
|
|
|
// all the disks. `uploads.json` carries metadata regarding on going
|
|
|
|
// multipart operation on the object.
|
|
|
|
func (xl xlObjects) newMultipartUpload(bucket string, object string, meta map[string]string) (uploadID string, err 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-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
2016-09-06 23:31:50 -04:00
|
|
|
// This lock needs to be held for any changes to the directory contents of ".minio.sys/multipart/object/"
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
uploadID = getUUID()
|
|
|
|
initiated := time.Now().UTC()
|
|
|
|
// Create 'uploads.json'
|
2016-06-29 05:10:40 -04:00
|
|
|
if err = xl.writeUploadJSON(bucket, object, uploadID, initiated); err != nil {
|
2016-05-20 23:48:47 -04:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
uploadIDPath := path.Join(mpartMetaPrefix, bucket, object, uploadID)
|
2016-05-29 03:42:09 -04:00
|
|
|
tempUploadIDPath := path.Join(tmpMetaPrefix, uploadID)
|
2016-06-02 19:34:15 -04:00
|
|
|
// Write updated `xl.json` to all disks.
|
2016-07-11 20:24:49 -04:00
|
|
|
if err = writeSameXLMetadata(xl.storageDisks, minioMetaBucket, tempUploadIDPath, xlMeta, xl.writeQuorum, xl.readQuorum); err != nil {
|
2016-05-20 23:48:47 -04:00
|
|
|
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
|
|
|
}
|
2016-07-19 22:24:32 -04:00
|
|
|
rErr := renameObject(xl.storageDisks, minioMetaBucket, tempUploadIDPath, minioMetaBucket, uploadIDPath, xl.writeQuorum)
|
2016-05-25 04:33:39 -04:00
|
|
|
if rErr == nil {
|
|
|
|
// Return success.
|
|
|
|
return uploadID, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 04:33:39 -04:00
|
|
|
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
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-06-01 19:43:31 -04:00
|
|
|
// Verify if bucket name is valid.
|
2016-05-20 23:48:47 -04:00
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNameInvalid{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
// Verify whether the bucket exists.
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNotFound{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
// Verify if object name is valid.
|
2016-05-20 23:48:47 -04:00
|
|
|
if !IsValidObjectName(object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(ObjectNameInvalid{Bucket: bucket, Object: object})
|
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.
|
|
|
|
func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, error) {
|
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNameInvalid{Bucket: bucket})
|
2016-07-05 04:04:50 -04:00
|
|
|
}
|
|
|
|
// Verify whether the bucket exists.
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNotFound{Bucket: bucket})
|
2016-07-05 04:04:50 -04:00
|
|
|
}
|
|
|
|
if !IsValidObjectName(object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(ObjectNameInvalid{Bucket: bucket, Object: object})
|
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
|
|
|
|
uploadIDPath := pathJoin(mpartMetaPrefix, bucket, object, uploadID)
|
2016-08-31 14:39:08 -04:00
|
|
|
|
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
|
|
|
nsMutex.RLock(minioMetaBucket, uploadIDPath, opsID)
|
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-08-31 14:39:08 -04:00
|
|
|
nsMutex.RUnlock(minioMetaBucket, uploadIDPath, opsID)
|
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-07-11 20:24:49 -04:00
|
|
|
partsMetadata, errs = readAllXLMetadata(xl.storageDisks, minioMetaBucket,
|
|
|
|
uploadIDPath)
|
2016-07-13 03:29:48 -04:00
|
|
|
if !isDiskQuorum(errs, xl.writeQuorum) {
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.RUnlock(minioMetaBucket, uploadIDPath, opsID)
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", toObjectErr(traceError(errXLWriteQuorum), bucket, object)
|
2016-06-27 13:01:09 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.RUnlock(minioMetaBucket, uploadIDPath, opsID)
|
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-07-14 17:59:01 -04:00
|
|
|
xlMeta := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
|
|
|
|
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-07-11 20:24:49 -04:00
|
|
|
tmpSuffix := getUUID()
|
2016-07-12 12:38:45 -04:00
|
|
|
tmpPartPath := path.Join(tmpMetaPrefix, tmpSuffix)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
// Initialize md5 writer.
|
|
|
|
md5Writer := md5.New()
|
|
|
|
|
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-07-05 04:04:50 -04:00
|
|
|
data = io.LimitReader(data, size)
|
2016-07-01 17:33:28 -04:00
|
|
|
} // else we read till EOF.
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Construct a tee reader for md5sum.
|
|
|
|
teeReader := io.TeeReader(data, md5Writer)
|
2016-05-29 18:38:14 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Erasure code data and write across all disks.
|
2016-07-28 05:20:34 -04:00
|
|
|
sizeWritten, checkSums, err := erasureCreateFile(onlineDisks, minioMetaBucket, 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
|
|
|
}
|
|
|
|
// 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-07-05 04:04:50 -04:00
|
|
|
// Validate if payload is valid.
|
|
|
|
if isSignVerify(data) {
|
|
|
|
if err = data.(*signVerifyReader).Verify(); err != nil {
|
|
|
|
// Incoming payload wrong, delete the temporary object.
|
|
|
|
xl.deleteObject(minioMetaBucket, tmpPartPath)
|
|
|
|
// Returns md5 mismatch.
|
|
|
|
return "", toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// MD5 mismatch, delete the temporary object.
|
|
|
|
xl.deleteObject(minioMetaBucket, tmpPartPath)
|
|
|
|
// 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-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID = getOpsID()
|
|
|
|
|
|
|
|
nsMutex.Lock(minioMetaBucket, uploadIDPath, opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, uploadIDPath, opsID)
|
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-07-19 22:24:32 -04:00
|
|
|
err = renamePart(onlineDisks, minioMetaBucket, tmpPartPath, minioMetaBucket, partPath, xl.writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaBucket, partPath)
|
|
|
|
}
|
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-07-12 18:20:31 -04:00
|
|
|
partsMetadata, errs = readAllXLMetadata(onlineDisks, minioMetaBucket, 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-07-14 17:59:01 -04:00
|
|
|
xlMeta = pickValidXLMeta(partsMetadata, modTime)
|
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-06-30 19:28:01 -04:00
|
|
|
newUUID := getUUID()
|
|
|
|
tempXLMetaPath := path.Join(tmpMetaPrefix, 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.
|
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaBucket, tempXLMetaPath, partsMetadata, xl.writeQuorum); err != nil {
|
2016-06-30 19:28:01 -04:00
|
|
|
return "", toObjectErr(err, minioMetaBucket, tempXLMetaPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-07-19 22:24:32 -04:00
|
|
|
rErr := commitXLMetadata(onlineDisks, tempXLMetaPath, uploadIDPath, xl.writeQuorum)
|
2016-05-28 18:13:15 -04:00
|
|
|
if rErr != nil {
|
|
|
|
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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{}
|
|
|
|
|
|
|
|
uploadIDPath := path.Join(mpartMetaPrefix, bucket, object, uploadID)
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-09-09 01:38:18 -04:00
|
|
|
xlParts, err := xl.readXLMetaParts(minioMetaBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return ListPartsInfo{}, toObjectErr(err, minioMetaBucket, uploadIDPath)
|
|
|
|
}
|
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-06-01 19:43:31 -04:00
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListPartsInfo{}, traceError(BucketNameInvalid{Bucket: bucket})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
// Verify whether the bucket exists.
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListPartsInfo{}, traceError(BucketNotFound{Bucket: bucket})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
if !IsValidObjectName(object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return ListPartsInfo{}, traceError(ObjectNameInvalid{Bucket: bucket, Object: object})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Hold lock so that there is no competing abort-multipart-upload or complete-multipart-upload.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
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) {
|
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNameInvalid{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
// Verify whether the bucket exists.
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(BucketNotFound{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
if !IsValidObjectName(object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return "", traceError(ObjectNameInvalid{
|
2016-05-20 23:48:47 -04:00
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Hold lock so that
|
|
|
|
// 1) no one aborts this multipart upload
|
|
|
|
// 2) no one does a parallel complete-multipart-upload on this multipart upload
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
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.
|
|
|
|
s3MD5, err := completeMultipartMD5(parts...)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadIDPath := pathJoin(mpartMetaPrefix, 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-07-11 20:24:49 -04:00
|
|
|
partsMetadata, errs := readAllXLMetadata(xl.storageDisks, minioMetaBucket, 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-07-14 17:59:01 -04:00
|
|
|
xlMeta := pickValidXLMeta(partsMetadata, modTime)
|
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-05-28 18:13:15 -04:00
|
|
|
uploadIDPath = path.Join(mpartMetaPrefix, bucket, object, uploadID)
|
2016-05-29 03:42:09 -04:00
|
|
|
tempUploadIDPath := path.Join(tmpMetaPrefix, 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-07-27 14:57:08 -04:00
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaBucket, tempUploadIDPath, partsMetadata, xl.writeQuorum); err != nil {
|
2016-05-28 18:13:15 -04:00
|
|
|
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
|
|
|
}
|
2016-07-27 14:57:08 -04:00
|
|
|
rErr := commitXLMetadata(onlineDisks, tempUploadIDPath, uploadIDPath, xl.writeQuorum)
|
2016-05-28 18:13:15 -04:00
|
|
|
if rErr != nil {
|
|
|
|
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID = getOpsID()
|
|
|
|
|
2016-06-10 09:13:16 -04:00
|
|
|
// Hold write lock on the destination before rename.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(bucket, object, opsID)
|
2016-07-08 23:34:27 -04:00
|
|
|
defer func() {
|
|
|
|
// A new complete multipart upload invalidates any
|
|
|
|
// previously cached object in memory.
|
|
|
|
xl.objCache.Delete(path.Join(bucket, object))
|
|
|
|
|
|
|
|
// This lock also protects the cache namespace.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Unlock(bucket, object, opsID)
|
2016-07-08 23:34:27 -04:00
|
|
|
|
2016-08-15 05:44:48 -04:00
|
|
|
// Prefetch the object from disk by triggering a fake GetObject call
|
2016-07-08 23:34:27 -04:00
|
|
|
// 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-05-20 23:48:47 -04:00
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename if an object already exists to temporary location.
|
|
|
|
uniqueID := getUUID()
|
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-07-19 22:24:32 -04:00
|
|
|
err = renameObject(xl.storageDisks, bucket, object, minioMetaBucket, path.Join(tmpMetaPrefix, 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-07-27 14:57:08 -04:00
|
|
|
if err = renameObject(onlineDisks, minioMetaBucket, 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.
|
|
|
|
xl.deleteObject(minioMetaBucket, path.Join(tmpMetaPrefix, uniqueID))
|
|
|
|
|
2016-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID = getOpsID()
|
|
|
|
|
2016-06-02 18:54:00 -04:00
|
|
|
// Hold the lock so that two parallel complete-multipart-uploads do not
|
2016-05-20 23:48:47 -04:00
|
|
|
// leave a stale uploads.json behind.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
// Validate if there are other incomplete upload-id's present for
|
|
|
|
// the object, if yes do not attempt to delete 'uploads.json'.
|
2016-07-24 21:08:15 -04:00
|
|
|
uploadsJSON, err := xl.readUploadsJSON(bucket, object)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaBucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
// If we have successfully read `uploads.json`, then we proceed to
|
|
|
|
// purge or update `uploads.json`.
|
|
|
|
uploadIDIdx := uploadsJSON.Index(uploadID)
|
|
|
|
if uploadIDIdx != -1 {
|
|
|
|
uploadsJSON.Uploads = append(uploadsJSON.Uploads[:uploadIDIdx], uploadsJSON.Uploads[uploadIDIdx+1:]...)
|
|
|
|
}
|
|
|
|
if len(uploadsJSON.Uploads) > 0 {
|
2016-06-29 05:10:40 -04:00
|
|
|
if err = xl.updateUploadsJSON(bucket, object, uploadsJSON); err != nil {
|
2016-06-01 19:43:31 -04:00
|
|
|
return "", toObjectErr(err, minioMetaBucket, path.Join(mpartMetaPrefix, bucket, object))
|
|
|
|
}
|
|
|
|
// Return success.
|
|
|
|
return s3MD5, nil
|
|
|
|
} // No more pending uploads for the object, proceed to delete
|
2016-09-06 23:31:50 -04:00
|
|
|
// object completely from '.minio.sys/multipart'.
|
2016-06-17 14:57:51 -04:00
|
|
|
if err = xl.deleteObject(minioMetaBucket, path.Join(mpartMetaPrefix, bucket, object)); err != nil {
|
2016-05-20 23:48:47 -04:00
|
|
|
return "", toObjectErr(err, minioMetaBucket, path.Join(mpartMetaPrefix, bucket, object))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object), opsID)
|
2016-06-01 19:43:31 -04:00
|
|
|
// Validate if there are other incomplete upload-id's present for
|
|
|
|
// the object, if yes do not attempt to delete 'uploads.json'.
|
2016-07-24 21:08:15 -04:00
|
|
|
uploadsJSON, err := xl.readUploadsJSON(bucket, object)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
uploadIDIdx := uploadsJSON.Index(uploadID)
|
|
|
|
if uploadIDIdx != -1 {
|
|
|
|
uploadsJSON.Uploads = append(uploadsJSON.Uploads[:uploadIDIdx], uploadsJSON.Uploads[uploadIDIdx+1:]...)
|
|
|
|
}
|
|
|
|
if len(uploadsJSON.Uploads) > 0 {
|
|
|
|
// There are pending uploads for the same object, preserve
|
|
|
|
// them update 'uploads.json' in-place.
|
2016-06-29 05:10:40 -04:00
|
|
|
err = xl.updateUploadsJSON(bucket, object, uploadsJSON)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
} // No more pending uploads for the object, we purge the entire
|
2016-09-06 23:31:50 -04:00
|
|
|
// entry at '.minio.sys/multipart/bucket/object'.
|
2016-06-01 19:43:31 -04:00
|
|
|
if err = xl.deleteObject(minioMetaBucket, path.Join(mpartMetaPrefix, bucket, object)); err != nil {
|
|
|
|
return toObjectErr(err, minioMetaBucket, path.Join(mpartMetaPrefix, 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-05-20 23:48:47 -04:00
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !IsValidBucketName(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(BucketNameInvalid{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
if !xl.isBucketExist(bucket) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(BucketNotFound{Bucket: bucket})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
if !IsValidObjectName(object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(ObjectNameInvalid{Bucket: bucket, Object: object})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-08-31 14:39:08 -04:00
|
|
|
// generates random string on setting MINIO_DEBUG=lock, else returns empty string.
|
|
|
|
// used for instrumentation on locks.
|
|
|
|
opsID := getOpsID()
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Hold lock so that there is no competing complete-multipart-upload or put-object-part.
|
2016-08-31 14:39:08 -04:00
|
|
|
nsMutex.Lock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
|
|
|
defer nsMutex.Unlock(minioMetaBucket, pathJoin(mpartMetaPrefix, bucket, object, uploadID), opsID)
|
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
|
|
|
}
|