2023-08-17 12:37:55 -04:00
|
|
|
// Copyright (c) 2015-2023 MinIO, Inc.
|
2021-04-18 15:41:13 -04:00
|
|
|
//
|
|
|
|
// 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-10-25 13:52:29 -04:00
|
|
|
"encoding/base64"
|
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"
|
2022-09-24 00:17:08 -04:00
|
|
|
"github.com/minio/minio/internal/crypto"
|
2022-08-29 19:57:16 -04:00
|
|
|
"github.com/minio/minio/internal/hash"
|
2021-06-01 17:59:40 -04:00
|
|
|
xhttp "github.com/minio/minio/internal/http"
|
2023-08-14 15:28:13 -04:00
|
|
|
xioutil "github.com/minio/minio/internal/ioutil"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/logger"
|
2023-09-04 15:57:37 -04:00
|
|
|
"github.com/minio/pkg/v2/mimedb"
|
|
|
|
"github.com/minio/pkg/v2/sync/errgroup"
|
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 {
|
2022-10-25 13:52:29 -04:00
|
|
|
uploadUUID := uploadID
|
2022-11-09 19:41:16 -05:00
|
|
|
uploadBytes, err := base64.RawURLEncoding.DecodeString(uploadID)
|
2022-10-25 13:52:29 -04:00
|
|
|
if err == nil {
|
|
|
|
slc := strings.SplitN(string(uploadBytes), ".", 2)
|
|
|
|
if len(slc) == 2 {
|
|
|
|
uploadUUID = slc[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pathJoin(er.getMultipartSHADir(bucket, object), uploadUUID)
|
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.
|
2022-09-15 15:43:49 -04:00
|
|
|
func (er erasureObjects) checkUploadIDExists(ctx context.Context, bucket, object, uploadID string, write bool) (fi FileInfo, metArr []FileInfo, err error) {
|
2021-03-26 14:17:23 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
|
|
|
|
storageDisks := er.getDisks()
|
2020-10-26 13:30:46 -04:00
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2022-09-15 15:43:49 -04:00
|
|
|
partsMetadata, errs := readAllFileInfo(ctx, storageDisks, minioMetaMultipartBucket,
|
|
|
|
uploadIDPath, "", false)
|
2020-10-26 13:30:46 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
readQuorum, writeQuorum, err := objectQuorumFromMeta(ctx, partsMetadata, errs, er.defaultParityCount)
|
2020-10-26 13:30:46 -04:00
|
|
|
if err != nil {
|
2022-09-15 15:43:49 -04:00
|
|
|
return fi, nil, err
|
2020-10-26 13:30:46 -04:00
|
|
|
}
|
|
|
|
|
2023-04-25 13:13:57 -04:00
|
|
|
quorum := readQuorum
|
|
|
|
if write {
|
|
|
|
quorum = writeQuorum
|
|
|
|
}
|
2023-06-17 22:18:20 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
// List all online disks.
|
2023-06-17 22:18:20 -04:00
|
|
|
_, modTime, etag := listOnlineDisks(storageDisks, partsMetadata, errs, quorum)
|
2022-09-15 15:43:49 -04:00
|
|
|
|
|
|
|
if write {
|
|
|
|
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2023-05-25 12:39:06 -04:00
|
|
|
if errors.Is(reducedErr, errErasureWriteQuorum) {
|
2022-09-15 15:43:49 -04:00
|
|
|
return fi, nil, reducedErr
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if reducedErr := reduceReadQuorumErrs(ctx, errs, objectOpIgnoredErrs, readQuorum); reducedErr != nil {
|
|
|
|
return fi, nil, reducedErr
|
|
|
|
}
|
2020-10-26 13:30:46 -04:00
|
|
|
}
|
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
// Pick one from the first valid metadata.
|
2023-06-17 22:18:20 -04:00
|
|
|
fi, err = pickValidFileInfo(ctx, partsMetadata, modTime, etag, quorum)
|
2022-09-15 15:43:49 -04:00
|
|
|
return fi, partsMetadata, 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) 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 {
|
2023-05-30 12:56:50 -04:00
|
|
|
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
|
|
|
}
|
2023-08-14 15:28:13 -04:00
|
|
|
w := xioutil.NewDeadlineWorker(diskMaxTimeout)
|
|
|
|
return w.Run(func() error {
|
|
|
|
wait := deletedCleanupSleeper.Timer(ctx)
|
|
|
|
if now.Sub(fi.ModTime) > expiry {
|
|
|
|
removeAll(pathJoin(diskPath, minioMetaMultipartBucket, uploadIDPath))
|
|
|
|
}
|
|
|
|
wait()
|
|
|
|
return nil
|
|
|
|
})
|
2021-02-26 12:52:27 -05:00
|
|
|
})
|
2023-05-30 12:56:50 -04:00
|
|
|
vi, err := disk.StatVol(ctx, pathJoin(minioMetaMultipartBucket, shaDir))
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-08-14 15:28:13 -04:00
|
|
|
w := xioutil.NewDeadlineWorker(diskMaxTimeout)
|
|
|
|
return w.Run(func() error {
|
|
|
|
wait := deletedCleanupSleeper.Timer(ctx)
|
|
|
|
if now.Sub(vi.Created) > expiry {
|
|
|
|
// We are not deleting shaDir recursively here, if shaDir is empty
|
|
|
|
// and its older then we can happily delete it.
|
|
|
|
Remove(pathJoin(diskPath, minioMetaMultipartBucket, shaDir))
|
|
|
|
}
|
|
|
|
wait()
|
|
|
|
return nil
|
|
|
|
})
|
2021-02-26 12:52:27 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2023-08-14 15:28:13 -04:00
|
|
|
w := xioutil.NewDeadlineWorker(diskMaxTimeout)
|
|
|
|
return w.Run(func() error {
|
|
|
|
wait := deletedCleanupSleeper.Timer(ctx)
|
|
|
|
if now.Sub(vi.Created) > expiry {
|
|
|
|
removeAll(pathJoin(diskPath, minioMetaTmpBucket, tmpDir))
|
|
|
|
}
|
|
|
|
wait()
|
|
|
|
return nil
|
|
|
|
})
|
2021-02-26 12:52:27 -05:00
|
|
|
})
|
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
|
2023-09-15 11:34:03 -04:00
|
|
|
disks := er.getLoadBalancedLocalDisks()
|
|
|
|
if len(disks) == 0 {
|
|
|
|
// using er.getLoadBalancedLocalDisks() has one side-affect where
|
|
|
|
// on a pooled setup all disks are remote, add a fallback
|
2023-10-10 16:47:35 -04:00
|
|
|
disks = er.getDisks()
|
2023-09-15 11:34:03 -04:00
|
|
|
}
|
|
|
|
for _, disk = range disks {
|
2023-10-10 16:47:35 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !disk.IsOnline() {
|
|
|
|
continue
|
|
|
|
}
|
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,
|
2023-10-18 11:06:57 -04:00
|
|
|
UploadID: base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID(), uploadID))),
|
2020-09-28 22:39:32 -04:00
|
|
|
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.
|
2022-08-29 19:57:16 -04:00
|
|
|
func (er erasureObjects) newMultipartUpload(ctx context.Context, bucket string, object string, opts ObjectOptions) (*NewMultipartUploadResult, error) {
|
2022-09-14 21:44:04 -04:00
|
|
|
if opts.CheckPrecondFn != nil {
|
|
|
|
// Lock the object before reading.
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
|
|
|
lkctx, err := lk.GetRLock(ctx, globalOperationTimeout)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
rctx := lkctx.Context()
|
|
|
|
obj, err := er.getObjectInfo(rctx, bucket, object, opts)
|
2022-12-23 22:49:07 -05:00
|
|
|
lk.RUnlock(lkctx)
|
2022-11-26 17:43:32 -05:00
|
|
|
if err != nil && !isErrVersionNotFound(err) {
|
2022-09-14 21:44:04 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if opts.CheckPrecondFn(obj) {
|
|
|
|
return nil, PreConditionFailed{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 07:14:41 -04:00
|
|
|
userDefined := cloneMSS(opts.UserDefined)
|
2022-11-26 17:43:32 -05:00
|
|
|
if opts.PreserveETag != "" {
|
|
|
|
userDefined["etag"] = opts.PreserveETag
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
onlineDisks := er.getDisks()
|
2023-05-23 10:57:57 -04:00
|
|
|
|
|
|
|
// Get parity and data drive count based on storage class metadata
|
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
|
|
|
|
2023-05-23 10:57:57 -04:00
|
|
|
// If we have offline disks upgrade the number of erasure codes for this object.
|
2021-05-27 16:38:04 -04:00
|
|
|
parityOrig := parityDrives
|
2023-05-23 10:57:57 -04:00
|
|
|
|
2023-10-10 16:47:35 -04:00
|
|
|
var offlineDrives int
|
2021-05-27 14:38:09 -04:00
|
|
|
for _, disk := range onlineDisks {
|
|
|
|
if disk == nil {
|
2023-10-10 16:47:35 -04:00
|
|
|
parityDrives++
|
|
|
|
offlineDrives++
|
2021-05-27 14:38:09 -04:00
|
|
|
continue
|
|
|
|
}
|
2023-05-23 10:57:57 -04:00
|
|
|
if !disk.IsOnline() {
|
2023-10-10 16:47:35 -04:00
|
|
|
parityDrives++
|
|
|
|
offlineDrives++
|
2023-05-23 10:57:57 -04:00
|
|
|
continue
|
2021-05-27 14:38:09 -04:00
|
|
|
}
|
2023-05-23 10:57:57 -04:00
|
|
|
}
|
|
|
|
|
2023-10-10 16:47:35 -04:00
|
|
|
if offlineDrives >= (len(onlineDisks)+1)/2 {
|
2023-05-23 10:57:57 -04:00
|
|
|
// if offline drives are more than 50% of the drives
|
|
|
|
// we have no quorum, we shouldn't proceed just
|
|
|
|
// fail at that point.
|
|
|
|
return nil, toObjectErr(errErasureWriteQuorum, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
if parityDrives >= len(onlineDisks)/2 {
|
|
|
|
parityDrives = len(onlineDisks) / 2
|
2021-05-27 14:38:09 -04:00
|
|
|
}
|
2023-10-10 16:47:35 -04:00
|
|
|
|
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
|
|
|
}
|
2023-05-23 10:57:57 -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
|
|
|
|
2022-08-29 19:57:16 -04:00
|
|
|
if opts.WantChecksum != nil && opts.WantChecksum.Type.IsSet() {
|
|
|
|
userDefined[hash.MinIOMultipartChecksum] = opts.WantChecksum.Type.String()
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2022-10-25 13:52:29 -04:00
|
|
|
uploadUUID := mustGetUUID()
|
2023-10-18 11:06:57 -04:00
|
|
|
uploadID := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%s.%s", globalDeploymentID(), uploadUUID)))
|
2022-10-25 13:52:29 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadUUID)
|
2021-04-21 22:06:08 -04:00
|
|
|
|
|
|
|
// Write updated `xl.meta` to all disks.
|
|
|
|
if _, err := writeUniqueFileInfo(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath, partsMetadata, writeQuorum); err != nil {
|
2022-08-29 19:57:16 -04:00
|
|
|
return nil, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
}
|
2022-08-29 19:57:16 -04:00
|
|
|
return &NewMultipartUploadResult{
|
|
|
|
UploadID: uploadID,
|
|
|
|
ChecksumAlgo: userDefined[hash.MinIOMultipartChecksum],
|
|
|
|
}, 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.
|
2022-08-29 19:57:16 -04:00
|
|
|
func (er erasureObjects) NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (*NewMultipartUploadResult, 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
|
|
|
}
|
|
|
|
|
2022-01-13 14:07:41 -05:00
|
|
|
// 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()
|
|
|
|
|
2022-12-12 04:40:29 -05:00
|
|
|
// Do not need to undo partial successful operation since those will be cleaned up
|
|
|
|
// in 24hrs via multipart cleaner, never rename() back to `.minio.sys/tmp` as there
|
|
|
|
// is no way to clean them.
|
|
|
|
|
2022-01-13 14:07:41 -05:00
|
|
|
// We can safely allow RenameFile errors up to len(er.getDisks()) - writeQuorum
|
|
|
|
// otherwise return failure. Cleanup successful renames.
|
2022-12-12 04:40:29 -05:00
|
|
|
return evalDisks(disks, errs), reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2022-01-13 14:07:41 -05:00
|
|
|
}
|
|
|
|
|
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)
|
2023-05-25 12:39:06 -04:00
|
|
|
if errors.Is(err, errErasureWriteQuorum) {
|
2022-07-19 11:35:29 -04:00
|
|
|
// 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
|
|
|
// 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-12-23 22:49:07 -05:00
|
|
|
defer uploadIDRLock.RUnlock(rlkctx)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2022-11-18 06:09:35 -05:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
|
|
|
// Validates if upload ID exists.
|
|
|
|
fi, _, err := er.checkUploadIDExists(rctx, bucket, object, uploadID, true)
|
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object, uploadID)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-18 06:09:35 -05:00
|
|
|
// Write lock for this part ID, only hold it if we are planning to read from the
|
|
|
|
// streamto avoid any concurrent updates.
|
|
|
|
//
|
|
|
|
// Must be held throughout this call.
|
|
|
|
partIDLock := er.NewNSLock(bucket, pathJoin(object, uploadID, strconv.Itoa(partID)))
|
|
|
|
plkctx, err := partIDLock.GetLock(ctx, globalOperationTimeout)
|
2017-12-22 06:28:13 -05:00
|
|
|
if err != nil {
|
2022-11-18 06:09:35 -05:00
|
|
|
return PartInfo{}, err
|
2016-06-27 13:01:09 -04:00
|
|
|
}
|
2022-11-18 06:09:35 -05:00
|
|
|
pctx := plkctx.Context()
|
2022-12-23 22:49:07 -05:00
|
|
|
defer partIDLock.Unlock(plkctx)
|
2016-05-30 14:26:10 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
onlineDisks := er.getDisks()
|
|
|
|
writeQuorum := fi.WriteQuorum(er.defaultWQuorum())
|
2016-07-14 17:59:01 -04:00
|
|
|
|
2022-08-29 19:57:16 -04:00
|
|
|
if cs := fi.Metadata[hash.MinIOMultipartChecksum]; cs != "" {
|
|
|
|
if r.ContentCRCType().String() != cs {
|
|
|
|
return pi, InvalidArgument{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: fi.Name,
|
2023-05-05 22:53:12 -04:00
|
|
|
Err: fmt.Errorf("checksum missing, want %q, got %q", cs, r.ContentCRCType().String()),
|
2022-08-29 19:57:16 -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
|
|
|
defer func() {
|
2023-08-27 12:57:11 -04:00
|
|
|
if countOnlineDisks(onlineDisks) != len(onlineDisks) {
|
2022-11-01 11:00:02 -04:00
|
|
|
er.deleteAll(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 {
|
2023-05-26 13:57:07 -04:00
|
|
|
// Account for padding and forced compression overhead and encryption.
|
|
|
|
buffer = make([]byte, data.ActualSize()+256+32+32, data.ActualSize()*2+512)
|
2021-03-03 19:28:10 -05:00
|
|
|
} 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-09-15 15:43:49 -04:00
|
|
|
partInfo := ObjectPartInfo{
|
2022-07-19 21:56:24 -04:00
|
|
|
Number: partID,
|
|
|
|
ETag: md5hex,
|
|
|
|
Size: n,
|
|
|
|
ActualSize: data.ActualSize(),
|
|
|
|
ModTime: UTCNow(),
|
|
|
|
Index: index,
|
2022-08-29 19:57:16 -04:00
|
|
|
Checksums: r.ContentCRC(),
|
2022-07-19 21:56:24 -04:00
|
|
|
}
|
2023-05-05 22:53:12 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
fi.Parts = []ObjectPartInfo{partInfo}
|
|
|
|
partFI, err := fi.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-09-15 15:43:49 -04:00
|
|
|
onlineDisks, err = writeAllDisks(ctx, onlineDisks, minioMetaMultipartBucket, partPath+".meta", partFI, 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-09-15 15:43:49 -04:00
|
|
|
PartNumber: partInfo.Number,
|
|
|
|
ETag: partInfo.ETag,
|
|
|
|
LastModified: partInfo.ModTime,
|
|
|
|
Size: partInfo.Size,
|
|
|
|
ActualSize: partInfo.ActualSize,
|
|
|
|
ChecksumCRC32: partInfo.Checksums["CRC32"],
|
|
|
|
ChecksumCRC32C: partInfo.Checksums["CRC32C"],
|
|
|
|
ChecksumSHA1: partInfo.Checksums["SHA1"],
|
|
|
|
ChecksumSHA256: partInfo.Checksums["SHA256"],
|
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()
|
2022-12-23 22:49:07 -05:00
|
|
|
defer uploadIDLock.RUnlock(lkctx)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
fi, _, err := er.checkUploadIDExists(ctx, bucket, object, uploadID, false)
|
2020-05-28 15:36:20 -04:00
|
|
|
if err != nil {
|
2022-09-15 15:43:49 -04:00
|
|
|
return result, toObjectErr(err, bucket, object, uploadID)
|
2020-05-28 15:36:20 -04:00
|
|
|
}
|
|
|
|
|
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()
|
2022-12-23 22:49:07 -05:00
|
|
|
defer uploadIDLock.RUnlock(lkctx)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
fi, _, err := er.checkUploadIDExists(ctx, bucket, object, uploadID, false)
|
|
|
|
if 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
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
onlineDisks := er.getDisks()
|
2020-06-12 23:04:01 -04:00
|
|
|
uploadIDPath := er.getUploadIDDir(bucket, object, uploadID)
|
2016-05-31 23:23:31 -04:00
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
writeQuorum := fi.WriteQuorum(er.defaultWQuorum())
|
|
|
|
|
2022-07-19 11:35:29 -04:00
|
|
|
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)
|
2022-08-29 19:57:16 -04:00
|
|
|
result.ChecksumAlgorithm = fi.Metadata[hash.MinIOMultipartChecksum]
|
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 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
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
var pfi FileInfo
|
|
|
|
_, err := pfi.UnmarshalMsg(part.Data)
|
2022-07-19 11:35:29 -04:00
|
|
|
if err != nil {
|
|
|
|
// Maybe crash or similar.
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
partI := pfi.Parts[0]
|
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-08-29 19:57:16 -04:00
|
|
|
fi.AddObjectPart(partI.Number, partI.ETag, partI.Size, partI.ActualSize, partI.ModTime, partI.Index, partI.Checksums)
|
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{
|
2022-08-29 19:57:16 -04:00
|
|
|
PartNumber: part.Number,
|
|
|
|
ETag: part.ETag,
|
|
|
|
LastModified: part.ModTime,
|
|
|
|
ActualSize: part.ActualSize,
|
|
|
|
Size: part.Size,
|
|
|
|
ChecksumCRC32: part.Checksums["CRC32"],
|
|
|
|
ChecksumCRC32C: part.Checksums["CRC32C"],
|
|
|
|
ChecksumSHA1: part.Checksums["SHA1"],
|
|
|
|
ChecksumSHA256: part.Checksums["SHA256"],
|
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
|
|
|
|
}
|
2023-08-17 12:37:55 -04:00
|
|
|
ctx = wlkctx.Context()
|
2022-12-23 22:49:07 -05:00
|
|
|
defer uploadIDLock.Unlock(wlkctx)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2023-08-17 12:37:55 -04:00
|
|
|
fi, partsMetadata, err := er.checkUploadIDExists(ctx, bucket, object, uploadID, true)
|
2022-09-15 15:43:49 -04:00
|
|
|
if 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)
|
2022-09-15 15:43:49 -04:00
|
|
|
onlineDisks := er.getDisks()
|
|
|
|
writeQuorum := fi.WriteQuorum(er.defaultWQuorum())
|
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.
|
|
|
|
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-08-29 19:57:16 -04:00
|
|
|
// Checksum type set when upload started.
|
|
|
|
var checksumType hash.ChecksumType
|
|
|
|
if cs := fi.Metadata[hash.MinIOMultipartChecksum]; cs != "" {
|
|
|
|
checksumType = hash.NewChecksumType(cs)
|
|
|
|
if opts.WantChecksum != nil && !opts.WantChecksum.Type.Is(checksumType) {
|
|
|
|
return oi, InvalidArgument{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: fi.Name,
|
|
|
|
Err: fmt.Errorf("checksum type mismatch"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-24 00:17:08 -04:00
|
|
|
|
2022-08-29 19:57:16 -04:00
|
|
|
var checksumCombined []byte
|
|
|
|
|
2022-09-24 00:17:08 -04:00
|
|
|
// However, in case of encryption, the persisted part ETags don't match
|
|
|
|
// what we have sent to the client during PutObjectPart. The reason is
|
|
|
|
// that ETags are encrypted. Hence, the client will send a list of complete
|
|
|
|
// part ETags of which non can match the ETag of any part. For example
|
|
|
|
// ETag (client): 30902184f4e62dd8f98f0aaff810c626
|
|
|
|
// ETag (server-internal): 20000f00ce5dc16e3f3b124f586ae1d88e9caa1c598415c2759bbb50e84a59f630902184f4e62dd8f98f0aaff810c626
|
|
|
|
//
|
|
|
|
// Therefore, we adjust all ETags sent by the client to match what is stored
|
|
|
|
// on the backend.
|
2022-12-07 13:18:18 -05:00
|
|
|
kind, _ := crypto.IsEncrypted(fi.Metadata)
|
2022-09-24 00:17:08 -04:00
|
|
|
|
|
|
|
var objectEncryptionKey []byte
|
2022-12-07 13:18:18 -05:00
|
|
|
switch kind {
|
|
|
|
case crypto.SSEC:
|
|
|
|
if checksumType.IsSet() {
|
|
|
|
if opts.EncryptFn == nil {
|
|
|
|
return oi, crypto.ErrMissingCustomerKey
|
|
|
|
}
|
|
|
|
baseKey := opts.EncryptFn("", nil)
|
|
|
|
if len(baseKey) != 32 {
|
|
|
|
return oi, crypto.ErrInvalidCustomerKey
|
|
|
|
}
|
|
|
|
objectEncryptionKey, err = decryptObjectMeta(baseKey, bucket, object, fi.Metadata)
|
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case crypto.S3, crypto.S3KMS:
|
2022-09-24 00:17:08 -04:00
|
|
|
objectEncryptionKey, err = decryptObjectMeta(nil, bucket, object, fi.Metadata)
|
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
|
|
|
}
|
2022-12-07 13:18:18 -05:00
|
|
|
if len(objectEncryptionKey) == 32 {
|
|
|
|
var key crypto.ObjectKey
|
|
|
|
copy(key[:], objectEncryptionKey)
|
|
|
|
opts.EncryptFn = metadataEncrypter(key)
|
|
|
|
}
|
2022-09-24 00:17:08 -04:00
|
|
|
|
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
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
var pfi FileInfo
|
|
|
|
_, err := pfi.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
|
|
|
|
2022-09-15 15:43:49 -04:00
|
|
|
partI := pfi.Parts[0]
|
|
|
|
partNumber := partI.Number
|
|
|
|
if partID != partNumber {
|
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", 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-08-29 19:57:16 -04:00
|
|
|
fi.AddObjectPart(partI.Number, partI.ETag, partI.Size, partI.ActualSize, partI.ModTime, partI.Index, partI.Checksums)
|
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
|
|
|
}
|
2022-09-24 00:17:08 -04:00
|
|
|
expPart := currentFI.Parts[partIdx]
|
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)
|
2023-06-05 16:08:51 -04:00
|
|
|
expETag := tryDecryptETag(objectEncryptionKey, expPart.ETag, kind == crypto.S3)
|
2022-09-24 00:17:08 -04:00
|
|
|
if expETag != part.ETag {
|
2018-08-14 21:35:30 -04:00
|
|
|
invp := InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
2022-09-24 00:17:08 -04:00
|
|
|
ExpETag: expETag,
|
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-08-29 19:57:16 -04:00
|
|
|
if checksumType.IsSet() {
|
2022-09-24 00:17:08 -04:00
|
|
|
crc := expPart.Checksums[checksumType.String()]
|
2022-08-29 19:57:16 -04:00
|
|
|
if crc == "" {
|
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wantCS := map[string]string{
|
|
|
|
hash.ChecksumCRC32.String(): part.ChecksumCRC32,
|
|
|
|
hash.ChecksumCRC32C.String(): part.ChecksumCRC32C,
|
|
|
|
hash.ChecksumSHA1.String(): part.ChecksumSHA1,
|
|
|
|
hash.ChecksumSHA256.String(): part.ChecksumSHA256,
|
|
|
|
}
|
|
|
|
if wantCS[checksumType.String()] != crc {
|
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
ExpETag: wantCS[checksumType.String()],
|
|
|
|
GotETag: crc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cs := hash.NewChecksumString(checksumType.String(), crc)
|
|
|
|
if !cs.Valid() {
|
|
|
|
return oi, InvalidPart{
|
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
}
|
|
|
|
}
|
2022-10-15 14:58:47 -04:00
|
|
|
checksumCombined = append(checksumCombined, cs.Raw...)
|
2022-08-29 19:57:16 -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,
|
2022-09-24 00:17:08 -04:00
|
|
|
PartSize: expPart.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.
|
2022-09-24 00:17:08 -04:00
|
|
|
objectSize += expPart.Size
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// Save the consolidated actual size.
|
2022-09-24 00:17:08 -04:00
|
|
|
objectActualSize += expPart.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,
|
2022-09-24 00:17:08 -04:00
|
|
|
Size: expPart.Size,
|
|
|
|
ActualSize: expPart.ActualSize,
|
|
|
|
ModTime: expPart.ModTime,
|
|
|
|
Index: expPart.Index,
|
2022-08-29 19:57:16 -04:00
|
|
|
Checksums: nil, // Not transferred since we do not need it.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.WantChecksum != nil {
|
|
|
|
err := opts.WantChecksum.Matches(checksumCombined)
|
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2023-10-20 22:28:05 -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)
|
|
|
|
|
2022-08-29 19:57:16 -04:00
|
|
|
if checksumType.IsSet() {
|
2023-04-28 11:26:32 -04:00
|
|
|
checksumType |= hash.ChecksumMultipart | hash.ChecksumIncludesMultipart
|
2022-08-29 19:57:16 -04:00
|
|
|
cs := hash.NewChecksumFromData(checksumType, checksumCombined)
|
2023-04-28 11:26:32 -04:00
|
|
|
fi.Checksum = cs.AppendTo(nil, checksumCombined)
|
2022-08-31 11:13:23 -04:00
|
|
|
if opts.EncryptFn != nil {
|
|
|
|
fi.Checksum = opts.EncryptFn("object-checksum", fi.Checksum)
|
|
|
|
}
|
2022-08-29 19:57:16 -04:00
|
|
|
}
|
|
|
|
delete(fi.Metadata, hash.MinIOMultipartChecksum) // Not needed in final object.
|
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.
|
2022-11-26 17:43:32 -05:00
|
|
|
// for replica, newMultipartUpload would have already sent the replication ETag
|
2021-09-09 01:25:23 -04:00
|
|
|
if fi.Metadata["etag"] == "" {
|
2022-11-26 17:43:32 -05:00
|
|
|
if opts.UserDefined["etag"] != "" {
|
|
|
|
fi.Metadata["etag"] = opts.UserDefined["etag"]
|
|
|
|
} else { // fallback if not already calculated in handler.
|
|
|
|
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
|
2022-10-26 21:14:58 -04:00
|
|
|
partsMetadata[index].Checksum = fi.Checksum
|
2023-08-27 12:57:11 -04:00
|
|
|
partsMetadata[index].Versioned = opts.Versioned || opts.VersionSuspended
|
2020-11-20 12:10:48 -05:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -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 {
|
2023-08-27 12:57:11 -04:00
|
|
|
// Remove part.meta which is not needed anymore.
|
|
|
|
er.removePartMeta(bucket, object, uploadID, currentFI.DataDir, curpart.Number)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
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.
|
2023-08-17 12:37:55 -04:00
|
|
|
er.removeObjectPart(bucket, object, uploadID, currentFI.DataDir, curpart.Number)
|
2016-05-28 16:23:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-29 13:28:19 -04:00
|
|
|
defer func() {
|
|
|
|
if err == nil {
|
|
|
|
er.deleteAll(context.Background(), minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
}
|
|
|
|
}()
|
2022-07-19 11:35:29 -04:00
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename the multipart object to final location.
|
2022-12-16 11:52:12 -05:00
|
|
|
onlineDisks, versionsDisparity, err := renameData(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath,
|
|
|
|
partsMetadata, bucket, object, writeQuorum)
|
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2022-08-02 19:57:39 -04:00
|
|
|
|
2022-12-16 11:52:12 -05:00
|
|
|
if !opts.Speedtest && versionsDisparity {
|
2023-06-24 22:31:04 -04:00
|
|
|
globalMRFState.addPartialOp(partialOperation{
|
|
|
|
bucket: bucket,
|
|
|
|
object: object,
|
|
|
|
queued: time.Now(),
|
|
|
|
allVersions: true,
|
|
|
|
setIndex: er.setIndex,
|
|
|
|
poolIndex: er.poolIndex,
|
|
|
|
})
|
2022-12-16 11:52:12 -05: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
|
|
|
}
|
2023-04-19 10:47:42 -04:00
|
|
|
er.addPartial(bucket, object, fi.VersionID)
|
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()
|
2022-12-23 22:49:07 -05:00
|
|
|
defer lk.Unlock(lkctx)
|
2020-09-14 18:57:13 -04:00
|
|
|
|
2019-04-23 17:54:28 -04:00
|
|
|
// Validates if upload ID exists.
|
2022-09-15 15:43:49 -04:00
|
|
|
if _, _, err = er.checkUploadIDExists(ctx, bucket, object, uploadID, false); 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-11-01 11:00:02 -04:00
|
|
|
er.deleteAll(ctx, minioMetaMultipartBucket, er.getUploadIDDir(bucket, object, uploadID))
|
2018-03-15 16:55:23 -04:00
|
|
|
|
|
|
|
// Successfully purged.
|
|
|
|
return nil
|
|
|
|
}
|