2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
import (
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2022-07-14 19:47:09 -04:00
|
|
|
"errors"
|
2016-05-20 23:48:47 -04:00
|
|
|
"fmt"
|
2019-01-17 07:58:18 -05:00
|
|
|
"io"
|
2021-02-26 12:52:27 -05:00
|
|
|
"os"
|
2016-05-20 23:48:47 -04:00
|
|
|
"path"
|
2018-03-15 16:55:23 -04:00
|
|
|
"sort"
|
2018-09-27 23:36:17 -04:00
|
|
|
"strconv"
|
2016-05-24 16:35:43 -04:00
|
|
|
"strings"
|
2021-02-11 13:22:03 -05:00
|
|
|
"sync"
|
2020-08-22 00:39:54 -04:00
|
|
|
"time"
|
2016-05-24 16:35:43 -04:00
|
|
|
|
2022-01-14 13:01:25 -05:00
|
|
|
"github.com/klauspost/readahead"
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/set"
|
2021-06-01 17:59:40 -04:00
|
|
|
xhttp "github.com/minio/minio/internal/http"
|
|
|
|
"github.com/minio/minio/internal/logger"
|
|
|
|
"github.com/minio/minio/internal/sync/errgroup"
|
2021-05-28 18:17:01 -04:00
|
|
|
"github.com/minio/pkg/mimedb"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) getUploadIDDir(bucket, object, uploadID string) string {
|
|
|
|
return pathJoin(er.getMultipartSHADir(bucket, object), uploadID)
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) getMultipartSHADir(bucket, object string) string {
|
2018-03-15 16:55:23 -04:00
|
|
|
return getSHA256Hash([]byte(pathJoin(bucket, object)))
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
2019-04-23 17:54:28 -04:00
|
|
|
// checkUploadIDExists - verify if a given uploadID exists and is valid.
|
2021-03-26 14:17:23 -04:00
|
|
|
func (er erasureObjects) checkUploadIDExists(ctx context.Context, bucket, object, uploadID string) (err error) {
|
|
|
|
defer func() {
|
2022-07-14 19:47:09 -04:00
|
|
|
if errors.Is(err, errFileNotFound) || errors.Is(err, errVolumeNotFound) {
|
2021-03-26 14:17:23 -04:00
|
|
|
err = errUploadIDNotFound
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-10-26 13:30:46 -04:00
|
|
|
disks := er.getDisks()
|
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-01-07 22:27:31 -05:00
|
|
|
metaArr, errs := readAllFileInfo(ctx, disks, minioMetaMultipartBucket, er.getUploadIDDir(bucket, object, uploadID), "", false)
|
2020-10-26 13:30:46 -04:00
|
|
|
|
2021-01-16 15:08:02 -05:00
|
|
|
readQuorum, _, err := objectQuorumFromMeta(ctx, metaArr, errs, er.defaultParityCount)
|
2020-10-26 13:30:46 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if reducedErr := reduceReadQuorumErrs(ctx, errs, objectOpIgnoredErrs, readQuorum); reducedErr != nil {
|
2021-03-26 14:17:23 -04:00
|
|
|
return reducedErr
|
2020-10-26 13:30:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// List all online disks.
|
2021-11-21 13:41:30 -05:00
|
|
|
_, modTime := listOnlineDisks(disks, metaArr, errs)
|
2020-10-26 13:30:46 -04:00
|
|
|
|
|
|
|
// Pick latest valid metadata.
|
2021-11-21 13:41:30 -05:00
|
|
|
_, err = pickValidFileInfo(ctx, metaArr, modTime, readQuorum)
|
2019-04-23 17:54:28 -04:00
|
|
|
return err
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Removes part.meta given by partName belonging to a mulitpart upload from minioMetaBucket
|
|
|
|
func (er erasureObjects) removePartMeta(bucket, object, uploadID, dataDir string, partNumber int) {
|
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
curpartPath := pathJoin(uploadIDPath, dataDir, fmt.Sprintf("part.%d", partNumber))
|
|
|
|
storageDisks := er.getDisks()
|
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
|
|
|
for index, disk := range storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
_ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath+".meta", DeleteOptions{
|
|
|
|
Recursive: false,
|
|
|
|
Force: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
g.Wait()
|
|
|
|
}
|
|
|
|
|
2017-01-26 15:51:12 -05:00
|
|
|
// Removes part given by partName belonging to a mulitpart upload from minioMetaBucket
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) removeObjectPart(bucket, object, uploadID, dataDir string, partNumber int) {
|
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
curpartPath := pathJoin(uploadIDPath, dataDir, fmt.Sprintf("part.%d", partNumber))
|
|
|
|
storageDisks := er.getDisks()
|
2019-10-14 12:44:51 -04:00
|
|
|
|
|
|
|
g := errgroup.WithNErrs(len(storageDisks))
|
|
|
|
for index, disk := range storageDisks {
|
2017-01-26 15:51:12 -05:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
2017-01-26 15:51:12 -05:00
|
|
|
// Ignoring failure to remove parts that weren't present in CompleteMultipartUpload
|
2020-06-12 23:04:01 -04:00
|
|
|
// requests. xl.meta is the authoritative source of truth on which parts constitute
|
2017-01-26 15:51:12 -05:00
|
|
|
// the object. The presence of parts that don't belong in the object doesn't affect correctness.
|
2022-07-11 12:15:54 -04:00
|
|
|
_ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath, DeleteOptions{
|
|
|
|
Recursive: false,
|
|
|
|
Force: false,
|
|
|
|
})
|
2022-07-19 11:35:29 -04:00
|
|
|
_ = storageDisks[index].Delete(context.TODO(), minioMetaMultipartBucket, curpartPath+".meta", DeleteOptions{
|
|
|
|
Recursive: false,
|
|
|
|
Force: false,
|
|
|
|
})
|
|
|
|
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
|
|
|
}, index)
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
g.Wait()
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
2020-08-22 00:39:54 -04:00
|
|
|
// Clean-up the old multipart uploads. Should be run in a Go routine.
|
2020-12-10 10:28:37 -05:00
|
|
|
func (er erasureObjects) cleanupStaleUploads(ctx context.Context, expiry time.Duration) {
|
|
|
|
// run multiple cleanup's local to this server.
|
2021-02-11 13:22:03 -05:00
|
|
|
var wg sync.WaitGroup
|
2020-12-10 10:28:37 -05:00
|
|
|
for _, disk := range er.getLoadBalancedLocalDisks() {
|
|
|
|
if disk != nil {
|
2021-02-11 13:22:03 -05:00
|
|
|
wg.Add(1)
|
|
|
|
go func(disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
er.cleanupStaleUploadsOnDisk(ctx, disk, expiry)
|
|
|
|
}(disk)
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
|
|
|
}
|
2021-02-11 13:22:03 -05:00
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (er erasureObjects) renameAll(ctx context.Context, bucket, prefix string) {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, disk := range er.getDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
2021-08-19 12:16:14 -04:00
|
|
|
disk.RenameFile(ctx, bucket, prefix, minioMetaTmpDeletedBucket, mustGetUUID())
|
2021-02-11 13:22:03 -05:00
|
|
|
}(disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (er erasureObjects) deleteAll(ctx context.Context, bucket, prefix string) {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, disk := range er.getDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
2022-07-11 12:15:54 -04:00
|
|
|
disk.Delete(ctx, bucket, prefix, DeleteOptions{
|
|
|
|
Recursive: true,
|
|
|
|
Force: false,
|
|
|
|
})
|
2021-02-11 13:22:03 -05:00
|
|
|
}(disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the old multipart uploads on the given disk.
|
2020-09-08 18:55:40 -04:00
|
|
|
func (er erasureObjects) cleanupStaleUploadsOnDisk(ctx context.Context, disk StorageAPI, expiry time.Duration) {
|
2020-08-22 00:39:54 -04:00
|
|
|
now := time.Now()
|
2021-02-26 12:52:27 -05:00
|
|
|
diskPath := disk.Endpoint().Path
|
|
|
|
|
|
|
|
readDirFn(pathJoin(diskPath, minioMetaMultipartBucket), func(shaDir string, typ os.FileMode) error {
|
|
|
|
return readDirFn(pathJoin(diskPath, minioMetaMultipartBucket, shaDir), func(uploadIDDir string, typ os.FileMode) error {
|
2020-08-22 00:39:54 -04:00
|
|
|
uploadIDPath := pathJoin(shaDir, uploadIDDir)
|
2021-01-07 22:27:31 -05:00
|
|
|
fi, err := disk.ReadVersion(ctx, minioMetaMultipartBucket, uploadIDPath, "", false)
|
2020-08-22 00:39:54 -04:00
|
|
|
if err != nil {
|
2021-02-26 12:52:27 -05:00
|
|
|
return nil
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
2021-02-26 12:52:27 -05:00
|
|
|
wait := er.deletedCleanupSleeper.Timer(ctx)
|
2020-08-22 00:39:54 -04:00
|
|
|
if now.Sub(fi.ModTime) > expiry {
|
2021-02-11 13:22:03 -05:00
|
|
|
er.renameAll(ctx, minioMetaMultipartBucket, uploadIDPath)
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
2021-02-26 12:52:27 -05:00
|
|
|
wait()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
readDirFn(pathJoin(diskPath, minioMetaTmpBucket), func(tmpDir string, typ os.FileMode) error {
|
|
|
|
if tmpDir == ".trash/" { // do not remove .trash/ here, it has its own routines
|
|
|
|
return nil
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
2021-02-11 13:22:03 -05:00
|
|
|
vi, err := disk.StatVol(ctx, pathJoin(minioMetaTmpBucket, tmpDir))
|
2020-09-08 18:55:40 -04:00
|
|
|
if err != nil {
|
2021-02-26 12:52:27 -05:00
|
|
|
return nil
|
2020-09-08 18:55:40 -04:00
|
|
|
}
|
2021-02-26 12:52:27 -05:00
|
|
|
wait := er.deletedCleanupSleeper.Timer(ctx)
|
2021-02-11 13:22:03 -05:00
|
|
|
if now.Sub(vi.Created) > expiry {
|
|
|
|
er.deleteAll(ctx, minioMetaTmpBucket, tmpDir)
|
2020-09-08 18:55:40 -04:00
|
|
|
}
|
2021-02-26 12:52:27 -05:00
|
|
|
wait()
|
|
|
|
return nil
|
|
|
|
})
|
2020-08-22 00:39:54 -04:00
|
|
|
}
|
|
|
|
|
2017-11-30 18:58:46 -05: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.
|
2020-07-03 22:27:13 -04:00
|
|
|
func (er erasureObjects) ListMultipartUploads(ctx context.Context, bucket, object, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, err error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2017-11-30 18:58:46 -05:00
|
|
|
result.MaxUploads = maxUploads
|
|
|
|
result.KeyMarker = keyMarker
|
|
|
|
result.Prefix = object
|
|
|
|
result.Delimiter = delimiter
|
|
|
|
|
2020-07-03 22:27:13 -04:00
|
|
|
var uploadIDs []string
|
2020-09-28 22:39:32 -04:00
|
|
|
var disk StorageAPI
|
2020-10-09 18:40:46 -04:00
|
|
|
for _, disk = range er.getLoadBalancedDisks(true) {
|
2020-09-04 12:45:06 -04:00
|
|
|
uploadIDs, err = disk.ListDir(ctx, minioMetaMultipartBucket, er.getMultipartSHADir(bucket, object), -1)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
2022-07-14 19:47:09 -04:00
|
|
|
if errors.Is(err, errDiskNotFound) {
|
2020-07-03 22:27:13 -04:00
|
|
|
continue
|
|
|
|
}
|
2022-07-14 19:47:09 -04:00
|
|
|
if errors.Is(err, errFileNotFound) || errors.Is(err, errVolumeNotFound) {
|
2018-03-15 16:55:23 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, err)
|
2020-07-03 22:27:13 -04:00
|
|
|
return result, toObjectErr(err, bucket, object)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2020-07-03 22:27:13 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range uploadIDs {
|
|
|
|
uploadIDs[i] = strings.TrimSuffix(uploadIDs[i], SlashSeparator)
|
|
|
|
}
|
|
|
|
|
|
|
|
// S3 spec says uploadIDs should be sorted based on initiated time, we need
|
|
|
|
// to read the metadata entry.
|
|
|
|
var uploads []MultipartInfo
|
|
|
|
|
|
|
|
populatedUploadIds := set.NewStringSet()
|
|
|
|
|
2020-09-28 22:39:32 -04:00
|
|
|
for _, uploadID := range uploadIDs {
|
|
|
|
if populatedUploadIds.Contains(uploadID) {
|
2020-07-03 22:27:13 -04:00
|
|
|
continue
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2021-01-07 22:27:31 -05:00
|
|
|
fi, err := disk.ReadVersion(ctx, minioMetaMultipartBucket, pathJoin(er.getUploadIDDir(bucket, object, uploadID)), "", false)
|
2020-09-28 22:39:32 -04:00
|
|
|
if err != nil {
|
2022-07-16 16:25:58 -04:00
|
|
|
if !IsErrIgnored(err, errFileNotFound, errDiskNotFound) {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
}
|
|
|
|
// Ignore this invalid upload-id since we are listing here
|
|
|
|
continue
|
2017-11-30 18:58:46 -05:00
|
|
|
}
|
2020-09-28 22:39:32 -04:00
|
|
|
populatedUploadIds.Add(uploadID)
|
|
|
|
uploads = append(uploads, MultipartInfo{
|
|
|
|
Object: object,
|
|
|
|
UploadID: uploadID,
|
|
|
|
Initiated: fi.ModTime,
|
|
|
|
})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
|
2020-07-03 22:27:13 -04:00
|
|
|
sort.Slice(uploads, func(i int, j int) bool {
|
|
|
|
return uploads[i].Initiated.Before(uploads[j].Initiated)
|
|
|
|
})
|
|
|
|
|
|
|
|
uploadIndex := 0
|
|
|
|
if uploadIDMarker != "" {
|
|
|
|
for uploadIndex < len(uploads) {
|
|
|
|
if uploads[uploadIndex].UploadID != uploadIDMarker {
|
|
|
|
uploadIndex++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if uploads[uploadIndex].UploadID == uploadIDMarker {
|
|
|
|
uploadIndex++
|
|
|
|
break
|
|
|
|
}
|
|
|
|
uploadIndex++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for uploadIndex < len(uploads) {
|
|
|
|
result.Uploads = append(result.Uploads, uploads[uploadIndex])
|
|
|
|
result.NextUploadIDMarker = uploads[uploadIndex].UploadID
|
|
|
|
uploadIndex++
|
|
|
|
if len(result.Uploads) == maxUploads {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.IsTruncated = uploadIndex < len(uploads)
|
|
|
|
|
|
|
|
if !result.IsTruncated {
|
|
|
|
result.NextKeyMarker = ""
|
|
|
|
result.NextUploadIDMarker = ""
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:58:46 -05:00
|
|
|
return result, nil
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// newMultipartUpload - wrapper for initializing a new multipart
|
2016-10-24 20:37:18 -04:00
|
|
|
// request; returns a unique upload id.
|
2016-06-01 19:43:31 -04:00
|
|
|
//
|
|
|
|
// Internally this function creates 'uploads.json' associated for the
|
2016-10-24 20:37:18 -04:00
|
|
|
// incoming object at
|
|
|
|
// '.minio.sys/multipart/bucket/object/uploads.json' on all the
|
|
|
|
// disks. `uploads.json` carries metadata regarding on-going multipart
|
|
|
|
// operation(s) on the object.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) newMultipartUpload(ctx context.Context, bucket string, object string, opts ObjectOptions) (string, error) {
|
2022-05-05 07:14:41 -04:00
|
|
|
userDefined := cloneMSS(opts.UserDefined)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
onlineDisks := er.getDisks()
|
2022-05-05 07:14:41 -04:00
|
|
|
parityDrives := globalStorageClass.GetParityForSC(userDefined[xhttp.AmzStorageClass])
|
2022-06-27 23:22:18 -04:00
|
|
|
if parityDrives < 0 {
|
2021-04-21 22:06:08 -04:00
|
|
|
parityDrives = er.defaultParityCount
|
2019-10-07 01:50:24 -04:00
|
|
|
}
|
2017-12-22 06:28:13 -05:00
|
|
|
|
2021-05-27 16:38:04 -04:00
|
|
|
parityOrig := parityDrives
|
2021-05-27 14:38:09 -04:00
|
|
|
for _, disk := range onlineDisks {
|
|
|
|
if parityDrives >= len(onlineDisks)/2 {
|
2021-05-27 16:38:04 -04:00
|
|
|
parityDrives = len(onlineDisks) / 2
|
2021-05-27 14:38:09 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if disk == nil {
|
|
|
|
parityDrives++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
di, err := disk.DiskInfo(ctx)
|
|
|
|
if err != nil || di.ID == "" {
|
|
|
|
parityDrives++
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 16:38:04 -04:00
|
|
|
if parityOrig != parityDrives {
|
2022-05-05 07:14:41 -04:00
|
|
|
userDefined[minIOErasureUpgraded] = strconv.Itoa(parityOrig) + "->" + strconv.Itoa(parityDrives)
|
2021-05-27 14:38:09 -04:00
|
|
|
}
|
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
dataDrives := len(onlineDisks) - parityDrives
|
2021-05-27 14:38:09 -04:00
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
// we now know the number of blocks this object needs for data and parity.
|
|
|
|
// establish the writeQuorum using this data
|
2021-04-21 22:06:08 -04:00
|
|
|
writeQuorum := dataDrives
|
|
|
|
if dataDrives == parityDrives {
|
2021-01-16 15:08:02 -05:00
|
|
|
writeQuorum++
|
2020-06-09 22:19:03 -04:00
|
|
|
}
|
2017-12-22 06:28:13 -05:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
// Initialize parts metadata
|
|
|
|
partsMetadata := make([]FileInfo, len(onlineDisks))
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
fi := newFileInfo(pathJoin(bucket, object), dataDrives, parityDrives)
|
2021-04-24 22:07:27 -04:00
|
|
|
fi.VersionID = opts.VersionID
|
|
|
|
if opts.Versioned && fi.VersionID == "" {
|
|
|
|
fi.VersionID = mustGetUUID()
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.DataDir = mustGetUUID()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
// Initialize erasure metadata.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index] = fi
|
|
|
|
}
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
// Guess content-type from the extension if possible.
|
2022-05-05 07:14:41 -04:00
|
|
|
if userDefined["content-type"] == "" {
|
|
|
|
userDefined["content-type"] = mimedb.TypeByExtension(path.Ext(object))
|
2021-04-21 22:06:08 -04:00
|
|
|
}
|
2019-04-25 10:33:26 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
modTime := opts.MTime
|
|
|
|
if opts.MTime.IsZero() {
|
|
|
|
modTime = UTCNow()
|
2019-09-11 13:22:12 -04:00
|
|
|
}
|
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
onlineDisks, partsMetadata = shuffleDisksAndPartsMetadata(onlineDisks, partsMetadata, fi)
|
2020-10-28 03:09:15 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
// Fill all the necessary metadata.
|
|
|
|
// Update `xl.meta` content on each disks.
|
|
|
|
for index := range partsMetadata {
|
2021-08-10 14:12:22 -04:00
|
|
|
partsMetadata[index].Fresh = true
|
2021-04-21 22:06:08 -04:00
|
|
|
partsMetadata[index].ModTime = modTime
|
2022-05-05 07:14:41 -04:00
|
|
|
partsMetadata[index].Metadata = userDefined
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-10-24 20:37:18 -04:00
|
|
|
|
2021-04-21 22:06:08 -04:00
|
|
|
uploadID := mustGetUUID()
|
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
|
|
|
|
// Write updated `xl.meta` to all disks.
|
|
|
|
if _, err := writeUniqueFileInfo(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath, partsMetadata, writeQuorum); err != nil {
|
2019-09-11 13:22:12 -04:00
|
|
|
return "", toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return success.
|
|
|
|
return uploadID, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// NewMultipartUpload - initialize a new multipart upload, returns a
|
|
|
|
// unique id. The unique id returned here is of UUID form, for each
|
|
|
|
// subsequent request each UUID is unique.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible initiate multipart API.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (string, error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return er.newMultipartUpload(ctx, bucket, object, opts)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
|
2017-01-31 12:38:34 -05: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.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) 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) {
|
2021-02-10 11:52:50 -05:00
|
|
|
partInfo, err := er.PutObjectPart(ctx, dstBucket, dstObject, uploadID, partID, NewPutObjReader(srcInfo.Reader), dstOpts)
|
2017-10-22 01:30:34 -04:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, dstBucket, dstObject)
|
|
|
|
}
|
|
|
|
|
2017-01-31 12:38:34 -05:00
|
|
|
// Success.
|
|
|
|
return partInfo, nil
|
|
|
|
}
|
|
|
|
|
2022-01-13 14:07:41 -05:00
|
|
|
func undoRenamePart(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, errs []error) {
|
|
|
|
// Undo rename object on disks where RenameFile succeeded.
|
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
for index, disk := range disks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if errs[index] == nil {
|
|
|
|
_ = disks[index].RenameFile(context.TODO(), dstBucket, dstEntry, srcBucket, srcEntry)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
g.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// renamePart - renames multipart part to its relevant location under uploadID.
|
|
|
|
func renamePart(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, writeQuorum int) ([]StorageAPI, error) {
|
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
|
|
|
|
// Rename file on all underlying storage disks.
|
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
return disks[index].RenameFile(ctx, srcBucket, srcEntry, dstBucket, dstEntry)
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all renames to finish.
|
|
|
|
errs := g.Wait()
|
|
|
|
|
|
|
|
// We can safely allow RenameFile errors up to len(er.getDisks()) - writeQuorum
|
|
|
|
// otherwise return failure. Cleanup successful renames.
|
|
|
|
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
|
|
|
if err == errErasureWriteQuorum {
|
|
|
|
// Undo all the partial rename operations.
|
|
|
|
undoRenamePart(disks, srcBucket, srcEntry, dstBucket, dstEntry, errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
return evalDisks(disks, errs), err
|
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// writeAllDisks - writes 'b' to all provided disks.
|
|
|
|
// If write cannot reach quorum, the files will be deleted from all disks.
|
|
|
|
func writeAllDisks(ctx context.Context, disks []StorageAPI, dstBucket, dstEntry string, b []byte, writeQuorum int) ([]StorageAPI, error) {
|
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
|
|
|
|
// Write file to all underlying storage disks.
|
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
return disks[index].WriteAll(ctx, dstBucket, dstEntry, b)
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all renames to finish.
|
|
|
|
errs := g.Wait()
|
|
|
|
|
|
|
|
// We can safely allow RenameFile errors up to len(er.getDisks()) - writeQuorum
|
|
|
|
// otherwise return failure. Cleanup successful renames.
|
|
|
|
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
|
|
|
if err == errErasureWriteQuorum {
|
|
|
|
// Remove all written
|
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
for index := range disks {
|
|
|
|
if disks[index] == nil || errs[index] != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
return disks[index].Delete(ctx, dstBucket, dstEntry, DeleteOptions{Force: true})
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
// Ignore these errors.
|
|
|
|
g.WaitErr()
|
|
|
|
}
|
|
|
|
|
|
|
|
return evalDisks(disks, errs), err
|
|
|
|
}
|
|
|
|
|
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.
|
2020-09-14 18:57:13 -04:00
|
|
|
func (er erasureObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, r *PutObjReader, opts ObjectOptions) (pi PartInfo, err error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2021-06-16 16:21:36 -04:00
|
|
|
// Write lock for this part ID.
|
|
|
|
// Held throughout the operation.
|
|
|
|
partIDLock := er.NewNSLock(bucket, pathJoin(object, uploadID, strconv.Itoa(partID)))
|
|
|
|
plkctx, err := partIDLock.GetLock(ctx, globalOperationTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return PartInfo{}, err
|
|
|
|
}
|
|
|
|
pctx := plkctx.Context()
|
|
|
|
defer partIDLock.Unlock(plkctx.Cancel)
|
|
|
|
|
|
|
|
// Read lock for upload id.
|
|
|
|
// Only held while reading the upload metadata.
|
|
|
|
uploadIDRLock := er.NewNSLock(bucket, pathJoin(object, uploadID))
|
|
|
|
rlkctx, err := uploadIDRLock.GetRLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return PartInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
rctx := rlkctx.Context()
|
2022-07-19 11:35:29 -04:00
|
|
|
defer uploadIDRLock.RUnlock(rlkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2018-11-14 20:36:41 -05:00
|
|
|
data := r.Reader
|
2017-10-06 12:38:01 -04:00
|
|
|
// Validate input data size and it can never be less than zero.
|
2018-09-27 23:36:17 -04:00
|
|
|
if data.Size() < -1 {
|
2021-04-27 19:12:50 -04:00
|
|
|
logger.LogIf(rctx, errInvalidArgument, logger.Application)
|
2018-04-05 18:04:40 -04:00
|
|
|
return pi, toObjectErr(errInvalidArgument)
|
2017-10-06 12:38:01 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
var partsMetadata []FileInfo
|
2016-07-11 20:24:49 -04:00
|
|
|
var errs []error
|
2020-06-12 23:04:01 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
2017-10-06 12:38:01 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
// Validates if upload ID exists.
|
2021-04-27 19:12:50 -04:00
|
|
|
if err = er.checkUploadIDExists(rctx, bucket, object, uploadID); err != nil {
|
2019-04-23 17:54:28 -04:00
|
|
|
return pi, toObjectErr(err, bucket, object, uploadID)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-01-31 12:38:34 -05:00
|
|
|
|
2020-12-07 13:04:07 -05:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2021-04-27 19:12:50 -04:00
|
|
|
partsMetadata, errs = readAllFileInfo(rctx, storageDisks, minioMetaMultipartBucket,
|
2021-01-07 22:27:31 -05:00
|
|
|
uploadIDPath, "", false)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2021-06-16 16:21:36 -04:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(pctx, partsMetadata, errs, er.defaultParityCount)
|
2017-12-22 06:28:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2021-06-16 16:21:36 -04:00
|
|
|
reducedErr := reduceWriteQuorumErrs(pctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2020-06-12 23:04:01 -04:00
|
|
|
if reducedErr == errErasureWriteQuorum {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(reducedErr, bucket, object)
|
2016-06-27 13:01:09 -04:00
|
|
|
}
|
2016-05-30 14:26:10 -04:00
|
|
|
|
2016-05-25 19:42:31 -04:00
|
|
|
// List all online disks.
|
2021-11-21 13:41:30 -05:00
|
|
|
onlineDisks, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2016-07-12 18:20:31 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2021-11-21 13:41:30 -05:00
|
|
|
fi, err := pickValidFileInfo(pctx, partsMetadata, modTime, writeQuorum)
|
2016-11-20 23:56:44 -05:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, err
|
2016-11-20 23:56:44 -05:00
|
|
|
}
|
2016-07-14 17:59:01 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
onlineDisks = shuffleDisks(onlineDisks, fi.Erasure.Distribution)
|
2016-05-26 22:55:48 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
// Need a unique name for the part being written in minioMetaBucket to
|
|
|
|
// accommodate concurrent PutObjectPart requests
|
2016-07-12 18:20:31 -04:00
|
|
|
|
2016-06-28 00:42:33 -04:00
|
|
|
partSuffix := fmt.Sprintf("part.%d", partID)
|
2016-11-22 19:52:37 -05:00
|
|
|
tmpPart := mustGetUUID()
|
2020-06-12 23:04:01 -04:00
|
|
|
tmpPartPath := pathJoin(tmpPart, partSuffix)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-10-20 01:52:03 -04:00
|
|
|
// Delete the temporary object part. If PutObjectPart succeeds there would be nothing to delete.
|
2021-03-24 17:19:52 -04:00
|
|
|
var online int
|
|
|
|
defer func() {
|
|
|
|
if online != len(onlineDisks) {
|
2022-01-13 14:07:41 -05:00
|
|
|
er.renameAll(context.Background(), minioMetaTmpBucket, tmpPart)
|
2021-03-24 17:19:52 -04:00
|
|
|
}
|
|
|
|
}()
|
2018-11-26 16:20:21 -05:00
|
|
|
|
2021-06-16 16:21:36 -04:00
|
|
|
erasure, err := NewErasure(pctx, fi.Erasure.DataBlocks, fi.Erasure.ParityBlocks, fi.Erasure.BlockSize)
|
2017-08-14 21:08:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
2018-02-15 20:45:57 -05:00
|
|
|
|
|
|
|
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
2018-06-13 14:55:12 -04:00
|
|
|
var buffer []byte
|
|
|
|
switch size := data.Size(); {
|
|
|
|
case size == 0:
|
|
|
|
buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF
|
2021-03-03 19:28:10 -05:00
|
|
|
case size == -1:
|
|
|
|
if size := data.ActualSize(); size > 0 && size < fi.Erasure.BlockSize {
|
|
|
|
buffer = make([]byte, data.ActualSize()+256, data.ActualSize()*2+512)
|
|
|
|
} else {
|
|
|
|
buffer = er.bp.Get()
|
|
|
|
defer er.bp.Put(buffer)
|
|
|
|
}
|
|
|
|
case size >= fi.Erasure.BlockSize:
|
2020-06-12 23:04:01 -04:00
|
|
|
buffer = er.bp.Get()
|
|
|
|
defer er.bp.Put(buffer)
|
|
|
|
case size < fi.Erasure.BlockSize:
|
|
|
|
// No need to allocate fully fi.Erasure.BlockSize buffer if the incoming data is smaller.
|
|
|
|
buffer = make([]byte, size, 2*size+int64(fi.Erasure.ParityBlocks+fi.Erasure.DataBlocks-1))
|
2018-06-13 14:55:12 -04:00
|
|
|
}
|
2018-02-15 20:45:57 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if len(buffer) > int(fi.Erasure.BlockSize) {
|
|
|
|
buffer = buffer[:fi.Erasure.BlockSize]
|
2018-08-06 18:14:08 -04:00
|
|
|
}
|
2019-01-17 07:58:18 -05:00
|
|
|
writers := make([]io.Writer, len(onlineDisks))
|
2018-08-06 18:14:08 -04:00
|
|
|
for i, disk := range onlineDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2021-05-17 11:32:28 -04:00
|
|
|
writers[i] = newBitrotWriter(disk, minioMetaTmpBucket, tmpPartPath, erasure.ShardFileSize(data.Size()), DefaultBitrotAlgorithm, erasure.ShardSize())
|
2018-08-06 18:14:08 -04:00
|
|
|
}
|
2018-11-26 16:20:21 -05:00
|
|
|
|
2022-01-14 13:01:25 -05:00
|
|
|
toEncode := io.Reader(data)
|
|
|
|
if data.Size() > bigFileThreshold {
|
|
|
|
// Add input readahead.
|
|
|
|
// We use 2 buffers, so we always have a full buffer of input.
|
|
|
|
bufA := er.bp.Get()
|
|
|
|
bufB := er.bp.Get()
|
|
|
|
defer er.bp.Put(bufA)
|
|
|
|
defer er.bp.Put(bufB)
|
|
|
|
ra, err := readahead.NewReaderBuffer(data, [][]byte{bufA[:fi.Erasure.BlockSize], bufB[:fi.Erasure.BlockSize]})
|
|
|
|
if err == nil {
|
|
|
|
toEncode = ra
|
|
|
|
defer ra.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err := erasure.Encode(pctx, toEncode, writers, buffer, writeQuorum)
|
2019-01-17 07:58:18 -05:00
|
|
|
closeBitrotWriters(writers)
|
2016-07-18 22:06:48 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, bucket, object)
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-10-20 01:52:03 -04:00
|
|
|
|
2016-07-18 22:06:48 -04:00
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
2018-08-06 18:14:08 -04:00
|
|
|
if n < data.Size() {
|
2020-09-08 17:22:04 -04:00
|
|
|
return pi, IncompleteBody{Bucket: bucket, Object: object}
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2018-08-06 18:14:08 -04:00
|
|
|
for i := range writers {
|
|
|
|
if writers[i] == nil {
|
|
|
|
onlineDisks[i] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 18:38:14 -04:00
|
|
|
// Rename temporary part file to its final location.
|
2020-06-12 23:04:01 -04:00
|
|
|
partPath := pathJoin(uploadIDPath, fi.DataDir, partSuffix)
|
2022-07-19 11:35:29 -04:00
|
|
|
onlineDisks, err = renamePart(ctx, onlineDisks, minioMetaTmpBucket, tmpPartPath, minioMetaMultipartBucket, partPath, writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-26 06:15:01 -04:00
|
|
|
|
2018-11-14 20:36:41 -05:00
|
|
|
md5hex := r.MD5CurrentHexString()
|
2022-07-16 22:35:24 -04:00
|
|
|
if opts.PreserveETag != "" {
|
|
|
|
md5hex = opts.PreserveETag
|
|
|
|
}
|
2022-07-19 11:35:29 -04:00
|
|
|
|
2022-07-11 20:30:56 -04:00
|
|
|
var index []byte
|
|
|
|
if opts.IndexCB != nil {
|
|
|
|
index = opts.IndexCB()
|
|
|
|
}
|
2017-10-22 01:30:34 -04:00
|
|
|
|
2022-07-19 21:56:24 -04:00
|
|
|
part := ObjectPartInfo{
|
|
|
|
Number: partID,
|
|
|
|
ETag: md5hex,
|
|
|
|
Size: n,
|
|
|
|
ActualSize: data.ActualSize(),
|
|
|
|
ModTime: UTCNow(),
|
|
|
|
Index: index,
|
|
|
|
}
|
2016-05-26 06:15:01 -04:00
|
|
|
|
2022-07-19 21:56:24 -04:00
|
|
|
partMsg, err := part.MarshalMsg(nil)
|
2022-07-19 11:35:29 -04:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Write part metadata to all disks.
|
2022-07-19 21:56:24 -04:00
|
|
|
onlineDisks, err = writeAllDisks(ctx, onlineDisks, minioMetaMultipartBucket, partPath+".meta", partMsg, writeQuorum)
|
2022-07-19 11:35:29 -04:00
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2017-01-31 12:38:34 -05:00
|
|
|
}
|
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// Return success.
|
2017-01-31 12:38:34 -05:00
|
|
|
return PartInfo{
|
2022-07-19 21:56:24 -04:00
|
|
|
PartNumber: part.Number,
|
|
|
|
ETag: part.ETag,
|
|
|
|
LastModified: part.ModTime,
|
|
|
|
Size: part.Size,
|
|
|
|
ActualSize: part.ActualSize,
|
2017-01-31 12:38:34 -05:00
|
|
|
}, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
// GetMultipartInfo returns multipart metadata uploaded during newMultipartUpload, used
|
|
|
|
// by callers to verify object states
|
|
|
|
// - encrypted
|
|
|
|
// - compressed
|
2022-07-19 11:35:29 -04:00
|
|
|
// Does not contain currently uploaded parts by design.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (MultipartInfo, error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
result := MultipartInfo{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
UploadID: uploadID,
|
|
|
|
}
|
|
|
|
|
2020-11-04 11:25:42 -05:00
|
|
|
uploadIDLock := er.NewNSLock(bucket, pathJoin(object, uploadID))
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := uploadIDLock.GetRLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return MultipartInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer uploadIDLock.RUnlock(lkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := er.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2020-05-28 15:36:20 -04:00
|
|
|
return result, toObjectErr(err, bucket, object, uploadID)
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
2020-05-28 15:36:20 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
2020-05-28 15:36:20 -04:00
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-01-07 22:27:31 -05:00
|
|
|
partsMetadata, errs := readAllFileInfo(ctx, storageDisks, minioMetaMultipartBucket, uploadIDPath, opts.VersionID, false)
|
2020-05-28 15:36:20 -04:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2021-01-16 15:08:02 -05:00
|
|
|
readQuorum, _, err := objectQuorumFromMeta(ctx, partsMetadata, errs, er.defaultParityCount)
|
2020-05-28 15:36:20 -04:00
|
|
|
if err != nil {
|
|
|
|
return result, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, readQuorum)
|
|
|
|
if reducedErr == errErasureReadQuorum {
|
2020-05-28 15:36:20 -04:00
|
|
|
return result, toObjectErr(reducedErr, minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
}
|
|
|
|
|
2021-11-21 13:41:30 -05:00
|
|
|
_, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2020-05-28 15:36:20 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2021-11-21 13:41:30 -05:00
|
|
|
fi, err := pickValidFileInfo(ctx, partsMetadata, modTime, readQuorum)
|
2020-05-28 15:36:20 -04:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2020-09-10 14:37:22 -04:00
|
|
|
result.UserDefined = cloneMSS(fi.Metadata)
|
2020-05-28 15:36:20 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-03-15 16:55:23 -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
|
2018-06-28 19:02:02 -04:00
|
|
|
// ListPartsInfo structure is marshaled directly into XML and
|
2018-03-15 16:55:23 -04:00
|
|
|
// replied back to the client.
|
2021-03-03 21:36:43 -05:00
|
|
|
func (er erasureObjects) ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker, maxParts int, opts ObjectOptions) (result ListPartsInfo, err error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2020-11-04 11:25:42 -05:00
|
|
|
uploadIDLock := er.NewNSLock(bucket, pathJoin(object, uploadID))
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := uploadIDLock.GetRLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return ListPartsInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer uploadIDLock.RUnlock(lkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := er.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2019-04-23 17:54:28 -04:00
|
|
|
return result, toObjectErr(err, bucket, object, uploadID)
|
2018-03-15 16:55:23 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
2019-02-01 11:58:41 -05:00
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-01-07 22:27:31 -05:00
|
|
|
partsMetadata, errs := readAllFileInfo(ctx, storageDisks, minioMetaMultipartBucket, uploadIDPath, "", false)
|
2019-02-01 11:58:41 -05:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2021-01-16 15:08:02 -05:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(ctx, partsMetadata, errs, er.defaultParityCount)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2018-03-15 16:55:23 -04:00
|
|
|
return result, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2019-02-01 11:58:41 -05:00
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2020-06-12 23:04:01 -04:00
|
|
|
if reducedErr == errErasureWriteQuorum {
|
2019-09-16 17:27:34 -04:00
|
|
|
return result, toObjectErr(reducedErr, minioMetaMultipartBucket, uploadIDPath)
|
2019-02-01 11:58:41 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
onlineDisks, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2019-02-01 11:58:41 -05:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2021-11-21 13:41:30 -05:00
|
|
|
fi, err := pickValidFileInfo(ctx, partsMetadata, modTime, writeQuorum)
|
2019-02-01 11:58:41 -05:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:47:58 -04:00
|
|
|
if maxParts == 0 {
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if partNumberMarker < 0 {
|
|
|
|
partNumberMarker = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit output to maxPartsList.
|
|
|
|
if maxParts > maxPartsList-partNumberMarker {
|
|
|
|
maxParts = maxPartsList - partNumberMarker
|
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Read Part info for all parts
|
|
|
|
partPath := pathJoin(uploadIDPath, fi.DataDir) + "/"
|
|
|
|
req := ReadMultipleReq{
|
2022-07-21 19:47:58 -04:00
|
|
|
Bucket: minioMetaMultipartBucket,
|
|
|
|
Prefix: partPath,
|
|
|
|
MaxSize: 1 << 20, // Each part should realistically not be > 1MiB.
|
|
|
|
MaxResults: maxParts + 1,
|
2022-07-19 11:35:29 -04:00
|
|
|
}
|
|
|
|
|
2022-07-21 19:47:58 -04:00
|
|
|
start := partNumberMarker + 1
|
|
|
|
end := start + maxParts
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Parts are 1 based, so index 0 is part one, etc.
|
2022-07-21 19:47:58 -04:00
|
|
|
for i := start; i <= end; i++ {
|
2022-07-19 11:35:29 -04:00
|
|
|
req.Files = append(req.Files, fmt.Sprintf("part.%d.meta", i))
|
|
|
|
}
|
|
|
|
|
|
|
|
partInfoFiles, err := readMultipleFiles(ctx, onlineDisks, req, writeQuorum)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Populate the result stub.
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
result.MaxParts = maxParts
|
2018-01-31 16:17:24 -05:00
|
|
|
result.PartNumberMarker = partNumberMarker
|
2020-09-10 14:37:22 -04:00
|
|
|
result.UserDefined = cloneMSS(fi.Metadata)
|
2016-05-25 00:24:20 -04:00
|
|
|
|
|
|
|
// For empty number of parts or maxParts as zero, return right here.
|
2022-07-19 11:35:29 -04:00
|
|
|
if len(partInfoFiles) == 0 || maxParts == 0 {
|
2016-05-25 00:24:20 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2022-07-19 21:56:24 -04:00
|
|
|
var partI ObjectPartInfo
|
2022-07-19 11:35:29 -04:00
|
|
|
for i, part := range partInfoFiles {
|
2022-07-21 19:47:58 -04:00
|
|
|
partN := i + partNumberMarker + 1
|
2022-07-19 11:35:29 -04:00
|
|
|
if part.Error != "" || !part.Exists {
|
|
|
|
continue
|
|
|
|
}
|
2022-07-19 21:56:24 -04:00
|
|
|
|
|
|
|
_, err := partI.UnmarshalMsg(part.Data)
|
2022-07-19 11:35:29 -04:00
|
|
|
if err != nil {
|
|
|
|
// Maybe crash or similar.
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:47:58 -04:00
|
|
|
if partN != partI.Number {
|
2022-07-19 21:56:24 -04:00
|
|
|
logger.LogIf(ctx, fmt.Errorf("part.%d.meta has incorrect corresponding part number: expected %d, got %d", i+1, i+1, partI.Number))
|
2022-07-19 11:35:29 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the current part.
|
2022-07-19 21:56:24 -04:00
|
|
|
fi.AddObjectPart(partI.Number, partI.ETag, partI.Size, partI.ActualSize, partI.ModTime, partI.Index)
|
2022-07-19 11:35:29 -04:00
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Only parts with higher part numbers will be listed.
|
2020-06-12 23:04:01 -04:00
|
|
|
parts := fi.Parts
|
2022-07-19 21:56:24 -04:00
|
|
|
result.Parts = make([]PartInfo, 0, len(parts))
|
2016-05-25 00:24:20 -04:00
|
|
|
for _, part := range parts {
|
2017-01-31 12:38:34 -05: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,
|
2022-07-19 21:56:24 -04:00
|
|
|
LastModified: part.ModTime,
|
|
|
|
ActualSize: part.ActualSize,
|
2016-05-28 03:18:58 -04:00
|
|
|
Size: part.Size,
|
2016-05-20 23:48:47 -04:00
|
|
|
})
|
2022-07-21 19:47:58 -04:00
|
|
|
if len(result.Parts) >= maxParts {
|
2016-05-20 23:48:47 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 19:47:58 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// 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
|
|
|
// 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.
|
2020-09-14 18:57:13 -04:00
|
|
|
func (er erasureObjects) CompleteMultipartUpload(ctx context.Context, bucket string, object string, uploadID string, parts []CompletePart, opts ObjectOptions) (oi ObjectInfo, err error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Hold write locks to verify uploaded parts, also disallows any
|
|
|
|
// parallel PutObjectPart() requests.
|
2020-11-04 11:25:42 -05:00
|
|
|
uploadIDLock := er.NewNSLock(bucket, pathJoin(object, uploadID))
|
2022-07-19 11:35:29 -04:00
|
|
|
wlkctx, err := uploadIDLock.GetLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return oi, err
|
|
|
|
}
|
2022-07-19 11:35:29 -04:00
|
|
|
wctx := wlkctx.Context()
|
|
|
|
defer uploadIDLock.Unlock(wlkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
if err = er.checkUploadIDExists(wctx, bucket, object, uploadID); err != nil {
|
2019-04-23 17:54:28 -04:00
|
|
|
return oi, toObjectErr(err, bucket, object, uploadID)
|
2016-05-28 00:50:09 -04:00
|
|
|
}
|
2017-02-21 22:43:44 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
2019-11-19 20:42:27 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
2020-01-15 21:30:32 -05:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2022-07-19 11:35:29 -04:00
|
|
|
partsMetadata, errs := readAllFileInfo(wctx, storageDisks, minioMetaMultipartBucket, uploadIDPath, "", false)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
|
|
|
// get Quorum for this object
|
2022-07-19 11:35:29 -04:00
|
|
|
_, writeQuorum, err := objectQuorumFromMeta(wctx, partsMetadata, errs, er.defaultParityCount)
|
2017-12-22 06:28:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return oi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
reducedErr := reduceWriteQuorumErrs(wctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2020-06-12 23:04:01 -04:00
|
|
|
if reducedErr == errErasureWriteQuorum {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(reducedErr, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2021-11-21 13:41:30 -05:00
|
|
|
onlineDisks, modTime := listOnlineDisks(storageDisks, partsMetadata, errs)
|
2021-04-21 22:06:08 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2022-07-19 11:35:29 -04:00
|
|
|
fi, err := pickValidFileInfo(wctx, partsMetadata, modTime, writeQuorum)
|
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read Part info for all parts
|
|
|
|
partPath := pathJoin(uploadIDPath, fi.DataDir) + "/"
|
|
|
|
req := ReadMultipleReq{
|
2022-07-21 19:47:58 -04:00
|
|
|
Bucket: minioMetaMultipartBucket,
|
|
|
|
Prefix: partPath,
|
|
|
|
MaxSize: 1 << 20, // Each part should realistically not be > 1MiB.
|
|
|
|
Files: make([]string, 0, len(parts)),
|
|
|
|
AbortOn404: true,
|
2022-07-19 11:35:29 -04:00
|
|
|
}
|
|
|
|
for _, part := range parts {
|
|
|
|
req.Files = append(req.Files, fmt.Sprintf("part.%d.meta", part.PartNumber))
|
|
|
|
}
|
|
|
|
partInfoFiles, err := readMultipleFiles(ctx, onlineDisks, req, writeQuorum)
|
2021-04-21 22:06:08 -04:00
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
2022-07-19 11:35:29 -04:00
|
|
|
if len(partInfoFiles) != len(parts) {
|
|
|
|
// Should only happen through internal error
|
|
|
|
err := fmt.Errorf("unexpected part result count: %d, want %d", len(partInfoFiles), len(parts))
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return oi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2022-07-19 21:56:24 -04:00
|
|
|
var partI ObjectPartInfo
|
2022-07-19 11:35:29 -04:00
|
|
|
for i, part := range partInfoFiles {
|
|
|
|
partID := parts[i].PartNumber
|
|
|
|
if part.Error != "" || !part.Exists {
|
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: partID,
|
|
|
|
}
|
|
|
|
}
|
2022-07-19 21:56:24 -04:00
|
|
|
|
|
|
|
_, err := partI.UnmarshalMsg(part.Data)
|
2022-07-19 11:35:29 -04:00
|
|
|
if err != nil {
|
|
|
|
// Maybe crash or similar.
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: partID,
|
|
|
|
}
|
|
|
|
}
|
2022-07-19 21:56:24 -04:00
|
|
|
|
|
|
|
if partID != partI.Number {
|
|
|
|
logger.LogIf(ctx, fmt.Errorf("part.%d.meta has incorrect corresponding part number: expected %d, got %d", partID, partID, partI.Number))
|
2022-07-19 11:35:29 -04:00
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: partID,
|
|
|
|
}
|
|
|
|
}
|
2022-07-19 21:56:24 -04:00
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Add the current part.
|
2022-07-19 21:56:24 -04:00
|
|
|
fi.AddObjectPart(partI.Number, partI.ETag, partI.Size, partI.ActualSize, partI.ModTime, partI.Index)
|
2022-07-19 11:35:29 -04:00
|
|
|
}
|
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
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// Calculate consolidated actual size.
|
|
|
|
var objectActualSize int64
|
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
// Order online disks in accordance with distribution order.
|
|
|
|
// Order parts metadata in accordance with distribution order.
|
2021-03-15 23:03:13 -04:00
|
|
|
onlineDisks, partsMetadata = shuffleDisksAndPartsMetadataByIndex(onlineDisks, partsMetadata, fi)
|
2016-07-27 14:57:08 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Save current erasure metadata for validation.
|
2022-01-02 12:15:06 -05:00
|
|
|
currentFI := fi
|
2016-05-25 00:24:20 -04:00
|
|
|
|
|
|
|
// Allocate parts similar to incoming slice.
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.Parts = make([]ObjectPartInfo, len(parts))
|
2016-05-25 00:24:20 -04:00
|
|
|
|
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 {
|
2020-06-12 23:04:01 -04:00
|
|
|
partIdx := objectPartIndex(currentFI.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 {
|
2018-08-14 21:35:30 -04:00
|
|
|
invp := InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
GotETag: part.ETag,
|
|
|
|
}
|
|
|
|
return oi, invp
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// ensure that part ETag is canonicalized to strip off extraneous quotes
|
|
|
|
part.ETag = canonicalizeETag(part.ETag)
|
|
|
|
if currentFI.Parts[partIdx].ETag != part.ETag {
|
2018-08-14 21:35:30 -04:00
|
|
|
invp := InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
2020-06-12 23:04:01 -04:00
|
|
|
ExpETag: currentFI.Parts[partIdx].ETag,
|
2018-08-14 21:35:30 -04:00
|
|
|
GotETag: part.ETag,
|
|
|
|
}
|
|
|
|
return oi, invp
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// All parts except the last part has to be at least 5MB.
|
2020-06-12 23:04:01 -04:00
|
|
|
if (i < len(parts)-1) && !isMinAllowedPartSize(currentFI.Parts[partIdx].ActualSize) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return oi, PartTooSmall{
|
|
|
|
PartNumber: part.PartNumber,
|
2020-06-12 23:04:01 -04:00
|
|
|
PartSize: currentFI.Parts[partIdx].ActualSize,
|
2018-04-05 18:04:40 -04:00
|
|
|
PartETag: part.ETag,
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
|
|
|
// Save for total object size.
|
2020-06-12 23:04:01 -04:00
|
|
|
objectSize += currentFI.Parts[partIdx].Size
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// Save the consolidated actual size.
|
2020-06-12 23:04:01 -04:00
|
|
|
objectActualSize += currentFI.Parts[partIdx].ActualSize
|
2018-09-27 23:36:17 -04:00
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Add incoming parts.
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.Parts[i] = ObjectPartInfo{
|
2018-09-27 23:36:17 -04:00
|
|
|
Number: part.PartNumber,
|
2020-06-12 23:04:01 -04:00
|
|
|
Size: currentFI.Parts[partIdx].Size,
|
|
|
|
ActualSize: currentFI.Parts[partIdx].ActualSize,
|
2022-07-19 21:56:24 -04:00
|
|
|
ModTime: currentFI.Parts[partIdx].ModTime,
|
2022-07-11 20:30:56 -04:00
|
|
|
Index: currentFI.Parts[partIdx].Index,
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the final object size and modtime.
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.Size = objectSize
|
2020-07-08 20:36:56 -04:00
|
|
|
fi.ModTime = opts.MTime
|
|
|
|
if opts.MTime.IsZero() {
|
|
|
|
fi.ModTime = UTCNow()
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
// Save successfully calculated md5sum.
|
2021-09-09 01:25:23 -04:00
|
|
|
fi.Metadata["etag"] = opts.UserDefined["etag"]
|
|
|
|
if fi.Metadata["etag"] == "" {
|
|
|
|
fi.Metadata["etag"] = getCompleteMultipartMD5(parts)
|
2020-08-12 20:32:24 -04:00
|
|
|
}
|
2017-10-22 01:30:34 -04:00
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// Save the consolidated actual size.
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.Metadata[ReservedMetadataPrefix+"actual-size"] = strconv.FormatInt(objectActualSize, 10)
|
2018-09-27 23:36:17 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Update all erasure metadata, make sure to not modify fields like
|
2016-05-31 23:23:31 -04:00
|
|
|
// checksum which are different on each disks.
|
|
|
|
for index := range partsMetadata {
|
2020-11-20 12:10:48 -05:00
|
|
|
if partsMetadata[index].IsValid() {
|
|
|
|
partsMetadata[index].Size = fi.Size
|
|
|
|
partsMetadata[index].ModTime = fi.ModTime
|
|
|
|
partsMetadata[index].Metadata = fi.Metadata
|
|
|
|
partsMetadata[index].Parts = fi.Parts
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2021-04-29 23:55:21 -04:00
|
|
|
// Hold namespace to complete the transaction
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
|
|
|
lkctx, err := lk.GetLock(ctx, globalOperationTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Write final `xl.meta` at uploadID location
|
2021-04-29 23:55:21 -04:00
|
|
|
onlineDisks, err = writeUniqueFileInfo(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath, partsMetadata, writeQuorum)
|
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return oi, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
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.
|
2020-06-12 23:04:01 -04:00
|
|
|
for _, curpart := range currentFI.Parts {
|
|
|
|
if objectPartIndex(fi.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.
|
2020-06-12 23:04:01 -04:00
|
|
|
er.removeObjectPart(bucket, object, uploadID, fi.DataDir, curpart.Number)
|
2016-05-28 16:23:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
// Remove part.meta which is not needed anymore.
|
|
|
|
for _, part := range fi.Parts {
|
|
|
|
er.removePartMeta(bucket, object, uploadID, fi.DataDir, part.Number)
|
|
|
|
}
|
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename the multipart object to final location.
|
2020-06-12 23:04:01 -04:00
|
|
|
if onlineDisks, err = renameData(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath,
|
2021-04-20 13:44:39 -04:00
|
|
|
partsMetadata, bucket, object, writeQuorum); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2020-01-15 21:30:32 -05:00
|
|
|
// Check if there is any offline disk and add it to the MRF list
|
2020-12-22 12:16:43 -05:00
|
|
|
for _, disk := range onlineDisks {
|
|
|
|
if disk != nil && disk.IsOnline() {
|
|
|
|
continue
|
2020-01-15 21:30:32 -05:00
|
|
|
}
|
2021-07-16 01:32:06 -04:00
|
|
|
er.addPartial(bucket, object, fi.VersionID, fi.Size)
|
2020-12-22 12:16:43 -05:00
|
|
|
break
|
2020-01-15 21:30:32 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
for i := 0; i < len(onlineDisks); i++ {
|
2020-12-22 12:16:43 -05:00
|
|
|
if onlineDisks[i] != nil && onlineDisks[i].IsOnline() {
|
|
|
|
// Object info is the same in all disks, so we can pick
|
|
|
|
// the first meta from online disk
|
|
|
|
fi = partsMetadata[i]
|
|
|
|
break
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 22:17:09 -04:00
|
|
|
// we are adding a new version to this object under the namespace lock, so this is the latest version.
|
|
|
|
fi.IsLatest = true
|
|
|
|
|
2017-01-16 22:23:43 -05:00
|
|
|
// Success, return object info.
|
2022-05-31 05:57:57 -04:00
|
|
|
return fi.ToObjectInfo(bucket, object, opts.Versioned || opts.VersionSuspended), nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04: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.
|
2021-03-03 21:36:43 -05:00
|
|
|
func (er erasureObjects) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (err error) {
|
2022-05-04 03:45:27 -04:00
|
|
|
auditObjectErasureSet(ctx, object, &er)
|
|
|
|
|
2020-11-04 11:25:42 -05:00
|
|
|
lk := er.NewNSLock(bucket, pathJoin(object, uploadID))
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2019-04-23 17:54:28 -04:00
|
|
|
// Validates if upload ID exists.
|
2020-06-12 23:04:01 -04:00
|
|
|
if err := er.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2019-04-23 17:54:28 -04:00
|
|
|
return toObjectErr(err, bucket, object, uploadID)
|
2016-05-28 16:23:08 -04:00
|
|
|
}
|
2018-03-15 16:55:23 -04:00
|
|
|
|
|
|
|
// Cleanup all uploaded parts.
|
2022-01-13 14:07:41 -05:00
|
|
|
er.renameAll(ctx, minioMetaMultipartBucket, er.getUploadIDDir(bucket, object, uploadID))
|
2018-03-15 16:55:23 -04:00
|
|
|
|
|
|
|
// Successfully purged.
|
|
|
|
return nil
|
|
|
|
}
|