2016-05-21 05:48:47 +02:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017, 2018 MinIO, Inc.
|
2016-05-21 05:48:47 +02:00
|
|
|
*
|
|
|
|
* 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-19 01:23:42 +02:00
|
|
|
package cmd
|
2016-05-21 05:48:47 +02:00
|
|
|
|
|
|
|
import (
|
2018-03-14 20:01:47 +01:00
|
|
|
"context"
|
2016-05-21 05:48:47 +02:00
|
|
|
"fmt"
|
2019-01-17 13:58:18 +01:00
|
|
|
"io"
|
2016-05-21 05:48:47 +02:00
|
|
|
"path"
|
2018-03-15 21:55:23 +01:00
|
|
|
"sort"
|
2018-09-28 05:36:17 +02:00
|
|
|
"strconv"
|
2016-05-24 22:35:43 +02:00
|
|
|
"strings"
|
2016-05-21 05:48:47 +02:00
|
|
|
"time"
|
2016-05-24 22:35:43 +02:00
|
|
|
|
2019-10-07 07:50:24 +02:00
|
|
|
xhttp "github.com/minio/minio/cmd/http"
|
2018-04-06 00:04:40 +02:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2016-05-24 22:35:43 +02:00
|
|
|
"github.com/minio/minio/pkg/mimedb"
|
2019-10-14 18:44:51 +02:00
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
2016-05-21 05:48:47 +02:00
|
|
|
)
|
|
|
|
|
2018-03-15 21:55:23 +01:00
|
|
|
func (xl xlObjects) getUploadIDDir(bucket, object, uploadID string) string {
|
|
|
|
return pathJoin(xl.getMultipartSHADir(bucket, object), uploadID)
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
2018-12-19 22:57:51 +01:00
|
|
|
// getUploadIDLockPath returns the name of the Lock in the form of
|
|
|
|
// bucket/object/uploadID. For locking, the path bucket/object/uploadID
|
|
|
|
// is locked instead of multipart-sha256-Dir/uploadID as it is more
|
|
|
|
// readable in the list-locks output which helps in debugging.
|
|
|
|
func (xl xlObjects) getUploadIDLockPath(bucket, object, uploadID string) string {
|
|
|
|
return pathJoin(bucket, object, uploadID)
|
|
|
|
}
|
|
|
|
|
2018-03-15 21:55:23 +01:00
|
|
|
func (xl xlObjects) getMultipartSHADir(bucket, object string) string {
|
|
|
|
return getSHA256Hash([]byte(pathJoin(bucket, object)))
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
// checkUploadIDExists - verify if a given uploadID exists and is valid.
|
|
|
|
func (xl xlObjects) checkUploadIDExists(ctx context.Context, bucket, object, uploadID string) error {
|
|
|
|
_, err := xl.getObjectInfo(ctx, minioMetaMultipartBucket, xl.getUploadIDDir(bucket, object, uploadID))
|
|
|
|
return err
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Removes part given by partName belonging to a mulitpart upload from minioMetaBucket
|
|
|
|
func (xl xlObjects) removeObjectPart(bucket, object, uploadID, partName string) {
|
|
|
|
curpartPath := path.Join(bucket, object, uploadID, partName)
|
2019-10-14 18:44:51 +02:00
|
|
|
storageDisks := xl.getDisks()
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
|
|
|
for index, disk := range storageDisks {
|
2017-01-26 21:51:12 +01:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 18:44:51 +02:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2017-01-26 21:51:12 +01:00
|
|
|
// Ignoring failure to remove parts that weren't present in CompleteMultipartUpload
|
|
|
|
// requests. xl.json is the authoritative source of truth on which parts constitute
|
|
|
|
// the object. The presence of parts that don't belong in the object doesn't affect correctness.
|
2019-10-14 18:44:51 +02:00
|
|
|
_ = storageDisks[index].DeleteFile(minioMetaMultipartBucket, curpartPath)
|
|
|
|
return nil
|
|
|
|
}, index)
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
2019-10-14 18:44:51 +02:00
|
|
|
g.Wait()
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// statPart - returns fileInfo structure for a successful stat on part file.
|
2018-04-06 00:04:40 +02:00
|
|
|
func (xl xlObjects) statPart(ctx context.Context, bucket, object, uploadID, partName string) (fileInfo FileInfo, err error) {
|
2017-04-14 10:46:16 +02:00
|
|
|
var ignoredErrs []error
|
2018-03-15 21:55:23 +01:00
|
|
|
partNamePath := path.Join(xl.getUploadIDDir(bucket, object, uploadID), partName)
|
2017-01-26 21:51:12 +01:00
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
2017-04-14 10:46:16 +02:00
|
|
|
ignoredErrs = append(ignoredErrs, errDiskNotFound)
|
2017-01-26 21:51:12 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
fileInfo, err = disk.StatFile(minioMetaMultipartBucket, partNamePath)
|
|
|
|
if err == nil {
|
|
|
|
return fileInfo, nil
|
|
|
|
}
|
|
|
|
// For any reason disk was deleted or goes offline we continue to next disk.
|
2018-04-10 18:36:37 +02:00
|
|
|
if IsErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2017-04-14 10:46:16 +02:00
|
|
|
ignoredErrs = append(ignoredErrs, err)
|
2017-01-26 21:51:12 +01:00
|
|
|
continue
|
|
|
|
}
|
2017-04-14 10:46:16 +02:00
|
|
|
// Error is not ignored, return right here.
|
2018-04-06 00:04:40 +02:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return FileInfo{}, err
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
2017-04-14 10:46:16 +02:00
|
|
|
// If all errors were ignored, reduce to maximal occurrence
|
|
|
|
// based on the read quorum.
|
2018-02-16 02:45:57 +01:00
|
|
|
readQuorum := len(xl.getDisks()) / 2
|
2018-04-06 00:04:40 +02:00
|
|
|
return FileInfo{}, reduceReadQuorumErrs(ctx, ignoredErrs, nil, readQuorum)
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// commitXLMetadata - commit `xl.json` from source prefix to destination prefix in the given slice of disks.
|
2018-04-06 00:04:40 +02:00
|
|
|
func commitXLMetadata(ctx context.Context, disks []StorageAPI, srcBucket, srcPrefix, dstBucket, dstPrefix string, quorum int) ([]StorageAPI, error) {
|
2017-01-26 21:51:12 +01:00
|
|
|
srcJSONFile := path.Join(srcPrefix, xlMetaJSONFile)
|
|
|
|
dstJSONFile := path.Join(dstPrefix, xlMetaJSONFile)
|
|
|
|
|
2019-10-14 18:44:51 +02:00
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
|
2017-01-26 21:51:12 +01:00
|
|
|
// Rename `xl.json` to all disks in parallel.
|
2019-10-14 18:44:51 +02:00
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2017-01-26 21:51:12 +01:00
|
|
|
// Delete any dangling directories.
|
2019-10-14 18:44:51 +02:00
|
|
|
defer disks[index].DeleteFile(srcBucket, srcPrefix)
|
2017-01-26 21:51:12 +01:00
|
|
|
|
|
|
|
// Renames `xl.json` from source prefix to destination prefix.
|
2019-10-14 18:44:51 +02:00
|
|
|
return disks[index].RenameFile(srcBucket, srcJSONFile, dstBucket, dstJSONFile)
|
|
|
|
}, index)
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
2019-10-14 18:44:51 +02:00
|
|
|
|
2017-01-26 21:51:12 +01:00
|
|
|
// Wait for all the routines.
|
2019-10-14 18:44:51 +02:00
|
|
|
mErrs := g.Wait()
|
2017-01-26 21:51:12 +01:00
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum)
|
2017-06-15 02:14:27 +02:00
|
|
|
return evalDisks(disks, mErrs), err
|
2017-01-26 21:51:12 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:58:46 +01:00
|
|
|
// ListMultipartUploads - lists all the pending multipart
|
|
|
|
// uploads for a particular object in a bucket.
|
|
|
|
//
|
|
|
|
// Implements minimal S3 compatible ListMultipartUploads API. We do
|
|
|
|
// not support prefix based listing, this is a deliberate attempt
|
|
|
|
// towards simplification of multipart APIs.
|
|
|
|
// The resulting ListMultipartsInfo structure is unmarshalled directly as XML.
|
2018-03-14 20:01:47 +01:00
|
|
|
func (xl xlObjects) ListMultipartUploads(ctx context.Context, bucket, object, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, e error) {
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkListMultipartArgs(ctx, bucket, object, keyMarker, uploadIDMarker, delimiter, xl); err != nil {
|
2018-03-15 21:55:23 +01:00
|
|
|
return result, err
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:58:46 +01:00
|
|
|
result.MaxUploads = maxUploads
|
|
|
|
result.KeyMarker = keyMarker
|
|
|
|
result.Prefix = object
|
|
|
|
result.Delimiter = delimiter
|
|
|
|
|
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
2016-06-03 01:34:15 +02:00
|
|
|
}
|
2019-04-23 23:54:28 +02:00
|
|
|
uploadIDs, err := disk.ListDir(minioMetaMultipartBucket, xl.getMultipartSHADir(bucket, object), -1, "")
|
2016-06-02 01:43:31 +02:00
|
|
|
if err != nil {
|
2018-03-15 21:55:23 +01:00
|
|
|
if err == errFileNotFound {
|
|
|
|
return result, nil
|
|
|
|
}
|
2018-04-06 00:04:40 +02:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return result, err
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
2018-03-15 21:55:23 +01:00
|
|
|
for i := range uploadIDs {
|
2019-08-06 21:08:58 +02:00
|
|
|
uploadIDs[i] = strings.TrimSuffix(uploadIDs[i], SlashSeparator)
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
2018-03-15 21:55:23 +01:00
|
|
|
sort.Strings(uploadIDs)
|
|
|
|
for _, uploadID := range uploadIDs {
|
|
|
|
if len(result.Uploads) == maxUploads {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
result.Uploads = append(result.Uploads, MultipartInfo{Object: object, UploadID: uploadID})
|
2017-12-01 00:58:46 +01:00
|
|
|
}
|
|
|
|
break
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-12-02 08:15:17 +01:00
|
|
|
|
2017-12-01 00:58:46 +01:00
|
|
|
return result, nil
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
|
2016-06-02 01:43:31 +02:00
|
|
|
// newMultipartUpload - wrapper for initializing a new multipart
|
2016-10-25 02:37:18 +02:00
|
|
|
// request; returns a unique upload id.
|
2016-06-02 01:43:31 +02:00
|
|
|
//
|
|
|
|
// Internally this function creates 'uploads.json' associated for the
|
2016-10-25 02:37:18 +02: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.
|
2018-04-06 00:04:40 +02:00
|
|
|
func (xl xlObjects) newMultipartUpload(ctx context.Context, bucket string, object string, meta map[string]string) (string, error) {
|
2017-12-22 12:28:13 +01:00
|
|
|
|
2019-10-07 07:50:24 +02:00
|
|
|
onlineDisks := xl.getDisks()
|
2019-10-23 07:59:13 +02:00
|
|
|
parityBlocks := globalStorageClass.GetParityForSC(meta[xhttp.AmzStorageClass])
|
2019-10-07 07:50:24 +02:00
|
|
|
if parityBlocks == 0 {
|
|
|
|
parityBlocks = len(onlineDisks) / 2
|
|
|
|
}
|
|
|
|
dataBlocks := len(onlineDisks) - parityBlocks
|
2017-12-22 12:28:13 +01:00
|
|
|
|
|
|
|
xlMeta := newXLMetaV1(object, dataBlocks, parityBlocks)
|
|
|
|
|
|
|
|
// we now know the number of blocks this object needs for data and parity.
|
|
|
|
// establish the writeQuorum using this data
|
|
|
|
writeQuorum := dataBlocks + 1
|
|
|
|
|
2016-05-21 05:48:47 +02:00
|
|
|
if meta["content-type"] == "" {
|
2018-10-02 08:18:17 +02:00
|
|
|
contentType := mimedb.TypeByExtension(path.Ext(object))
|
2016-05-24 22:35:43 +02:00
|
|
|
meta["content-type"] = contentType
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2017-03-18 19:28:41 +01:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-05-21 05:48:47 +02:00
|
|
|
xlMeta.Meta = meta
|
|
|
|
|
2016-11-23 01:52:37 +01:00
|
|
|
uploadID := mustGetUUID()
|
2018-03-15 21:55:23 +01:00
|
|
|
uploadIDPath := xl.getUploadIDDir(bucket, object, uploadID)
|
2016-11-20 23:25:43 +01:00
|
|
|
tempUploadIDPath := uploadID
|
2017-08-15 03:08:42 +02:00
|
|
|
|
2019-04-25 16:33:26 +02:00
|
|
|
// Delete the tmp path later in case we fail to commit (ignore
|
|
|
|
// returned errors) - this will be a no-op in case of a commit
|
|
|
|
// success.
|
|
|
|
defer xl.deleteObject(ctx, minioMetaTmpBucket, tempUploadIDPath, writeQuorum, false)
|
|
|
|
|
2019-09-11 19:22:12 +02:00
|
|
|
var partsMetadata = make([]xlMetaV1, len(onlineDisks))
|
|
|
|
for i := range onlineDisks {
|
|
|
|
partsMetadata[i] = xlMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
2016-06-03 01:34:15 +02:00
|
|
|
// Write updated `xl.json` to all disks.
|
2019-09-11 19:22:12 +02:00
|
|
|
onlineDisks, err = writeUniqueXLMetadata(ctx, onlineDisks, minioMetaTmpBucket, tempUploadIDPath, partsMetadata, writeQuorum)
|
2017-01-31 18:38:34 +01:00
|
|
|
if err != nil {
|
2016-11-20 23:25:43 +01:00
|
|
|
return "", toObjectErr(err, minioMetaTmpBucket, tempUploadIDPath)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-10-25 02:37:18 +02:00
|
|
|
|
2017-02-22 04:43:44 +01:00
|
|
|
// Attempt to rename temp upload object to actual upload path object
|
2019-09-11 19:22:12 +02:00
|
|
|
_, err = rename(ctx, onlineDisks, minioMetaTmpBucket, tempUploadIDPath, minioMetaMultipartBucket, uploadIDPath, true, writeQuorum, nil)
|
|
|
|
if err != nil {
|
|
|
|
return "", toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-10-25 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return success.
|
|
|
|
return uploadID, nil
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 01:43:31 +02: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.
|
2019-02-09 06:31:06 +01:00
|
|
|
func (xl xlObjects) NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (string, error) {
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkNewMultipartArgs(ctx, bucket, object, xl); err != nil {
|
2016-12-02 08:15:17 +01:00
|
|
|
return "", err
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-06-02 01:43:31 +02:00
|
|
|
// No metadata is set, allocate a new one.
|
2019-02-09 06:31:06 +01:00
|
|
|
if opts.UserDefined == nil {
|
|
|
|
opts.UserDefined = make(map[string]string)
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
2019-02-09 06:31:06 +01:00
|
|
|
return xl.newMultipartUpload(ctx, bucket, object, opts.UserDefined)
|
2016-06-02 01:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-31 18:38:34 +01:00
|
|
|
// CopyObjectPart - reads incoming stream and internally erasure codes
|
|
|
|
// them. This call is similar to put object part operation but the source
|
|
|
|
// data is read from an existing object.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Upload Part Copy API.
|
2018-09-10 18:42:43 +02:00
|
|
|
func (xl xlObjects) CopyObjectPart(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject, uploadID string, partID int, startOffset int64, length int64, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (pi PartInfo, e error) {
|
2018-01-13 05:34:52 +01:00
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkNewMultipartArgs(ctx, srcBucket, srcObject, xl); err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, err
|
2017-01-31 18:38:34 +01:00
|
|
|
}
|
|
|
|
|
2018-11-15 02:36:41 +01:00
|
|
|
partInfo, err := xl.PutObjectPart(ctx, dstBucket, dstObject, uploadID, partID, NewPutObjReader(srcInfo.Reader, nil, nil), dstOpts)
|
2017-10-22 07:30:34 +02:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, dstBucket, dstObject)
|
|
|
|
}
|
|
|
|
|
2017-01-31 18:38:34 +01:00
|
|
|
// Success.
|
|
|
|
return partInfo, nil
|
|
|
|
}
|
|
|
|
|
2016-07-05 10:04:50 +02: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 07:01:58 +02:00
|
|
|
// of the multipart transaction.
|
2016-07-05 10:04:50 +02:00
|
|
|
//
|
|
|
|
// Implements S3 compatible Upload Part API.
|
2018-11-15 02:36:41 +01:00
|
|
|
func (xl xlObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, r *PutObjReader, opts ObjectOptions) (pi PartInfo, e error) {
|
|
|
|
data := r.Reader
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkPutObjectPartArgs(ctx, bucket, object, xl); err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, err
|
2016-07-05 10:04:50 +02:00
|
|
|
}
|
2016-05-27 10:12:44 +02:00
|
|
|
|
2017-10-06 18:38:01 +02:00
|
|
|
// Validate input data size and it can never be less than zero.
|
2018-09-28 05:36:17 +02:00
|
|
|
if data.Size() < -1 {
|
2019-10-12 03:50:54 +02:00
|
|
|
logger.LogIf(ctx, errInvalidArgument, logger.Application)
|
2018-04-06 00:04:40 +02:00
|
|
|
return pi, toObjectErr(errInvalidArgument)
|
2017-10-06 18:38:01 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 02:24:49 +02:00
|
|
|
var partsMetadata []xlMetaV1
|
|
|
|
var errs []error
|
2018-03-15 21:55:23 +01:00
|
|
|
uploadIDPath := xl.getUploadIDDir(bucket, object, uploadID)
|
2017-10-06 18:38:01 +02:00
|
|
|
|
2016-07-12 02:24:49 +02:00
|
|
|
// Validates if upload ID exists.
|
2019-04-23 23:54:28 +02:00
|
|
|
if err := xl.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object, uploadID)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2017-01-31 18:38:34 +01:00
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Read metadata associated with the object from all disks.
|
2018-04-06 00:04:40 +02:00
|
|
|
partsMetadata, errs = readAllXLMetadata(ctx, xl.getDisks(), minioMetaMultipartBucket,
|
2016-07-12 02:24:49 +02:00
|
|
|
uploadIDPath)
|
2017-12-22 12:28:13 +01:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2018-07-31 09:23:29 +02:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
2017-12-22 12:28:13 +01:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2018-04-10 18:36:37 +02:00
|
|
|
if reducedErr == errXLWriteQuorum {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, toObjectErr(reducedErr, bucket, object)
|
2016-06-27 19:01:09 +02:00
|
|
|
}
|
2016-05-30 20:26:10 +02:00
|
|
|
|
2016-05-26 01:42:31 +02:00
|
|
|
// List all online disks.
|
2018-02-16 02:45:57 +01:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.getDisks(), partsMetadata, errs)
|
2016-07-13 00:20:31 +02:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2018-08-17 23:42:04 +02:00
|
|
|
xlMeta, err := pickValidXLMeta(ctx, partsMetadata, modTime, writeQuorum)
|
2016-11-21 05:56:44 +01:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, err
|
2016-11-21 05:56:44 +01:00
|
|
|
}
|
2016-07-14 23:59:01 +02:00
|
|
|
|
2017-02-24 18:20:40 +01:00
|
|
|
onlineDisks = shuffleDisks(onlineDisks, xlMeta.Erasure.Distribution)
|
2016-05-27 04:55:48 +02:00
|
|
|
|
2016-07-12 02:24:49 +02:00
|
|
|
// Need a unique name for the part being written in minioMetaBucket to
|
|
|
|
// accommodate concurrent PutObjectPart requests
|
2016-07-13 00:20:31 +02:00
|
|
|
|
2016-06-28 06:42:33 +02:00
|
|
|
partSuffix := fmt.Sprintf("part.%d", partID)
|
2016-11-23 01:52:37 +01:00
|
|
|
tmpPart := mustGetUUID()
|
|
|
|
tmpPartPath := path.Join(tmpPart, partSuffix)
|
2016-05-21 05:48:47 +02:00
|
|
|
|
2016-10-20 07:52:03 +02:00
|
|
|
// Delete the temporary object part. If PutObjectPart succeeds there would be nothing to delete.
|
2018-08-29 22:36:19 +02:00
|
|
|
defer xl.deleteObject(ctx, minioMetaTmpBucket, tmpPart, writeQuorum, false)
|
2018-11-26 22:20:21 +01:00
|
|
|
|
2018-08-24 08:35:37 +02:00
|
|
|
erasure, err := NewErasure(ctx, xlMeta.Erasure.DataBlocks, xlMeta.Erasure.ParityBlocks, xlMeta.Erasure.BlockSize)
|
2017-08-15 03:08:42 +02:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
2018-06-13 20:55:12 +02:00
|
|
|
var buffer []byte
|
|
|
|
switch size := data.Size(); {
|
|
|
|
case size == 0:
|
|
|
|
buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF
|
2018-10-06 02:09:50 +02:00
|
|
|
case size == -1 || size >= blockSizeV1:
|
2018-09-28 05:36:17 +02:00
|
|
|
buffer = xl.bp.Get()
|
|
|
|
defer xl.bp.Put(buffer)
|
2018-06-13 20:55:12 +02:00
|
|
|
case size < blockSizeV1:
|
|
|
|
// No need to allocate fully blockSizeV1 buffer if the incoming data is smaller.
|
|
|
|
buffer = make([]byte, size, 2*size)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
2018-08-07 00:14:08 +02:00
|
|
|
if len(buffer) > int(xlMeta.Erasure.BlockSize) {
|
|
|
|
buffer = buffer[:xlMeta.Erasure.BlockSize]
|
|
|
|
}
|
2019-01-17 13:58:18 +01:00
|
|
|
writers := make([]io.Writer, len(onlineDisks))
|
2018-08-07 00:14:08 +02:00
|
|
|
for i, disk := range onlineDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-17 13:58:18 +01:00
|
|
|
writers[i] = newBitrotWriter(disk, minioMetaTmpBucket, tmpPartPath, erasure.ShardFileSize(data.Size()), DefaultBitrotAlgorithm, erasure.ShardSize())
|
2018-08-07 00:14:08 +02:00
|
|
|
}
|
2018-11-26 22:20:21 +01:00
|
|
|
|
2018-08-24 08:35:37 +02:00
|
|
|
n, err := erasure.Encode(ctx, data, writers, buffer, erasure.dataBlocks+1)
|
2019-01-17 13:58:18 +01:00
|
|
|
closeBitrotWriters(writers)
|
2016-07-19 04:06:48 +02:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, toObjectErr(err, bucket, object)
|
2016-07-19 04:06:48 +02:00
|
|
|
}
|
2016-10-20 07:52:03 +02:00
|
|
|
|
2016-07-19 04:06:48 +02:00
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
2018-08-07 00:14:08 +02:00
|
|
|
if n < data.Size() {
|
2018-04-06 00:04:40 +02:00
|
|
|
return pi, IncompleteBody{}
|
2016-07-19 04:06:48 +02:00
|
|
|
}
|
2016-07-01 23:33:28 +02:00
|
|
|
|
2018-08-07 00:14:08 +02:00
|
|
|
for i := range writers {
|
|
|
|
if writers[i] == nil {
|
|
|
|
onlineDisks[i] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
// Validates if upload ID exists.
|
|
|
|
if err := xl.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object, uploadID)
|
2016-05-30 20:26:10 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 00:38:14 +02:00
|
|
|
// Rename temporary part file to its final location.
|
2016-06-01 05:23:31 +02:00
|
|
|
partPath := path.Join(uploadIDPath, partSuffix)
|
2018-10-05 02:22:49 +02:00
|
|
|
onlineDisks, err = rename(ctx, onlineDisks, minioMetaTmpBucket, tmpPartPath, minioMetaMultipartBucket, partPath, false, writeQuorum, nil)
|
2016-05-21 05:48:47 +02:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-05-26 12:15:01 +02:00
|
|
|
|
2016-07-14 23:59:01 +02:00
|
|
|
// Read metadata again because it might be updated with parallel upload of another part.
|
2018-04-06 00:04:40 +02:00
|
|
|
partsMetadata, errs = readAllXLMetadata(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
reducedErr = reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2018-04-10 18:36:37 +02:00
|
|
|
if reducedErr == errXLWriteQuorum {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, toObjectErr(reducedErr, bucket, object)
|
2016-07-12 02:24:49 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:59:01 +02:00
|
|
|
// Get current highest version based on re-read partsMetadata.
|
|
|
|
onlineDisks, modTime = listOnlineDisks(onlineDisks, partsMetadata, errs)
|
2016-07-12 02:24:49 +02:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2018-08-17 23:42:04 +02:00
|
|
|
xlMeta, err = pickValidXLMeta(ctx, partsMetadata, modTime, writeQuorum)
|
2016-11-21 05:56:44 +01:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, err
|
2016-11-21 05:56:44 +01:00
|
|
|
}
|
2016-07-12 02:24:49 +02:00
|
|
|
|
2016-05-26 12:15:01 +02:00
|
|
|
// Once part is successfully committed, proceed with updating XL metadata.
|
2017-03-18 19:28:41 +01:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-06-17 20:57:51 +02:00
|
|
|
|
2018-11-15 02:36:41 +01:00
|
|
|
md5hex := r.MD5CurrentHexString()
|
2017-10-22 07:30:34 +02:00
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Add the current part.
|
2018-09-28 05:36:17 +02:00
|
|
|
xlMeta.AddObjectPart(partID, partSuffix, md5hex, n, data.ActualSize())
|
2016-05-26 12:15:01 +02:00
|
|
|
|
2017-08-15 03:08:42 +02:00
|
|
|
for i, disk := range onlineDisks {
|
|
|
|
if disk == OfflineDisk {
|
2016-07-14 23:59:01 +02:00
|
|
|
continue
|
|
|
|
}
|
2018-08-17 02:55:01 +02:00
|
|
|
partsMetadata[i].Stat = xlMeta.Stat
|
2017-08-15 03:08:42 +02:00
|
|
|
partsMetadata[i].Parts = xlMeta.Parts
|
2019-01-17 13:58:18 +01:00
|
|
|
partsMetadata[i].Erasure.AddChecksumInfo(ChecksumInfo{partSuffix, DefaultBitrotAlgorithm, bitrotWriterSum(writers[i])})
|
2016-06-01 05:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write all the checksum metadata.
|
2019-04-25 16:33:26 +02:00
|
|
|
tempXLMetaPath := mustGetUUID()
|
|
|
|
|
|
|
|
// Cleanup in case of xl.json writing failure
|
|
|
|
defer xl.deleteObject(ctx, minioMetaTmpBucket, tempXLMetaPath, writeQuorum, false)
|
2016-06-01 05:23:31 +02:00
|
|
|
|
2016-07-20 04:24:32 +02:00
|
|
|
// Writes a unique `xl.json` each disk carrying new checksum related information.
|
2019-09-11 19:22:12 +02:00
|
|
|
onlineDisks, err = writeUniqueXLMetadata(ctx, onlineDisks, minioMetaTmpBucket, tempXLMetaPath, partsMetadata, writeQuorum)
|
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return pi, toObjectErr(err, minioMetaTmpBucket, tempXLMetaPath)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2017-08-24 02:58:52 +02:00
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
if _, err = commitXLMetadata(ctx, onlineDisks, minioMetaTmpBucket, tempXLMetaPath, minioMetaMultipartBucket, uploadIDPath, writeQuorum); err != nil {
|
2017-08-24 02:58:52 +02:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2017-01-31 18:38:34 +01:00
|
|
|
}
|
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
fi, err := xl.statPart(ctx, bucket, object, uploadID, partSuffix)
|
2017-01-31 18:38:34 +01:00
|
|
|
if err != nil {
|
2017-08-24 02:58:52 +02:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partSuffix)
|
2016-05-29 00:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return success.
|
2017-01-31 18:38:34 +01:00
|
|
|
return PartInfo{
|
|
|
|
PartNumber: partID,
|
|
|
|
LastModified: fi.ModTime,
|
2017-10-22 07:30:34 +02:00
|
|
|
ETag: md5hex,
|
2017-01-31 18:38:34 +01:00
|
|
|
Size: fi.Size,
|
2018-09-28 05:36:17 +02:00
|
|
|
ActualSize: data.ActualSize(),
|
2017-01-31 18:38:34 +01:00
|
|
|
}, nil
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2018-03-15 21:55:23 +01: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
|
2018-06-29 01:02:02 +02:00
|
|
|
// ListPartsInfo structure is marshaled directly into XML and
|
2018-03-15 21:55:23 +01:00
|
|
|
// replied back to the client.
|
2019-01-05 23:16:43 +01:00
|
|
|
func (xl xlObjects) ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker, maxParts int, opts ObjectOptions) (result ListPartsInfo, e error) {
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkListPartsArgs(ctx, bucket, object, xl); err != nil {
|
2018-03-15 21:55:23 +01:00
|
|
|
return result, err
|
|
|
|
}
|
2019-04-23 23:54:28 +02:00
|
|
|
if err := xl.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return result, toObjectErr(err, bucket, object, uploadID)
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
|
2018-03-15 21:55:23 +01:00
|
|
|
uploadIDPath := xl.getUploadIDDir(bucket, object, uploadID)
|
2016-06-01 05:23:31 +02:00
|
|
|
|
2019-02-01 17:58:41 +01:00
|
|
|
storageDisks := xl.getDisks()
|
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
|
|
|
partsMetadata, errs := readAllXLMetadata(ctx, storageDisks, minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
|
|
|
|
// get Quorum for this object
|
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
2016-05-21 05:48:47 +02:00
|
|
|
if err != nil {
|
2018-03-15 21:55:23 +01:00
|
|
|
return result, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-05-25 06:24:20 +02:00
|
|
|
|
2019-02-01 17:58:41 +01:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
|
|
|
if reducedErr == errXLWriteQuorum {
|
2019-09-16 23:27:34 +02:00
|
|
|
return result, toObjectErr(reducedErr, minioMetaMultipartBucket, uploadIDPath)
|
2019-02-01 17:58:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
|
|
|
xlValidMeta, err := pickValidXLMeta(ctx, partsMetadata, modTime, writeQuorum)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var xlMeta = xlValidMeta.Meta
|
|
|
|
var xlParts = xlValidMeta.Parts
|
|
|
|
|
2016-05-25 06:24:20 +02:00
|
|
|
// Populate the result stub.
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
result.MaxParts = maxParts
|
2018-01-31 22:17:24 +01:00
|
|
|
result.PartNumberMarker = partNumberMarker
|
2018-03-01 20:37:57 +01:00
|
|
|
result.UserDefined = xlMeta
|
2016-05-25 06:24:20 +02:00
|
|
|
|
|
|
|
// For empty number of parts or maxParts as zero, return right here.
|
2016-09-09 07:38:18 +02:00
|
|
|
if len(xlParts) == 0 || maxParts == 0 {
|
2016-05-25 06:24:20 +02:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit output to maxPartsList.
|
|
|
|
if maxParts > maxPartsList {
|
|
|
|
maxParts = maxPartsList
|
|
|
|
}
|
|
|
|
|
2016-05-21 05:48:47 +02:00
|
|
|
// Only parts with higher part numbers will be listed.
|
2016-09-09 07:38:18 +02:00
|
|
|
partIdx := objectPartIndex(xlParts, partNumberMarker)
|
|
|
|
parts := xlParts
|
2016-05-25 06:24:20 +02:00
|
|
|
if partIdx != -1 {
|
2016-09-09 07:38:18 +02:00
|
|
|
parts = xlParts[partIdx+1:]
|
2016-05-25 06:24:20 +02:00
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
count := maxParts
|
2016-05-25 06:24:20 +02:00
|
|
|
for _, part := range parts {
|
2016-05-25 10:33:39 +02:00
|
|
|
var fi FileInfo
|
2018-04-06 00:04:40 +02:00
|
|
|
fi, err = xl.statPart(ctx, bucket, object, uploadID, part.Name)
|
2016-05-21 05:48:47 +02:00
|
|
|
if err != nil {
|
2018-03-15 21:55:23 +01:00
|
|
|
return result, toObjectErr(err, minioMetaBucket, path.Join(uploadID, part.Name))
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2017-01-31 18:38:34 +01:00
|
|
|
result.Parts = append(result.Parts, PartInfo{
|
2016-05-25 06:24:20 +02:00
|
|
|
PartNumber: part.Number,
|
2016-05-21 05:48:47 +02:00
|
|
|
ETag: part.ETag,
|
|
|
|
LastModified: fi.ModTime,
|
2016-05-28 09:18:58 +02:00
|
|
|
Size: part.Size,
|
2016-05-21 05:48:47 +02: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-02 01:43:31 +02: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.
|
2018-11-15 02:36:41 +01:00
|
|
|
func (xl xlObjects) CompleteMultipartUpload(ctx context.Context, bucket string, object string, uploadID string, parts []CompletePart, opts ObjectOptions) (oi ObjectInfo, e error) {
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkCompleteMultipartArgs(ctx, bucket, object, xl); err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, err
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 23:54:28 +02:00
|
|
|
if err := xl.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return oi, toObjectErr(err, bucket, object, uploadID)
|
2016-05-28 06:50:09 +02:00
|
|
|
}
|
2017-02-22 04:43:44 +01:00
|
|
|
|
|
|
|
// Check if an object is present as one of the parent dir.
|
|
|
|
// -- FIXME. (needs a new kind of lock).
|
2018-04-06 00:04:40 +02:00
|
|
|
if xl.parentDirIsObject(ctx, bucket, path.Dir(object)) {
|
2019-03-20 21:06:53 +01:00
|
|
|
return oi, toObjectErr(errFileParentIsFile, bucket, object)
|
2017-02-22 04:43:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-21 05:48:47 +02:00
|
|
|
// Calculate s3 compatible md5sum for complete multipart.
|
2019-05-09 03:35:40 +02:00
|
|
|
s3MD5 := getCompleteMultipartMD5(parts)
|
2016-05-21 05:48:47 +02:00
|
|
|
|
2019-11-20 02:42:27 +01:00
|
|
|
uploadIDPath := xl.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Read metadata associated with the object from all disks.
|
2018-04-06 00:04:40 +02:00
|
|
|
partsMetadata, errs := readAllXLMetadata(ctx, xl.getDisks(), minioMetaMultipartBucket, uploadIDPath)
|
2017-12-22 12:28:13 +01:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2018-07-31 09:23:29 +02:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
2017-12-22 12:28:13 +01:00
|
|
|
if err != nil {
|
|
|
|
return oi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2018-04-06 00:04:40 +02:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2018-04-10 18:36:37 +02:00
|
|
|
if reducedErr == errXLWriteQuorum {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, toObjectErr(reducedErr, bucket, object)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.getDisks(), partsMetadata, errs)
|
2016-07-14 23:59:01 +02:00
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Calculate full object size.
|
2016-05-21 05:48:47 +02:00
|
|
|
var objectSize int64
|
2016-05-25 06:24:20 +02:00
|
|
|
|
2018-09-28 05:36:17 +02:00
|
|
|
// Calculate consolidated actual size.
|
|
|
|
var objectActualSize int64
|
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Pick one from the first valid metadata.
|
2018-08-17 23:42:04 +02:00
|
|
|
xlMeta, err := pickValidXLMeta(ctx, partsMetadata, modTime, writeQuorum)
|
2016-11-21 05:56:44 +01:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, err
|
2016-11-21 05:56:44 +01:00
|
|
|
}
|
2016-06-01 05:23:31 +02:00
|
|
|
|
2016-07-27 20:57:08 +02:00
|
|
|
// Order online disks in accordance with distribution order.
|
2017-02-24 18:20:40 +01:00
|
|
|
onlineDisks = shuffleDisks(onlineDisks, xlMeta.Erasure.Distribution)
|
2016-07-27 20:57:08 +02:00
|
|
|
|
|
|
|
// Order parts metadata in accordance with distribution order.
|
2017-02-24 18:20:40 +01:00
|
|
|
partsMetadata = shufflePartsMetadata(partsMetadata, xlMeta.Erasure.Distribution)
|
2016-07-27 20:57:08 +02:00
|
|
|
|
2016-05-25 06:24:20 +02:00
|
|
|
// Save current xl meta for validation.
|
|
|
|
var currentXLMeta = xlMeta
|
|
|
|
|
|
|
|
// Allocate parts similar to incoming slice.
|
2019-01-05 23:16:43 +01:00
|
|
|
xlMeta.Parts = make([]ObjectPartInfo, len(parts))
|
2016-05-25 06:24:20 +02:00
|
|
|
|
2016-06-02 01:43:31 +02:00
|
|
|
// Validate each part and then commit to disk.
|
2016-05-21 05:48:47 +02:00
|
|
|
for i, part := range parts {
|
2019-04-01 21:19:52 +02:00
|
|
|
// ensure that part ETag is canonicalized to strip off extraneous quotes
|
|
|
|
part.ETag = canonicalizeETag(part.ETag)
|
2016-09-09 07:38:18 +02:00
|
|
|
partIdx := objectPartIndex(currentXLMeta.Parts, part.PartNumber)
|
2016-06-19 23:51:20 +02:00
|
|
|
// All parts should have same part number.
|
2016-05-25 06:24:20 +02:00
|
|
|
if partIdx == -1 {
|
2018-08-15 03:35:30 +02:00
|
|
|
invp := InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
GotETag: part.ETag,
|
|
|
|
}
|
|
|
|
return oi, invp
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-06-19 23:51:20 +02:00
|
|
|
|
2016-05-25 06:24:20 +02:00
|
|
|
if currentXLMeta.Parts[partIdx].ETag != part.ETag {
|
2018-08-15 03:35:30 +02:00
|
|
|
invp := InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
ExpETag: currentXLMeta.Parts[partIdx].ETag,
|
|
|
|
GotETag: part.ETag,
|
|
|
|
}
|
|
|
|
return oi, invp
|
2016-05-25 06:24:20 +02:00
|
|
|
}
|
2016-06-19 23:51:20 +02:00
|
|
|
|
2016-05-21 05:48:47 +02:00
|
|
|
// All parts except the last part has to be atleast 5MB.
|
2018-09-28 05:36:17 +02:00
|
|
|
if (i < len(parts)-1) && !isMinAllowedPartSize(currentXLMeta.Parts[partIdx].ActualSize) {
|
2018-04-06 00:04:40 +02:00
|
|
|
return oi, PartTooSmall{
|
|
|
|
PartNumber: part.PartNumber,
|
2018-09-28 05:36:17 +02:00
|
|
|
PartSize: currentXLMeta.Parts[partIdx].ActualSize,
|
2018-04-06 00:04:40 +02:00
|
|
|
PartETag: part.ETag,
|
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-05-25 06:24:20 +02:00
|
|
|
|
|
|
|
// Save for total object size.
|
|
|
|
objectSize += currentXLMeta.Parts[partIdx].Size
|
|
|
|
|
2018-09-28 05:36:17 +02:00
|
|
|
// Save the consolidated actual size.
|
|
|
|
objectActualSize += currentXLMeta.Parts[partIdx].ActualSize
|
|
|
|
|
2016-05-25 06:24:20 +02:00
|
|
|
// Add incoming parts.
|
2019-01-05 23:16:43 +01:00
|
|
|
xlMeta.Parts[i] = ObjectPartInfo{
|
2018-09-28 05:36:17 +02:00
|
|
|
Number: part.PartNumber,
|
|
|
|
ETag: part.ETag,
|
|
|
|
Size: currentXLMeta.Parts[partIdx].Size,
|
|
|
|
Name: fmt.Sprintf("part.%d", part.PartNumber),
|
|
|
|
ActualSize: currentXLMeta.Parts[partIdx].ActualSize,
|
2016-05-25 06:24:20 +02:00
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the final object size and modtime.
|
|
|
|
xlMeta.Stat.Size = objectSize
|
2017-03-18 19:28:41 +01:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-05-21 05:48:47 +02:00
|
|
|
|
|
|
|
// Save successfully calculated md5sum.
|
2017-05-14 21:05:51 +02:00
|
|
|
xlMeta.Meta["etag"] = s3MD5
|
2017-10-22 07:30:34 +02:00
|
|
|
|
2018-09-28 05:36:17 +02:00
|
|
|
// Save the consolidated actual size.
|
|
|
|
xlMeta.Meta[ReservedMetadataPrefix+"actual-size"] = strconv.FormatInt(objectActualSize, 10)
|
|
|
|
|
2016-06-01 05:23:31 +02: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-02 01:43:31 +02:00
|
|
|
|
2019-04-25 16:33:26 +02:00
|
|
|
tempXLMetaPath := mustGetUUID()
|
|
|
|
|
|
|
|
// Cleanup in case of failure
|
|
|
|
defer xl.deleteObject(ctx, minioMetaTmpBucket, tempXLMetaPath, writeQuorum, false)
|
|
|
|
|
2016-06-01 05:23:31 +02:00
|
|
|
// Write unique `xl.json` for each disk.
|
2019-04-25 16:33:26 +02:00
|
|
|
if onlineDisks, err = writeUniqueXLMetadata(ctx, onlineDisks, minioMetaTmpBucket, tempXLMetaPath, partsMetadata, writeQuorum); err != nil {
|
|
|
|
return oi, toObjectErr(err, minioMetaTmpBucket, tempXLMetaPath)
|
2016-05-29 00:13:15 +02:00
|
|
|
}
|
2017-02-22 04:43:44 +01:00
|
|
|
|
2017-06-15 02:14:27 +02:00
|
|
|
var rErr error
|
2019-04-25 16:33:26 +02:00
|
|
|
onlineDisks, rErr = commitXLMetadata(ctx, onlineDisks, minioMetaTmpBucket, tempXLMetaPath, minioMetaMultipartBucket, uploadIDPath, writeQuorum)
|
2016-05-29 00:13:15 +02:00
|
|
|
if rErr != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2016-08-31 20:39:08 +02:00
|
|
|
|
2016-06-20 15:18:47 +02:00
|
|
|
if xl.isObject(bucket, object) {
|
2018-10-04 05:39:24 +02:00
|
|
|
// Deny if WORM is enabled
|
2019-12-17 19:13:12 +01:00
|
|
|
if _, ok := isWORMEnabled(bucket); ok {
|
2019-11-20 22:18:09 +01:00
|
|
|
if _, err := xl.getObjectInfo(ctx, bucket, object); err == nil {
|
2019-11-12 23:50:18 +01:00
|
|
|
return ObjectInfo{}, ObjectAlreadyExists{Bucket: bucket, Object: object}
|
|
|
|
}
|
2018-10-04 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 04:43:44 +01:00
|
|
|
// Rename if an object already exists to temporary location.
|
|
|
|
newUniqueID := mustGetUUID()
|
|
|
|
|
|
|
|
// Delete success renamed object.
|
2018-08-29 22:36:19 +02:00
|
|
|
defer xl.deleteObject(ctx, minioMetaTmpBucket, newUniqueID, writeQuorum, false)
|
2017-02-22 04:43:44 +01:00
|
|
|
|
2018-10-05 02:22:49 +02: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. Also allow renaming of the
|
|
|
|
// existing object if it is not present in quorum disks so users can overwrite stale objects.
|
|
|
|
_, err = rename(ctx, xl.getDisks(), bucket, object, minioMetaTmpBucket, newUniqueID, true, writeQuorum, []error{errFileNotFound})
|
2016-06-20 15:18:47 +02:00
|
|
|
if err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-06-20 15:18:47 +02:00
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2016-06-10 15:13:16 +02:00
|
|
|
// Remove parts that weren't present in CompleteMultipartUpload request.
|
2016-05-28 22:23:08 +02:00
|
|
|
for _, curpart := range currentXLMeta.Parts {
|
2016-09-09 07:38:18 +02:00
|
|
|
if objectPartIndex(xlMeta.Parts, curpart.Number) == -1 {
|
2016-05-28 22:23:08 +02: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 09:42:09 +02:00
|
|
|
// Rename the multipart object to final location.
|
2018-10-05 02:22:49 +02:00
|
|
|
if _, err = rename(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath, bucket, object, true, writeQuorum, nil); err != nil {
|
2017-06-22 04:53:09 +02:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2017-01-17 04:23:43 +01:00
|
|
|
// Success, return object info.
|
2018-03-01 20:37:57 +01:00
|
|
|
return xlMeta.ToObjectInfo(bucket, object), nil
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 01:43:31 +02:00
|
|
|
// 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.
|
2018-03-14 20:01:47 +01:00
|
|
|
func (xl xlObjects) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) error {
|
2018-04-06 00:04:40 +02:00
|
|
|
if err := checkAbortMultipartArgs(ctx, bucket, object, xl); err != nil {
|
2016-12-02 08:15:17 +01:00
|
|
|
return err
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|
2019-04-23 23:54:28 +02:00
|
|
|
// Validates if upload ID exists.
|
|
|
|
if err := xl.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return toObjectErr(err, bucket, object, uploadID)
|
2016-05-28 22:23:08 +02:00
|
|
|
}
|
2018-03-15 21:55:23 +01:00
|
|
|
|
2019-11-20 02:42:27 +01:00
|
|
|
uploadIDPath := xl.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
|
2018-03-15 21:55:23 +01:00
|
|
|
// Read metadata associated with the object from all disks.
|
2018-04-06 00:04:40 +02:00
|
|
|
partsMetadata, errs := readAllXLMetadata(ctx, xl.getDisks(), minioMetaMultipartBucket, uploadIDPath)
|
2018-03-15 21:55:23 +01:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2018-07-31 09:23:29 +02:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
2018-03-15 21:55:23 +01:00
|
|
|
if err != nil {
|
2019-11-09 18:27:23 +01:00
|
|
|
return toObjectErr(err, bucket, object, uploadID)
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup all uploaded parts.
|
2018-08-29 22:36:19 +02:00
|
|
|
if err = xl.deleteObject(ctx, minioMetaMultipartBucket, uploadIDPath, writeQuorum, false); err != nil {
|
2019-11-09 18:27:23 +01:00
|
|
|
return toObjectErr(err, bucket, object, uploadID)
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Successfully purged.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean-up the old multipart uploads. Should be run in a Go routine.
|
2018-04-06 00:04:40 +02:00
|
|
|
func (xl xlObjects) cleanupStaleMultipartUploads(ctx context.Context, cleanupInterval, expiry time.Duration, doneCh chan struct{}) {
|
2018-03-15 21:55:23 +01:00
|
|
|
ticker := time.NewTicker(cleanupInterval)
|
2018-05-04 19:43:20 +02:00
|
|
|
defer ticker.Stop()
|
2018-03-15 21:55:23 +01:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-doneCh:
|
|
|
|
return
|
|
|
|
case <-ticker.C:
|
|
|
|
var disk StorageAPI
|
|
|
|
for _, d := range xl.getLoadBalancedDisks() {
|
|
|
|
if d != nil {
|
|
|
|
disk = d
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2018-04-06 00:04:40 +02:00
|
|
|
xl.cleanupStaleMultipartUploadsOnDisk(ctx, disk, expiry)
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the old multipart uploads on the given disk.
|
2018-04-06 00:04:40 +02:00
|
|
|
func (xl xlObjects) cleanupStaleMultipartUploadsOnDisk(ctx context.Context, disk StorageAPI, expiry time.Duration) {
|
2018-03-15 21:55:23 +01:00
|
|
|
now := time.Now()
|
2019-04-23 23:54:28 +02:00
|
|
|
shaDirs, err := disk.ListDir(minioMetaMultipartBucket, "", -1, "")
|
2018-03-15 21:55:23 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, shaDir := range shaDirs {
|
2019-04-23 23:54:28 +02:00
|
|
|
uploadIDDirs, err := disk.ListDir(minioMetaMultipartBucket, shaDir, -1, "")
|
2018-03-15 21:55:23 +01:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, uploadIDDir := range uploadIDDirs {
|
|
|
|
uploadIDPath := pathJoin(shaDir, uploadIDDir)
|
|
|
|
fi, err := disk.StatFile(minioMetaMultipartBucket, pathJoin(uploadIDPath, xlMetaJSONFile))
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if now.Sub(fi.ModTime) > expiry {
|
2018-08-29 22:36:19 +02:00
|
|
|
xl.deleteObject(ctx, minioMetaMultipartBucket, uploadIDPath, len(xl.getDisks())/2+1, false)
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 05:48:47 +02:00
|
|
|
}
|