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-06-01 19:43:31 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
import (
|
2021-03-29 20:00:55 -04:00
|
|
|
"bytes"
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2021-01-12 01:36:51 -05:00
|
|
|
"errors"
|
2020-03-02 19:29:30 -05:00
|
|
|
"fmt"
|
2016-05-20 23:48:47 -04:00
|
|
|
"io"
|
2018-09-20 22:22:09 -04:00
|
|
|
"net/http"
|
2016-05-20 23:48:47 -04:00
|
|
|
"path"
|
2020-11-12 15:12:09 -05:00
|
|
|
"strings"
|
2020-03-11 11:56:36 -04:00
|
|
|
"sync"
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/tags"
|
2019-10-07 01:50:24 -04:00
|
|
|
xhttp "github.com/minio/minio/cmd/http"
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2020-11-12 15:12:09 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/lifecycle"
|
2020-11-19 21:43:58 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/replication"
|
2021-04-19 13:30:42 -04:00
|
|
|
"github.com/minio/minio/pkg/event"
|
|
|
|
"github.com/minio/minio/pkg/hash"
|
2021-05-11 12:18:37 -04:00
|
|
|
xioutil "github.com/minio/minio/pkg/ioutil"
|
2016-05-20 23:48:47 -04:00
|
|
|
"github.com/minio/minio/pkg/mimedb"
|
2019-10-14 12:44:51 -04:00
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2016-11-20 19:57:12 -05:00
|
|
|
// list all errors which can be ignored in object operations.
|
2020-07-24 16:16:11 -04:00
|
|
|
var objectOpIgnoredErrs = append(baseIgnoredErrs, errDiskAccessDenied, errUnformattedDisk)
|
2016-11-20 19:57:12 -05:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
/// Object Operations
|
|
|
|
|
2021-03-24 17:19:52 -04:00
|
|
|
func countOnlineDisks(onlineDisks []StorageAPI) (online int) {
|
|
|
|
for _, onlineDisk := range onlineDisks {
|
|
|
|
if onlineDisk != nil && onlineDisk.IsOnline() {
|
|
|
|
online++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return online
|
|
|
|
}
|
|
|
|
|
2016-12-26 19:29:26 -05:00
|
|
|
// CopyObject - copy object source object to destination object.
|
|
|
|
// if source object and destination object are same we only
|
|
|
|
// update metadata.
|
2021-03-03 21:36:43 -05:00
|
|
|
func (er erasureObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (oi ObjectInfo, err error) {
|
2020-08-03 19:21:10 -04:00
|
|
|
// This call shouldn't be used for anything other than metadata updates or adding self referential versions.
|
2020-05-28 17:36:38 -04:00
|
|
|
if !srcInfo.metadataOnly {
|
|
|
|
return oi, NotImplemented{}
|
|
|
|
}
|
2020-10-28 03:09:15 -04:00
|
|
|
|
2021-05-17 11:25:48 -04:00
|
|
|
defer NSUpdated(dstBucket, dstObject)
|
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
if !dstOpts.NoLock {
|
|
|
|
lk := er.NewNSLock(dstBucket, dstObject)
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetLock(ctx, globalOperationTimeout)
|
2021-04-19 13:30:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2020-09-15 23:44:48 -04:00
|
|
|
}
|
2020-05-28 17:36:38 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
2021-04-03 12:03:42 -04:00
|
|
|
metaArr, errs := readAllFileInfo(ctx, storageDisks, srcBucket, srcObject, srcOpts.VersionID, true)
|
2016-12-26 19:29:26 -05:00
|
|
|
|
2020-05-28 17:36:38 -04:00
|
|
|
// get Quorum for this object
|
2021-01-16 15:08:02 -05:00
|
|
|
readQuorum, writeQuorum, err := objectQuorumFromMeta(ctx, metaArr, errs, er.defaultParityCount)
|
2020-05-28 17:36:38 -04:00
|
|
|
if err != nil {
|
|
|
|
return oi, toObjectErr(err, srcBucket, srcObject)
|
|
|
|
}
|
2016-12-26 19:29:26 -05:00
|
|
|
|
2020-05-28 17:36:38 -04:00
|
|
|
// List all online disks.
|
2021-04-21 22:06:08 -04:00
|
|
|
onlineDisks, modTime, dataDir := listOnlineDisks(storageDisks, metaArr, errs)
|
2016-12-26 19:29:26 -05:00
|
|
|
|
2020-05-28 17:36:38 -04:00
|
|
|
// Pick latest valid metadata.
|
2021-04-21 22:06:08 -04:00
|
|
|
fi, err := pickValidFileInfo(ctx, metaArr, modTime, dataDir, readQuorum)
|
2020-05-28 17:36:38 -04:00
|
|
|
if err != nil {
|
|
|
|
return oi, toObjectErr(err, srcBucket, srcObject)
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
if fi.Deleted {
|
|
|
|
if srcOpts.VersionID == "" {
|
|
|
|
return oi, toObjectErr(errFileNotFound, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
return fi.ToObjectInfo(srcBucket, srcObject), toObjectErr(errMethodNotAllowed, srcBucket, srcObject)
|
2020-05-28 17:36:38 -04:00
|
|
|
}
|
2018-03-02 20:24:02 -05:00
|
|
|
|
2020-08-03 19:21:10 -04:00
|
|
|
versionID := srcInfo.VersionID
|
|
|
|
if srcInfo.versionOnly {
|
|
|
|
versionID = dstOpts.VersionID
|
|
|
|
// preserve destination versionId if specified.
|
|
|
|
if versionID == "" {
|
|
|
|
versionID = mustGetUUID()
|
|
|
|
}
|
|
|
|
modTime = UTCNow()
|
|
|
|
}
|
|
|
|
fi.VersionID = versionID // set any new versionID we might have created
|
|
|
|
fi.ModTime = modTime // set modTime for the new versionID
|
2020-11-19 14:50:22 -05:00
|
|
|
if !dstOpts.MTime.IsZero() {
|
|
|
|
modTime = dstOpts.MTime
|
|
|
|
fi.ModTime = dstOpts.MTime
|
|
|
|
}
|
2021-01-29 17:49:18 -05:00
|
|
|
fi.Metadata = srcInfo.UserDefined
|
2020-09-15 23:44:48 -04:00
|
|
|
srcInfo.UserDefined["etag"] = srcInfo.ETag
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Update `xl.meta` content on each disks.
|
|
|
|
for index := range metaArr {
|
2020-11-20 12:10:48 -05:00
|
|
|
if metaArr[index].IsValid() {
|
|
|
|
metaArr[index].ModTime = modTime
|
|
|
|
metaArr[index].VersionID = versionID
|
|
|
|
metaArr[index].Metadata = srcInfo.UserDefined
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2016-12-26 19:29:26 -05:00
|
|
|
|
2021-04-02 01:12:03 -04:00
|
|
|
// Write unique `xl.meta` for each disk.
|
2021-04-20 13:44:39 -04:00
|
|
|
if _, err = writeUniqueFileInfo(ctx, onlineDisks, srcBucket, srcObject, metaArr, writeQuorum); err != nil {
|
2021-04-02 01:12:03 -04:00
|
|
|
return oi, toObjectErr(err, srcBucket, srcObject)
|
2016-12-26 19:29:26 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return fi.ToObjectInfo(srcBucket, srcObject), nil
|
2016-12-26 19:29:26 -05:00
|
|
|
}
|
|
|
|
|
2018-09-20 22:22:09 -04:00
|
|
|
// GetObjectNInfo - returns object info and an object
|
|
|
|
// Read(Closer). When err != nil, the returned reader is always nil.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (gr *GetObjectReader, err error) {
|
2020-09-14 18:57:13 -04:00
|
|
|
var unlockOnDefer bool
|
|
|
|
var nsUnlocker = func() {}
|
|
|
|
defer func() {
|
|
|
|
if unlockOnDefer {
|
|
|
|
nsUnlocker()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Acquire lock
|
|
|
|
if lockType != noLock {
|
2020-11-04 11:25:42 -05:00
|
|
|
lock := er.NewNSLock(bucket, object)
|
2020-09-14 18:57:13 -04:00
|
|
|
switch lockType {
|
|
|
|
case writeLock:
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lock.GetLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
nsUnlocker = func() { lock.Unlock(lkctx.Cancel) }
|
2020-09-14 18:57:13 -04:00
|
|
|
case readLock:
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lock.GetRLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
nsUnlocker = func() { lock.RUnlock(lkctx.Cancel) }
|
2020-09-14 18:57:13 -04:00
|
|
|
}
|
|
|
|
unlockOnDefer = true
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
fi, metaArr, onlineDisks, err := er.getObjectFileInfo(ctx, bucket, object, opts, true)
|
2018-09-20 22:22:09 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2020-07-02 19:17:27 -04:00
|
|
|
objInfo := fi.ToObjectInfo(bucket, object)
|
|
|
|
if objInfo.DeleteMarker {
|
|
|
|
if opts.VersionID == "" {
|
|
|
|
return &GetObjectReader{
|
|
|
|
ObjInfo: objInfo,
|
|
|
|
}, toObjectErr(errFileNotFound, bucket, object)
|
|
|
|
}
|
|
|
|
// Make sure to return object info to provide extra information.
|
|
|
|
return &GetObjectReader{
|
|
|
|
ObjInfo: objInfo,
|
|
|
|
}, toObjectErr(errMethodNotAllowed, bucket, object)
|
|
|
|
}
|
2021-05-04 11:40:42 -04:00
|
|
|
if objInfo.IsRemote() {
|
|
|
|
gr, err := getTransitionedObjectReader(ctx, bucket, object, rs, h, objInfo, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-11-12 15:12:09 -05:00
|
|
|
}
|
2021-05-04 11:40:42 -04:00
|
|
|
unlockOnDefer = false
|
|
|
|
return gr.WithCleanupFuncs(nsUnlocker), nil
|
2020-11-12 15:12:09 -05:00
|
|
|
}
|
2021-04-30 21:37:58 -04:00
|
|
|
|
|
|
|
fn, off, length, err := NewGetObjectReader(rs, objInfo, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
2021-04-30 21:37:58 -04:00
|
|
|
unlockOnDefer = false
|
2021-05-11 12:18:37 -04:00
|
|
|
|
|
|
|
pr, pw := xioutil.WaitPipe()
|
2018-09-20 22:22:09 -04:00
|
|
|
go func() {
|
2021-04-30 21:37:58 -04:00
|
|
|
pw.CloseWithError(er.getObjectWithFileInfo(ctx, bucket, object, off, length, pw, fi, metaArr, onlineDisks))
|
2018-09-20 22:22:09 -04:00
|
|
|
}()
|
2020-04-21 01:01:59 -04:00
|
|
|
|
2018-09-21 14:42:06 -04:00
|
|
|
// Cleanup function to cause the go routine above to exit, in
|
|
|
|
// case of incomplete read.
|
2021-05-11 12:18:37 -04:00
|
|
|
pipeCloser := func() {
|
|
|
|
pr.CloseWithError(nil)
|
|
|
|
}
|
2018-09-20 22:22:09 -04:00
|
|
|
|
2021-04-30 21:37:58 -04:00
|
|
|
return fn(pr, h, opts.CheckPrecondFn, pipeCloser, nsUnlocker)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
func (er erasureObjects) getObjectWithFileInfo(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, fi FileInfo, metaArr []FileInfo, onlineDisks []StorageAPI) error {
|
2020-10-28 03:09:15 -04:00
|
|
|
// Reorder online disks based on erasure distribution order.
|
2016-07-25 01:49:27 -04:00
|
|
|
// Reorder parts metadata based on erasure distribution order.
|
2021-03-15 23:03:13 -04:00
|
|
|
onlineDisks, metaArr = shuffleDisksAndPartsMetadataByIndex(onlineDisks, metaArr, fi)
|
2016-05-25 19:42:31 -04:00
|
|
|
|
2016-12-21 14:29:32 -05:00
|
|
|
// For negative length read everything.
|
|
|
|
if length < 0 {
|
2020-06-12 23:04:01 -04:00
|
|
|
length = fi.Size - startOffset
|
2016-07-08 10:46:49 -04:00
|
|
|
}
|
|
|
|
|
2016-12-21 14:29:32 -05:00
|
|
|
// Reply back invalid range if the input offset and length fall out of range.
|
2020-06-12 23:04:01 -04:00
|
|
|
if startOffset > fi.Size || startOffset+length > fi.Size {
|
|
|
|
logger.LogIf(ctx, InvalidRange{startOffset, length, fi.Size}, logger.Application)
|
|
|
|
return InvalidRange{startOffset, length, fi.Size}
|
2016-07-08 10:46:49 -04:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:35:26 -04:00
|
|
|
// Get start part index and offset.
|
2020-06-12 23:04:01 -04:00
|
|
|
partIndex, partOffset, err := fi.ObjectToPartOffset(ctx, startOffset)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return InvalidRange{startOffset, length, fi.Size}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2017-01-27 13:51:02 -05:00
|
|
|
// Calculate endOffset according to length
|
|
|
|
endOffset := startOffset
|
|
|
|
if length > 0 {
|
|
|
|
endOffset += length - 1
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:35:26 -04:00
|
|
|
// Get last part index to read given length.
|
2020-06-12 23:04:01 -04:00
|
|
|
lastPartIndex, _, err := fi.ObjectToPartOffset(ctx, endOffset)
|
2016-06-19 16:35:26 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return InvalidRange{startOffset, length, fi.Size}
|
2016-06-19 16:35:26 -04:00
|
|
|
}
|
|
|
|
|
2017-02-24 12:20:40 -05:00
|
|
|
var totalBytesRead int64
|
2020-06-12 23:04:01 -04:00
|
|
|
erasure, err := NewErasure(ctx, fi.Erasure.DataBlocks, fi.Erasure.ParityBlocks, fi.Erasure.BlockSize)
|
2017-08-14 21:08:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
2021-05-25 19:33:06 -04:00
|
|
|
|
|
|
|
// This hack is needed to avoid a bug found when overwriting
|
|
|
|
// the inline data object with a un-inlined version, for the
|
|
|
|
// time being we need this as we have released inline-data
|
|
|
|
// version already and this bug is already present in newer
|
|
|
|
// releases.
|
|
|
|
//
|
|
|
|
// This mainly happens with objects < smallFileThreshold when
|
|
|
|
// they are overwritten with un-inlined objects >= smallFileThreshold,
|
|
|
|
// due to a bug in RenameData() the fi.Data is not niled leading to
|
|
|
|
// GetObject thinking that fi.Data is valid while fi.Size has
|
|
|
|
// changed already.
|
|
|
|
if _, ok := fi.Metadata[ReservedMetadataPrefixLower+"inline-data"]; ok {
|
|
|
|
shardFileSize := erasure.ShardFileSize(fi.Size)
|
|
|
|
if shardFileSize >= 0 && shardFileSize >= smallFileThreshold {
|
|
|
|
for i := range metaArr {
|
|
|
|
metaArr[i].Data = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Prefer local disks when fetching data blocks (#9563)
If the requested server is part of the set this will always read
from the local disk, even if the disk contains a parity shard.
In default setup there is a 50% chance that at least
one shard that otherwise would have been fetched remotely
will be read locally instead.
It basically trades RPC call overhead for reed-solomon.
On distributed localhost this seems to be fairly break-even,
with a very small gain in throughput and latency.
However on networked servers this should be a bigger
1MB objects, before:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 76257:
* Avg: 25ms 50%: 24ms 90%: 32ms 99%: 42ms Fastest: 7ms Slowest: 67ms
* First Byte: Average: 23ms, Median: 22ms, Best: 5ms, Worst: 65ms
Throughput:
* Average: 1213.68 MiB/s, 1272.63 obj/s (59.948s, starting 14:45:44 CEST)
```
After:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 78845:
* Avg: 24ms 50%: 24ms 90%: 31ms 99%: 39ms Fastest: 8ms Slowest: 62ms
* First Byte: Average: 22ms, Median: 21ms, Best: 6ms, Worst: 57ms
Throughput:
* Average: 1255.11 MiB/s, 1316.08 obj/s (59.938s, starting 14:43:58 CEST)
```
Bonus fix: Only ask for heal once on an object.
2020-05-26 19:47:23 -04:00
|
|
|
var healOnce sync.Once
|
2020-11-12 15:12:09 -05:00
|
|
|
|
2021-05-14 19:50:47 -04:00
|
|
|
// once we have obtained a common FileInfo i.e latest, we should stick
|
|
|
|
// to single dataDir to read the content to avoid reading from some other
|
|
|
|
// dataDir that has stale FileInfo{} to ensure that we fail appropriately
|
|
|
|
// during reads and expect the same dataDir everywhere.
|
|
|
|
dataDir := fi.DataDir
|
2016-06-19 16:35:26 -04:00
|
|
|
for ; partIndex <= lastPartIndex; partIndex++ {
|
2016-06-21 17:34:11 -04:00
|
|
|
if length == totalBytesRead {
|
|
|
|
break
|
|
|
|
}
|
2020-03-02 19:29:30 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
partNumber := fi.Parts[partIndex].Number
|
2020-03-02 19:29:30 -05:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Save the current part name and size.
|
2020-06-12 23:04:01 -04:00
|
|
|
partSize := fi.Parts[partIndex].Size
|
2016-06-22 12:05:03 -04:00
|
|
|
|
2018-08-06 18:14:08 -04:00
|
|
|
partLength := partSize - partOffset
|
|
|
|
// partLength should be adjusted so that we don't write more data than what was requested.
|
|
|
|
if partLength > (length - totalBytesRead) {
|
|
|
|
partLength = length - totalBytesRead
|
2016-06-19 16:35:26 -04:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
tillOffset := erasure.ShardFileOffset(partOffset, partLength, partSize)
|
2016-07-16 11:35:30 -04:00
|
|
|
// Get the checksums of the current part.
|
2019-01-17 07:58:18 -05:00
|
|
|
readers := make([]io.ReaderAt, len(onlineDisks))
|
Prefer local disks when fetching data blocks (#9563)
If the requested server is part of the set this will always read
from the local disk, even if the disk contains a parity shard.
In default setup there is a 50% chance that at least
one shard that otherwise would have been fetched remotely
will be read locally instead.
It basically trades RPC call overhead for reed-solomon.
On distributed localhost this seems to be fairly break-even,
with a very small gain in throughput and latency.
However on networked servers this should be a bigger
1MB objects, before:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 76257:
* Avg: 25ms 50%: 24ms 90%: 32ms 99%: 42ms Fastest: 7ms Slowest: 67ms
* First Byte: Average: 23ms, Median: 22ms, Best: 5ms, Worst: 65ms
Throughput:
* Average: 1213.68 MiB/s, 1272.63 obj/s (59.948s, starting 14:45:44 CEST)
```
After:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 78845:
* Avg: 24ms 50%: 24ms 90%: 31ms 99%: 39ms Fastest: 8ms Slowest: 62ms
* First Byte: Average: 22ms, Median: 21ms, Best: 6ms, Worst: 57ms
Throughput:
* Average: 1255.11 MiB/s, 1316.08 obj/s (59.938s, starting 14:43:58 CEST)
```
Bonus fix: Only ask for heal once on an object.
2020-05-26 19:47:23 -04:00
|
|
|
prefer := make([]bool, len(onlineDisks))
|
2018-08-06 18:14:08 -04:00
|
|
|
for index, disk := range onlineDisks {
|
2017-08-14 21:08:42 -04:00
|
|
|
if disk == OfflineDisk {
|
2016-07-25 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2020-11-20 12:10:48 -05:00
|
|
|
if !metaArr[index].IsValid() {
|
|
|
|
continue
|
|
|
|
}
|
2020-03-02 19:29:30 -05:00
|
|
|
checksumInfo := metaArr[index].Erasure.GetChecksumInfo(partNumber)
|
2021-05-14 19:50:47 -04:00
|
|
|
partPath := pathJoin(object, dataDir, fmt.Sprintf("part.%d", partNumber))
|
|
|
|
readers[index] = newBitrotReader(disk, metaArr[index].Data, bucket, partPath, tillOffset,
|
2020-03-02 19:29:30 -05:00
|
|
|
checksumInfo.Algorithm, checksumInfo.Hash, erasure.ShardSize())
|
Prefer local disks when fetching data blocks (#9563)
If the requested server is part of the set this will always read
from the local disk, even if the disk contains a parity shard.
In default setup there is a 50% chance that at least
one shard that otherwise would have been fetched remotely
will be read locally instead.
It basically trades RPC call overhead for reed-solomon.
On distributed localhost this seems to be fairly break-even,
with a very small gain in throughput and latency.
However on networked servers this should be a bigger
1MB objects, before:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 76257:
* Avg: 25ms 50%: 24ms 90%: 32ms 99%: 42ms Fastest: 7ms Slowest: 67ms
* First Byte: Average: 23ms, Median: 22ms, Best: 5ms, Worst: 65ms
Throughput:
* Average: 1213.68 MiB/s, 1272.63 obj/s (59.948s, starting 14:45:44 CEST)
```
After:
```
Operation: GET. Concurrency: 32. Hosts: 4.
Requests considered: 78845:
* Avg: 24ms 50%: 24ms 90%: 31ms 99%: 39ms Fastest: 8ms Slowest: 62ms
* First Byte: Average: 22ms, Median: 21ms, Best: 6ms, Worst: 57ms
Throughput:
* Average: 1255.11 MiB/s, 1316.08 obj/s (59.938s, starting 14:43:58 CEST)
```
Bonus fix: Only ask for heal once on an object.
2020-05-26 19:47:23 -04:00
|
|
|
|
|
|
|
// Prefer local disks
|
|
|
|
prefer[index] = disk.Hostname() == ""
|
2016-07-16 11:35:30 -04:00
|
|
|
}
|
2021-01-27 13:21:14 -05:00
|
|
|
|
|
|
|
written, err := erasure.Decode(ctx, writer, readers, partOffset, partLength, partSize, prefer)
|
2020-06-12 23:04:01 -04:00
|
|
|
// Note: we should not be defer'ing the following closeBitrotReaders() call as
|
|
|
|
// we are inside a for loop i.e if we use defer, we would accumulate a lot of open files by the time
|
2019-01-17 07:58:18 -05:00
|
|
|
// we return from this function.
|
|
|
|
closeBitrotReaders(readers)
|
2016-05-31 23:23:31 -04:00
|
|
|
if err != nil {
|
2021-01-27 13:21:14 -05:00
|
|
|
// If we have successfully written all the content that was asked
|
|
|
|
// by the client, but we still see an error - this would mean
|
|
|
|
// that we have some parts or data blocks missing or corrupted
|
|
|
|
// - attempt a heal to successfully heal them for future calls.
|
|
|
|
if written == partLength {
|
|
|
|
var scan madmin.HealScanMode
|
|
|
|
if errors.Is(err, errFileNotFound) {
|
|
|
|
scan = madmin.HealNormalScan
|
2021-05-14 19:50:47 -04:00
|
|
|
logger.Info("Healing required, attempting to heal missing shards for %s", pathJoin(bucket, object, fi.VersionID))
|
2021-01-27 13:21:14 -05:00
|
|
|
} else if errors.Is(err, errFileCorrupt) {
|
|
|
|
scan = madmin.HealDeepScan
|
2021-05-14 19:50:47 -04:00
|
|
|
logger.Info("Healing required, attempting to heal bitrot for %s", pathJoin(bucket, object, fi.VersionID))
|
2021-01-27 13:21:14 -05:00
|
|
|
}
|
2021-05-14 19:50:47 -04:00
|
|
|
if scan == madmin.HealNormalScan || scan == madmin.HealDeepScan {
|
2021-01-27 13:21:14 -05:00
|
|
|
healOnce.Do(func() {
|
2021-02-17 13:18:12 -05:00
|
|
|
if _, healing := er.getOnlineDisksWithHealing(); !healing {
|
|
|
|
go healObject(bucket, object, fi.VersionID, scan)
|
|
|
|
}
|
2021-01-27 13:21:14 -05:00
|
|
|
})
|
|
|
|
}
|
2020-04-01 15:14:00 -04:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
2019-01-17 07:58:18 -05:00
|
|
|
for i, r := range readers {
|
2018-08-06 18:14:08 -04:00
|
|
|
if r == nil {
|
|
|
|
onlineDisks[i] = OfflineDisk
|
|
|
|
}
|
|
|
|
}
|
2016-07-28 05:20:34 -04:00
|
|
|
// Track total bytes read from disk and written to the client.
|
2018-08-06 18:14:08 -04:00
|
|
|
totalBytesRead += partLength
|
2016-06-22 12:05:03 -04:00
|
|
|
// partOffset will be valid only for the first part, hence reset it to 0 for
|
|
|
|
// the remaining parts.
|
2016-05-31 23:23:31 -04:00
|
|
|
partOffset = 0
|
2016-06-01 19:43:31 -04:00
|
|
|
} // End of read all parts loop.
|
2016-05-31 23:23:31 -04:00
|
|
|
// Return success.
|
2016-05-28 18:13:15 -04:00
|
|
|
return nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// GetObjectInfo - reads object metadata and replies back ObjectInfo.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) GetObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (info ObjectInfo, err error) {
|
2021-02-16 05:43:47 -05:00
|
|
|
if !opts.NoLock {
|
|
|
|
// Lock the object before reading.
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetRLock(ctx, globalOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2021-02-16 05:43:47 -05:00
|
|
|
return ObjectInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.RUnlock(lkctx.Cancel)
|
2020-09-14 18:57:13 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 19:17:27 -04:00
|
|
|
return er.getObjectInfo(ctx, bucket, object, opts)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
func (er erasureObjects) getObjectFileInfo(ctx context.Context, bucket, object string, opts ObjectOptions, readData bool) (fi FileInfo, metaArr []FileInfo, onlineDisks []StorageAPI, err error) {
|
2020-06-12 23:04:01 -04:00
|
|
|
disks := er.getDisks()
|
2018-10-19 14:00:09 -04:00
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-01-07 22:27:31 -05:00
|
|
|
metaArr, errs := readAllFileInfo(ctx, disks, bucket, object, opts.VersionID, readData)
|
2018-10-19 14:00:09 -04:00
|
|
|
|
2021-01-16 15:08:02 -05:00
|
|
|
readQuorum, _, err := objectQuorumFromMeta(ctx, metaArr, errs, er.defaultParityCount)
|
2019-02-05 20:58:48 -05:00
|
|
|
if err != nil {
|
2020-11-02 18:15:12 -05:00
|
|
|
return fi, nil, nil, err
|
2018-02-01 13:47:49 -05:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:14:26 -04:00
|
|
|
if reducedErr := reduceReadQuorumErrs(ctx, errs, objectOpIgnoredErrs, readQuorum); reducedErr != nil {
|
2020-11-05 14:48:55 -05:00
|
|
|
if reducedErr == errErasureReadQuorum && bucket != minioMetaBucket {
|
|
|
|
if _, ok := isObjectDangling(metaArr, errs, nil); ok {
|
|
|
|
reducedErr = errFileNotFound
|
|
|
|
if opts.VersionID != "" {
|
|
|
|
reducedErr = errFileVersionNotFound
|
|
|
|
}
|
|
|
|
// Remove the dangling object only when:
|
|
|
|
// - This is a non versioned bucket
|
|
|
|
// - This is a versioned bucket and the version ID is passed, the reason
|
|
|
|
// is that we cannot fetch the ID of the latest version when we don't trust xl.meta
|
|
|
|
if !opts.Versioned || opts.VersionID != "" {
|
|
|
|
er.deleteObjectVersion(ctx, bucket, object, 1, FileInfo{
|
|
|
|
Name: object,
|
|
|
|
VersionID: opts.VersionID,
|
2021-02-03 13:33:43 -05:00
|
|
|
}, false)
|
2020-11-05 14:48:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return fi, nil, nil, toObjectErr(reducedErr, bucket, object)
|
2020-05-27 19:14:26 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2020-05-27 19:14:26 -04:00
|
|
|
// List all online disks.
|
2021-04-21 22:06:08 -04:00
|
|
|
onlineDisks, modTime, dataDir := listOnlineDisks(disks, metaArr, errs)
|
2018-02-01 13:47:49 -05:00
|
|
|
|
|
|
|
// Pick latest valid metadata.
|
2021-04-21 22:06:08 -04:00
|
|
|
fi, err = pickValidFileInfo(ctx, metaArr, modTime, dataDir, readQuorum)
|
2016-05-25 04:33:39 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return fi, nil, nil, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2021-01-27 13:21:14 -05:00
|
|
|
|
2021-04-29 12:54:16 -04:00
|
|
|
// if one of the disk is offline, return right here no need
|
|
|
|
// to attempt a heal on the object.
|
|
|
|
if countErrs(errs, errDiskNotFound) > 0 {
|
|
|
|
return fi, metaArr, onlineDisks, nil
|
|
|
|
}
|
|
|
|
|
2021-01-27 13:21:14 -05:00
|
|
|
var missingBlocks int
|
|
|
|
for i, err := range errs {
|
|
|
|
if err != nil && errors.Is(err, errFileNotFound) {
|
|
|
|
missingBlocks++
|
|
|
|
continue
|
|
|
|
}
|
2021-04-21 22:06:08 -04:00
|
|
|
if metaArr[i].IsValid() && metaArr[i].ModTime.Equal(fi.ModTime) && metaArr[i].DataDir == fi.DataDir {
|
2021-01-27 13:21:14 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
missingBlocks++
|
|
|
|
}
|
|
|
|
|
|
|
|
// if missing metadata can be reconstructed, attempt to reconstruct.
|
|
|
|
if missingBlocks > 0 && missingBlocks < readQuorum {
|
2021-02-17 13:18:12 -05:00
|
|
|
if _, healing := er.getOnlineDisksWithHealing(); !healing {
|
|
|
|
go healObject(bucket, object, fi.VersionID, madmin.HealNormalScan)
|
|
|
|
}
|
2021-01-27 13:21:14 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return fi, metaArr, onlineDisks, nil
|
2020-05-27 19:14:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// getObjectInfo - wrapper for reading object metadata and constructs ObjectInfo.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) getObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2021-01-07 22:27:31 -05:00
|
|
|
fi, _, _, err := er.getObjectFileInfo(ctx, bucket, object, opts, false)
|
2020-05-27 19:14:26 -04:00
|
|
|
if err != nil {
|
2020-07-02 19:17:27 -04:00
|
|
|
return objInfo, toObjectErr(err, bucket, object)
|
2021-01-12 01:36:51 -05:00
|
|
|
|
2020-05-27 19:14:26 -04:00
|
|
|
}
|
2020-11-22 02:48:50 -05:00
|
|
|
objInfo = fi.ToObjectInfo(bucket, object)
|
2021-04-19 13:30:42 -04:00
|
|
|
if !fi.VersionPurgeStatus.Empty() {
|
2020-11-22 02:48:50 -05:00
|
|
|
// Make sure to return object info to provide extra information.
|
|
|
|
return objInfo, toObjectErr(errMethodNotAllowed, bucket, object)
|
|
|
|
}
|
2021-02-10 14:45:02 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if fi.Deleted {
|
2020-11-19 21:43:58 -05:00
|
|
|
if opts.VersionID == "" || opts.DeleteMarker {
|
2020-06-12 23:04:01 -04:00
|
|
|
return objInfo, toObjectErr(errFileNotFound, bucket, object)
|
|
|
|
}
|
|
|
|
// Make sure to return object info to provide extra information.
|
2020-06-17 11:33:14 -04:00
|
|
|
return objInfo, toObjectErr(errMethodNotAllowed, bucket, object)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-11-22 02:48:50 -05:00
|
|
|
|
|
|
|
return objInfo, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-12-26 19:29:26 -05:00
|
|
|
func undoRename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isDir bool, errs []error) {
|
2016-06-17 14:57:51 -04:00
|
|
|
// Undo rename object on disks where RenameFile succeeded.
|
2016-06-20 22:11:55 -04:00
|
|
|
|
|
|
|
// If srcEntry/dstEntry are objects then add a trailing slash to copy
|
|
|
|
// over all the parts inside the object directory
|
2016-12-26 19:29:26 -05:00
|
|
|
if isDir {
|
2016-06-20 22:11:55 -04:00
|
|
|
srcEntry = retainSlash(srcEntry)
|
|
|
|
dstEntry = retainSlash(dstEntry)
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
g := errgroup.WithNErrs(len(disks))
|
2016-07-12 01:53:54 -04:00
|
|
|
for index, disk := range disks {
|
2016-06-17 14:57:51 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if errs[index] == nil {
|
2020-09-04 12:45:06 -04:00
|
|
|
_ = disks[index].RenameFile(context.TODO(), dstBucket, dstEntry, srcBucket, srcEntry)
|
2016-06-17 14:57:51 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
|
|
|
}, index)
|
2016-06-17 14:57:51 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
g.Wait()
|
2016-06-17 14:57:51 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Similar to rename but renames data from srcEntry to dstEntry at dataDir
|
2021-04-20 13:44:39 -04:00
|
|
|
func renameData(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry string, metadata []FileInfo, dstBucket, dstEntry string, writeQuorum int) ([]StorageAPI, error) {
|
2021-05-17 11:25:48 -04:00
|
|
|
defer NSUpdated(dstBucket, dstEntry)
|
2020-10-28 12:18:35 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
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
|
|
|
|
}
|
2021-04-20 13:44:39 -04:00
|
|
|
// Pick one FileInfo for a disk at index.
|
|
|
|
fi := metadata[index]
|
|
|
|
// Assign index when index is initialized
|
|
|
|
if fi.Erasure.Index == 0 {
|
|
|
|
fi.Erasure.Index = index + 1
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-04-20 13:44:39 -04:00
|
|
|
if fi.IsValid() {
|
|
|
|
return disks[index].RenameData(ctx, srcBucket, srcEntry, fi, dstBucket, dstEntry)
|
|
|
|
}
|
|
|
|
return errFileCorrupt
|
2020-06-12 23:04:01 -04:00
|
|
|
}, 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)
|
|
|
|
return evalDisks(disks, errs), err
|
|
|
|
}
|
|
|
|
|
2016-06-20 22:11:55 -04:00
|
|
|
// rename - common function that renamePart and renameObject use to rename
|
|
|
|
// the respective underlying storage layer representations.
|
2018-04-11 20:15:42 -04:00
|
|
|
func rename(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isDir bool, writeQuorum int, ignoredErr []error) ([]StorageAPI, error) {
|
2016-12-26 19:29:26 -05:00
|
|
|
if isDir {
|
2016-06-20 22:11:55 -04:00
|
|
|
dstEntry = retainSlash(dstEntry)
|
|
|
|
srcEntry = retainSlash(srcEntry)
|
|
|
|
}
|
2021-05-17 11:25:48 -04:00
|
|
|
defer NSUpdated(dstBucket, dstEntry)
|
2016-06-20 22:11:55 -04:00
|
|
|
|
2019-10-14 12:44:51 -04:00
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Rename file on all underlying storage disks.
|
2019-10-14 12:44:51 -04:00
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
if err := disks[index].RenameFile(ctx, srcBucket, srcEntry, dstBucket, dstEntry); err != nil {
|
2018-04-11 20:15:42 -04:00
|
|
|
if !IsErrIgnored(err, ignoredErr...) {
|
2019-10-14 12:44:51 -04:00
|
|
|
return err
|
2018-04-11 20:15:42 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2019-10-14 12:44:51 -04:00
|
|
|
return nil
|
|
|
|
}, index)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Wait for all renames to finish.
|
2019-10-14 12:44:51 -04:00
|
|
|
errs := g.Wait()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// We can safely allow RenameFile errors up to len(er.getDisks()) - writeQuorum
|
2016-05-20 23:48:47 -04:00
|
|
|
// otherwise return failure. Cleanup successful renames.
|
2018-04-05 18:04:40 -04:00
|
|
|
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
|
2020-06-12 23:04:01 -04:00
|
|
|
if err == errErasureWriteQuorum {
|
2016-06-17 14:57:51 -04:00
|
|
|
// Undo all the partial rename operations.
|
2016-12-26 19:29:26 -05:00
|
|
|
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isDir, errs)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-06-14 20:14:27 -04:00
|
|
|
return evalDisks(disks, errs), err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// PutObject - creates an object upon reading from the input stream
|
|
|
|
// until EOF, erasure codes the data across all disk and additionally
|
2020-06-12 23:04:01 -04:00
|
|
|
// writes `xl.meta` which carries the necessary metadata for future
|
2016-06-01 19:43:31 -04:00
|
|
|
// object operations.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) PutObject(ctx context.Context, bucket string, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
|
|
|
return er.putObject(ctx, bucket, object, data, opts)
|
2018-01-12 23:34:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// putObject wrapper for erasureObjects PutObject
|
|
|
|
func (er erasureObjects) putObject(ctx context.Context, bucket string, object string, r *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2018-11-14 20:36:41 -05:00
|
|
|
data := r.Reader
|
|
|
|
|
2018-01-29 21:43:13 -05:00
|
|
|
// No metadata is set, allocate a new one.
|
2019-02-09 00:31:06 -05:00
|
|
|
if opts.UserDefined == nil {
|
|
|
|
opts.UserDefined = make(map[string]string)
|
2018-01-29 21:43:13 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
2019-10-07 01:50:24 -04:00
|
|
|
|
2021-03-09 13:19:47 -05:00
|
|
|
parityDrives := len(storageDisks) / 2
|
|
|
|
if !opts.MaxParity {
|
|
|
|
// Get parity and data drive count based on storage class metadata
|
|
|
|
parityDrives = globalStorageClass.GetParityForSC(opts.UserDefined[xhttp.AmzStorageClass])
|
|
|
|
if parityDrives <= 0 {
|
|
|
|
parityDrives = er.defaultParityCount
|
|
|
|
}
|
2019-10-07 01:50:24 -04:00
|
|
|
}
|
|
|
|
dataDrives := len(storageDisks) - parityDrives
|
2018-01-29 21:43:13 -05:00
|
|
|
|
|
|
|
// we now know the number of blocks this object needs for data and parity.
|
|
|
|
// writeQuorum is dataBlocks + 1
|
2020-06-09 22:19:03 -04:00
|
|
|
writeQuorum := dataDrives
|
|
|
|
if dataDrives == parityDrives {
|
2021-01-16 15:08:02 -05:00
|
|
|
writeQuorum++
|
2020-06-09 22:19:03 -04:00
|
|
|
}
|
2018-01-29 21:43:13 -05:00
|
|
|
|
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 {
|
2019-10-11 21:50:54 -04:00
|
|
|
logger.LogIf(ctx, errInvalidArgument, logger.Application)
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(errInvalidArgument)
|
2017-10-06 12:38:01 -04:00
|
|
|
}
|
|
|
|
|
2017-02-21 22:43:44 -05:00
|
|
|
// Check if an object is present as one of the parent dir.
|
|
|
|
// -- FIXME. (needs a new kind of lock).
|
2017-05-09 17:32:24 -04:00
|
|
|
// -- FIXME (this also causes performance issue when disks are down).
|
2021-01-17 04:11:48 -05:00
|
|
|
if opts.ParentIsObject != nil && opts.ParentIsObject(ctx, bucket, path.Dir(object)) {
|
2019-03-20 16:06:53 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(errFileParentIsFile, bucket, object)
|
2017-02-21 22:43:44 -05:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// Initialize parts metadata
|
2020-12-07 13:04:07 -05:00
|
|
|
partsMetadata := make([]FileInfo, len(storageDisks))
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2021-02-25 13:11:31 -05:00
|
|
|
fi := newFileInfo(pathJoin(bucket, object), dataDrives, parityDrives)
|
2021-04-19 13:30:42 -04:00
|
|
|
fi.VersionID = opts.VersionID
|
|
|
|
if opts.Versioned && fi.VersionID == "" {
|
|
|
|
fi.VersionID = mustGetUUID()
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-05-15 22:54:07 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
fi.DataDir = mustGetUUID()
|
2021-05-15 22:54:07 -04:00
|
|
|
uniqueID := mustGetUUID()
|
|
|
|
tempObj := uniqueID
|
2016-07-13 14:56:25 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Initialize erasure metadata.
|
2017-01-30 18:44:42 -05:00
|
|
|
for index := range partsMetadata {
|
2020-06-12 23:04:01 -04:00
|
|
|
partsMetadata[index] = fi
|
2017-01-30 18:44:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Order disks according to erasure distribution
|
2020-10-28 03:09:15 -04:00
|
|
|
var onlineDisks []StorageAPI
|
2021-04-21 22:06:08 -04:00
|
|
|
onlineDisks, partsMetadata = shuffleDisksAndPartsMetadata(storageDisks, partsMetadata, fi)
|
2017-01-30 18:44:42 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
erasure, err := NewErasure(ctx, fi.Erasure.DataBlocks, fi.Erasure.ParityBlocks, fi.Erasure.BlockSize)
|
2017-08-14 21:08:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
|
|
|
}
|
2017-10-06 12:38:01 -04:00
|
|
|
|
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:
|
2018-06-13 14:55:12 -04:00
|
|
|
// No need to allocate fully blockSizeV1 buffer if the incoming data is smaller.
|
2020-06-12 23:04:01 -04:00
|
|
|
buffer = make([]byte, size, 2*size+int64(fi.Erasure.ParityBlocks+fi.Erasure.DataBlocks-1))
|
2018-06-13 14:55:12 -04:00
|
|
|
}
|
2017-10-06 12:38:01 -04: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-05-14 15:33:18 -04:00
|
|
|
partName := "part.1"
|
2020-06-12 23:04:01 -04:00
|
|
|
tempErasureObj := pathJoin(uniqueID, fi.DataDir, partName)
|
2017-01-30 18:44:42 -05:00
|
|
|
|
2021-03-24 17:19:52 -04:00
|
|
|
// Delete temporary object in the event of failure.
|
|
|
|
// If PutObject succeeded there would be no temporary
|
|
|
|
// object to delete.
|
|
|
|
var online int
|
|
|
|
defer func() {
|
|
|
|
if online != len(onlineDisks) {
|
|
|
|
er.deleteObject(context.Background(), minioMetaTmpBucket, tempObj, writeQuorum)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-03-31 12:19:14 -04:00
|
|
|
shardFileSize := erasure.ShardFileSize(data.Size())
|
2019-05-14 15:33:18 -04:00
|
|
|
writers := make([]io.Writer, len(onlineDisks))
|
2021-03-29 20:00:55 -04:00
|
|
|
var inlineBuffers []*bytes.Buffer
|
2021-03-31 12:19:14 -04:00
|
|
|
if shardFileSize >= 0 {
|
|
|
|
if !opts.Versioned && shardFileSize < smallFileThreshold {
|
|
|
|
inlineBuffers = make([]*bytes.Buffer, len(onlineDisks))
|
|
|
|
} else if shardFileSize < smallFileThreshold/8 {
|
|
|
|
inlineBuffers = make([]*bytes.Buffer, len(onlineDisks))
|
|
|
|
}
|
2021-03-29 20:00:55 -04:00
|
|
|
}
|
2019-05-14 15:33:18 -04:00
|
|
|
for i, disk := range onlineDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
2018-09-27 23:36:17 -04:00
|
|
|
}
|
2021-03-29 20:00:55 -04:00
|
|
|
|
|
|
|
if len(inlineBuffers) > 0 {
|
2021-03-31 12:19:14 -04:00
|
|
|
inlineBuffers[i] = bytes.NewBuffer(make([]byte, 0, shardFileSize))
|
2021-03-29 20:00:55 -04:00
|
|
|
writers[i] = newStreamingBitrotWriterBuffer(inlineBuffers[i], DefaultBitrotAlgorithm, erasure.ShardSize())
|
|
|
|
continue
|
|
|
|
}
|
2021-05-17 11:32:28 -04:00
|
|
|
writers[i] = newBitrotWriter(disk, minioMetaTmpBucket, tempErasureObj, shardFileSize, DefaultBitrotAlgorithm, erasure.ShardSize())
|
2019-05-14 15:33:18 -04:00
|
|
|
}
|
2018-09-27 23:36:17 -04:00
|
|
|
|
2020-08-03 15:15:08 -04:00
|
|
|
n, erasureErr := erasure.Encode(ctx, data, writers, buffer, writeQuorum)
|
2019-05-14 15:33:18 -04:00
|
|
|
closeBitrotWriters(writers)
|
|
|
|
if erasureErr != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(erasureErr, minioMetaTmpBucket, tempErasureObj)
|
|
|
|
}
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2019-05-14 15:33:18 -04:00
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
|
|
|
if n < data.Size() {
|
2020-09-08 17:22:04 -04:00
|
|
|
return ObjectInfo{}, IncompleteBody{Bucket: bucket, Object: object}
|
2019-05-14 15:33:18 -04:00
|
|
|
}
|
2017-01-31 18:34:49 -05:00
|
|
|
|
2020-12-24 18:02:02 -05:00
|
|
|
if !opts.NoLock {
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
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-12-24 18:02:02 -05:00
|
|
|
return ObjectInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2020-09-15 23:44:48 -04:00
|
|
|
}
|
|
|
|
|
2019-05-14 15:33:18 -04:00
|
|
|
for i, w := range writers {
|
|
|
|
if w == nil {
|
|
|
|
onlineDisks[i] = nil
|
|
|
|
continue
|
2017-01-30 18:44:42 -05:00
|
|
|
}
|
2021-03-29 20:00:55 -04:00
|
|
|
if len(inlineBuffers) > 0 && inlineBuffers[i] != nil {
|
|
|
|
partsMetadata[i].Data = inlineBuffers[i].Bytes()
|
2021-04-21 22:06:08 -04:00
|
|
|
} else {
|
|
|
|
partsMetadata[i].Data = nil
|
2021-03-29 20:00:55 -04:00
|
|
|
}
|
2020-03-02 19:29:30 -05:00
|
|
|
partsMetadata[i].AddObjectPart(1, "", n, data.ActualSize())
|
|
|
|
partsMetadata[i].Erasure.AddChecksumInfo(ChecksumInfo{
|
|
|
|
PartNumber: 1,
|
|
|
|
Algorithm: DefaultBitrotAlgorithm,
|
|
|
|
Hash: bitrotWriterSum(w),
|
|
|
|
})
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2020-08-12 20:32:24 -04:00
|
|
|
if opts.UserDefined["etag"] == "" {
|
|
|
|
opts.UserDefined["etag"] = r.MD5CurrentHexString()
|
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2016-06-17 00:42:02 -04:00
|
|
|
// Guess content-type from the extension if possible.
|
2019-02-09 00:31:06 -05:00
|
|
|
if opts.UserDefined["content-type"] == "" {
|
|
|
|
opts.UserDefined["content-type"] = mimedb.TypeByExtension(path.Ext(object))
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2020-07-08 20:36:56 -04:00
|
|
|
modTime := opts.MTime
|
|
|
|
if opts.MTime.IsZero() {
|
|
|
|
modTime = UTCNow()
|
|
|
|
}
|
|
|
|
|
2016-05-26 22:55:48 -04:00
|
|
|
// Fill all the necessary metadata.
|
2020-06-12 23:04:01 -04:00
|
|
|
// Update `xl.meta` content on each disks.
|
2016-05-31 23:23:31 -04:00
|
|
|
for index := range partsMetadata {
|
2020-06-12 23:04:01 -04:00
|
|
|
partsMetadata[index].Metadata = opts.UserDefined
|
|
|
|
partsMetadata[index].Size = n
|
|
|
|
partsMetadata[index].ModTime = modTime
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
2021-05-25 19:33:06 -04:00
|
|
|
if len(inlineBuffers) > 0 {
|
|
|
|
// Set an additional header when data is inlined.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index].Metadata[ReservedMetadataPrefixLower+"inline-data"] = "true"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 01:12:03 -04:00
|
|
|
// Rename the successfully written temporary object to final location.
|
2021-04-20 13:44:39 -04:00
|
|
|
if onlineDisks, err = renameData(ctx, onlineDisks, minioMetaTmpBucket, tempObj, partsMetadata, bucket, object, writeQuorum); err != nil {
|
2021-04-02 01:12:03 -04:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
2016-05-29 03:42:09 -04:00
|
|
|
|
2020-01-15 21:30:32 -05:00
|
|
|
// Whether a disk was initially or becomes offline
|
|
|
|
// during this upload, send it to the MRF list.
|
|
|
|
for i := 0; i < len(onlineDisks); i++ {
|
2020-12-22 12:16:43 -05:00
|
|
|
if onlineDisks[i] != nil && onlineDisks[i].IsOnline() {
|
|
|
|
continue
|
2020-01-15 21:30:32 -05:00
|
|
|
}
|
2020-12-22 12:16:43 -05:00
|
|
|
er.addPartial(bucket, object, fi.VersionID)
|
|
|
|
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-03-24 17:19:52 -04:00
|
|
|
online = countOnlineDisks(onlineDisks)
|
2020-06-12 23:04:01 -04:00
|
|
|
|
|
|
|
return fi.ToObjectInfo(bucket, object), nil
|
|
|
|
}
|
|
|
|
|
2021-02-03 13:33:43 -05:00
|
|
|
func (er erasureObjects) deleteObjectVersion(ctx context.Context, bucket, object string, writeQuorum int, fi FileInfo, forceDelMarker bool) error {
|
2020-06-12 23:04:01 -04:00
|
|
|
disks := er.getDisks()
|
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
2021-02-03 13:33:43 -05:00
|
|
|
return disks[index].DeleteVersion(ctx, bucket, object, fi, forceDelMarker)
|
2020-06-12 23:04:01 -04:00
|
|
|
}, index)
|
2016-09-02 15:18:35 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
// return errors if any during deletion
|
|
|
|
return reduceWriteQuorumErrs(ctx, g.Wait(), objectOpIgnoredErrs, writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// deleteObject - wrapper for delete object, deletes an object from
|
2020-06-12 23:04:01 -04:00
|
|
|
// all the disks in parallel, including `xl.meta` associated with the
|
2016-06-01 19:43:31 -04:00
|
|
|
// object.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) deleteObject(ctx context.Context, bucket, object string, writeQuorum int) error {
|
2018-01-29 21:43:13 -05:00
|
|
|
var err error
|
2018-02-20 18:33:26 -05:00
|
|
|
|
2020-12-07 13:04:07 -05:00
|
|
|
disks := er.getDisks()
|
2021-03-24 17:19:52 -04:00
|
|
|
tmpObj := mustGetUUID()
|
2018-08-29 16:36:19 -04:00
|
|
|
if bucket == minioMetaTmpBucket {
|
|
|
|
tmpObj = object
|
|
|
|
} else {
|
2018-10-04 20:22:49 -04:00
|
|
|
// Rename the current object while requiring write quorum, but also consider
|
|
|
|
// that a non found object in a given disk as a success since it already
|
|
|
|
// confirms that the object doesn't have a part in that disk (already removed)
|
2020-12-07 13:04:07 -05:00
|
|
|
disks, err = rename(ctx, disks, bucket, object, minioMetaTmpBucket, tmpObj, true, writeQuorum,
|
2020-06-12 23:04:01 -04:00
|
|
|
[]error{errFileNotFound})
|
2018-03-26 19:39:28 -04:00
|
|
|
if err != nil {
|
2018-08-29 16:36:19 -04:00
|
|
|
return toObjectErr(err, bucket, object)
|
2018-03-26 19:39:28 -04:00
|
|
|
}
|
2017-12-22 06:28:13 -05:00
|
|
|
}
|
|
|
|
|
2019-10-14 12:44:51 -04:00
|
|
|
g := errgroup.WithNErrs(len(disks))
|
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
2021-03-24 12:08:05 -04:00
|
|
|
return disks[index].Delete(ctx, minioMetaTmpBucket, tmpObj, true)
|
2019-10-14 12:44:51 -04:00
|
|
|
}, index)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 19:39:28 -04:00
|
|
|
// return errors if any during deletion
|
2019-10-14 12:44:51 -04:00
|
|
|
return reduceWriteQuorumErrs(ctx, g.Wait(), objectOpIgnoredErrs, writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// DeleteObjects deletes objects/versions in bulk, this function will still automatically split objects list
|
|
|
|
// into smaller bulks if some object names are found to be duplicated in the delete list, splitting
|
|
|
|
// into smaller bulks will avoid holding twice the write lock of the duplicated object names.
|
|
|
|
func (er erasureObjects) DeleteObjects(ctx context.Context, bucket string, objects []ObjectToDelete, opts ObjectOptions) ([]DeletedObject, []error) {
|
|
|
|
errs := make([]error, len(objects))
|
|
|
|
dobjects := make([]DeletedObject, len(objects))
|
|
|
|
writeQuorums := make([]int, len(objects))
|
2020-04-27 13:06:21 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
|
|
|
|
for i := range objects {
|
|
|
|
// Assume (N/2 + 1) quorums for all objects
|
|
|
|
// this is a theoretical assumption such that
|
|
|
|
// for delete's we do not need to honor storage
|
|
|
|
// class for objects which have reduced quorum
|
|
|
|
// storage class only needs to be honored for
|
|
|
|
// Read() requests alone which we already do.
|
|
|
|
writeQuorums[i] = getWriteQuorum(len(storageDisks))
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
versions := make([]FileInfo, len(objects))
|
|
|
|
for i := range objects {
|
|
|
|
if objects[i].VersionID == "" {
|
2020-11-12 15:10:59 -05:00
|
|
|
modTime := opts.MTime
|
|
|
|
if opts.MTime.IsZero() {
|
|
|
|
modTime = UTCNow()
|
|
|
|
}
|
|
|
|
uuid := opts.VersionID
|
|
|
|
if uuid == "" {
|
|
|
|
uuid = mustGetUUID()
|
|
|
|
}
|
|
|
|
if opts.Versioned || opts.VersionSuspended {
|
2020-11-19 21:43:58 -05:00
|
|
|
versions[i] = FileInfo{
|
|
|
|
Name: objects[i].ObjectName,
|
|
|
|
ModTime: modTime,
|
|
|
|
Deleted: true, // delete marker
|
|
|
|
DeleteMarkerReplicationStatus: objects[i].DeleteMarkerReplicationStatus,
|
|
|
|
VersionPurgeStatus: objects[i].VersionPurgeStatus,
|
2020-10-06 15:03:57 -04:00
|
|
|
}
|
|
|
|
if opts.Versioned {
|
2020-11-19 21:43:58 -05:00
|
|
|
versions[i].VersionID = uuid
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-10-06 15:03:57 -04:00
|
|
|
continue
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
versions[i] = FileInfo{
|
2020-11-19 21:43:58 -05:00
|
|
|
Name: objects[i].ObjectName,
|
|
|
|
VersionID: objects[i].VersionID,
|
|
|
|
DeleteMarkerReplicationStatus: objects[i].DeleteMarkerReplicationStatus,
|
|
|
|
VersionPurgeStatus: objects[i].VersionPurgeStatus,
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
}
|
2020-03-06 16:44:24 -05:00
|
|
|
|
2019-05-13 15:25:49 -04:00
|
|
|
// Initialize list of errors.
|
2020-06-12 23:04:01 -04:00
|
|
|
var delObjErrs = make([][]error, len(storageDisks))
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
// Remove versions in bulk for each disk
|
|
|
|
for index, disk := range storageDisks {
|
2020-03-11 11:56:36 -04:00
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
2020-11-29 00:15:45 -05:00
|
|
|
if disk == nil {
|
|
|
|
delObjErrs[index] = make([]error, len(versions))
|
|
|
|
for i := range versions {
|
|
|
|
delObjErrs[index][i] = errDiskNotFound
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-09-04 12:45:06 -04:00
|
|
|
delObjErrs[index] = disk.DeleteVersions(ctx, bucket, versions)
|
2020-06-12 23:04:01 -04:00
|
|
|
}(index, disk)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2020-03-11 11:56:36 -04:00
|
|
|
wg.Wait()
|
|
|
|
|
2019-05-13 15:25:49 -04:00
|
|
|
// Reduce errors for each object
|
|
|
|
for objIndex := range objects {
|
2020-06-12 23:04:01 -04:00
|
|
|
diskErrs := make([]error, len(storageDisks))
|
2020-03-11 11:56:36 -04:00
|
|
|
// Iterate over disks to fetch the error
|
|
|
|
// of deleting of the current object
|
2019-05-13 15:25:49 -04:00
|
|
|
for i := range delObjErrs {
|
2020-03-11 11:56:36 -04:00
|
|
|
// delObjErrs[i] is not nil when disks[i] is also not nil
|
2019-05-13 15:25:49 -04:00
|
|
|
if delObjErrs[i] != nil {
|
2020-09-02 03:19:03 -04:00
|
|
|
diskErrs[i] = delObjErrs[i][objIndex]
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
}
|
2020-11-29 00:15:45 -05:00
|
|
|
err := reduceWriteQuorumErrs(ctx, diskErrs, objectOpIgnoredErrs, writeQuorums[objIndex])
|
|
|
|
if objects[objIndex].VersionID != "" {
|
|
|
|
errs[objIndex] = toObjectErr(err, bucket, objects[objIndex].ObjectName, objects[objIndex].VersionID)
|
|
|
|
} else {
|
|
|
|
errs[objIndex] = toObjectErr(err, bucket, objects[objIndex].ObjectName)
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
if errs[objIndex] == nil {
|
2021-05-17 11:25:48 -04:00
|
|
|
NSUpdated(bucket, objects[objIndex].ObjectName)
|
2020-11-29 00:15:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if versions[objIndex].Deleted {
|
|
|
|
dobjects[objIndex] = DeletedObject{
|
|
|
|
DeleteMarker: versions[objIndex].Deleted,
|
|
|
|
DeleteMarkerVersionID: versions[objIndex].VersionID,
|
|
|
|
DeleteMarkerMTime: DeleteMarkerMTime{versions[objIndex].ModTime},
|
|
|
|
DeleteMarkerReplicationStatus: versions[objIndex].DeleteMarkerReplicationStatus,
|
|
|
|
ObjectName: versions[objIndex].Name,
|
|
|
|
VersionPurgeStatus: versions[objIndex].VersionPurgeStatus,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dobjects[objIndex] = DeletedObject{
|
|
|
|
ObjectName: versions[objIndex].Name,
|
|
|
|
VersionID: versions[objIndex].VersionID,
|
|
|
|
VersionPurgeStatus: versions[objIndex].VersionPurgeStatus,
|
|
|
|
DeleteMarkerReplicationStatus: versions[objIndex].DeleteMarkerReplicationStatus,
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
// Check failed deletes across multiple objects
|
|
|
|
for _, version := range versions {
|
|
|
|
// Check if there is any offline disk and add it to the MRF list
|
|
|
|
for _, disk := range storageDisks {
|
2020-12-22 12:16:43 -05:00
|
|
|
if disk != nil && disk.IsOnline() {
|
|
|
|
// Skip attempted heal on online disks.
|
|
|
|
continue
|
2020-06-29 16:07:26 -04:00
|
|
|
}
|
2020-12-22 12:16:43 -05:00
|
|
|
|
|
|
|
// all other direct versionId references we should
|
|
|
|
// ensure no dangling file is left over.
|
|
|
|
er.addPartial(bucket, version.Name, version.VersionID)
|
|
|
|
break
|
2020-06-29 16:07:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return dobjects, errs
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// DeleteObject - deletes an object, this call doesn't necessary reply
|
|
|
|
// any error as it is not necessary for the handler to reply back a
|
|
|
|
// response to the client request.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) DeleteObject(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) {
|
2020-11-19 21:43:58 -05:00
|
|
|
versionFound := true
|
2020-12-11 19:58:15 -05:00
|
|
|
objInfo = ObjectInfo{VersionID: opts.VersionID} // version id needed in Delete API response.
|
2020-10-08 20:47:21 -04:00
|
|
|
goi, gerr := er.GetObjectInfo(ctx, bucket, object, opts)
|
|
|
|
if gerr != nil && goi.Name == "" {
|
|
|
|
switch gerr.(type) {
|
|
|
|
case InsufficientReadQuorum:
|
|
|
|
return objInfo, InsufficientWriteQuorum{}
|
|
|
|
}
|
2020-11-19 21:43:58 -05:00
|
|
|
// For delete marker replication, versionID being replicated will not exist on disk
|
|
|
|
if opts.DeleteMarker {
|
|
|
|
versionFound = false
|
|
|
|
} else {
|
|
|
|
return objInfo, gerr
|
|
|
|
}
|
2020-10-08 20:47:21 -04:00
|
|
|
}
|
2021-05-17 11:25:48 -04:00
|
|
|
|
|
|
|
defer NSUpdated(bucket, object)
|
|
|
|
|
2020-09-14 18:57:13 -04:00
|
|
|
// Acquire a write lock before deleting the object.
|
2020-11-04 11:25:42 -05:00
|
|
|
lk := er.NewNSLock(bucket, object)
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetLock(ctx, globalDeleteOperationTimeout)
|
2021-03-03 21:36:43 -05:00
|
|
|
if err != nil {
|
2020-09-14 18:57:13 -04:00
|
|
|
return ObjectInfo{}, 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
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
storageDisks := er.getDisks()
|
|
|
|
writeQuorum := len(storageDisks)/2 + 1
|
2020-11-19 21:43:58 -05:00
|
|
|
var markDelete bool
|
|
|
|
// Determine whether to mark object deleted for replication
|
|
|
|
if goi.VersionID != "" {
|
|
|
|
markDelete = true
|
|
|
|
}
|
2021-02-09 18:11:43 -05:00
|
|
|
|
2020-11-19 21:43:58 -05:00
|
|
|
// Default deleteMarker to true if object is under versioning
|
2021-02-09 18:11:43 -05:00
|
|
|
deleteMarker := opts.Versioned
|
|
|
|
|
2020-11-19 21:43:58 -05:00
|
|
|
if opts.VersionID != "" {
|
|
|
|
// case where replica version needs to be deleted on target cluster
|
|
|
|
if versionFound && opts.DeleteMarkerReplicationStatus == replication.Replica.String() {
|
|
|
|
markDelete = false
|
|
|
|
}
|
|
|
|
if opts.VersionPurgeStatus.Empty() && opts.DeleteMarkerReplicationStatus == "" {
|
|
|
|
markDelete = false
|
|
|
|
}
|
2021-02-09 18:11:43 -05:00
|
|
|
if opts.VersionPurgeStatus == Complete {
|
2020-11-19 21:43:58 -05:00
|
|
|
markDelete = false
|
|
|
|
}
|
|
|
|
// determine if the version represents an object delete
|
|
|
|
// deleteMarker = true
|
|
|
|
if versionFound && !goi.DeleteMarker { // implies a versioned delete of object
|
|
|
|
deleteMarker = false
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 16:36:19 -04:00
|
|
|
|
2020-11-19 21:43:58 -05:00
|
|
|
modTime := opts.MTime
|
|
|
|
if opts.MTime.IsZero() {
|
|
|
|
modTime = UTCNow()
|
|
|
|
}
|
2021-04-19 13:30:42 -04:00
|
|
|
|
2020-11-19 21:43:58 -05:00
|
|
|
if markDelete {
|
2020-11-12 15:10:59 -05:00
|
|
|
if opts.Versioned || opts.VersionSuspended {
|
2020-10-06 15:03:57 -04:00
|
|
|
fi := FileInfo{
|
2020-11-19 21:43:58 -05:00
|
|
|
Name: object,
|
|
|
|
Deleted: deleteMarker,
|
|
|
|
MarkDeleted: markDelete,
|
|
|
|
ModTime: modTime,
|
|
|
|
DeleteMarkerReplicationStatus: opts.DeleteMarkerReplicationStatus,
|
|
|
|
VersionPurgeStatus: opts.VersionPurgeStatus,
|
2021-04-19 13:30:42 -04:00
|
|
|
TransitionStatus: opts.Transition.Status,
|
|
|
|
ExpireRestored: opts.Transition.ExpireRestored,
|
2020-10-06 15:03:57 -04:00
|
|
|
}
|
|
|
|
if opts.Versioned {
|
|
|
|
fi.VersionID = mustGetUUID()
|
2020-11-19 21:43:58 -05:00
|
|
|
if opts.VersionID != "" {
|
|
|
|
fi.VersionID = opts.VersionID
|
|
|
|
}
|
2020-10-06 15:03:57 -04:00
|
|
|
}
|
|
|
|
// versioning suspended means we add `null`
|
|
|
|
// version as delete marker
|
|
|
|
// Add delete marker, since we don't have any version specified explicitly.
|
2020-11-19 21:43:58 -05:00
|
|
|
// Or if a particular version id needs to be replicated.
|
2021-02-03 13:33:43 -05:00
|
|
|
if err = er.deleteObjectVersion(ctx, bucket, object, writeQuorum, fi, opts.DeleteMarker); err != nil {
|
2020-10-06 15:03:57 -04:00
|
|
|
return objInfo, toObjectErr(err, bucket, object)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-10-06 15:03:57 -04:00
|
|
|
return fi.ToObjectInfo(bucket, object), nil
|
2018-08-31 16:16:35 -04:00
|
|
|
}
|
2018-08-29 16:36:19 -04:00
|
|
|
}
|
2016-06-17 01:18:43 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Delete the object version on all disks.
|
|
|
|
if err = er.deleteObjectVersion(ctx, bucket, object, writeQuorum, FileInfo{
|
2020-11-19 21:43:58 -05:00
|
|
|
Name: object,
|
|
|
|
VersionID: opts.VersionID,
|
|
|
|
MarkDeleted: markDelete,
|
|
|
|
Deleted: deleteMarker,
|
|
|
|
ModTime: modTime,
|
|
|
|
DeleteMarkerReplicationStatus: opts.DeleteMarkerReplicationStatus,
|
|
|
|
VersionPurgeStatus: opts.VersionPurgeStatus,
|
2021-04-19 13:30:42 -04:00
|
|
|
TransitionStatus: opts.Transition.Status,
|
|
|
|
ExpireRestored: opts.Transition.ExpireRestored,
|
2021-02-03 13:33:43 -05:00
|
|
|
}, opts.DeleteMarker); err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return objInfo, toObjectErr(err, bucket, object)
|
2016-06-07 14:35:03 -04:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
for _, disk := range storageDisks {
|
2020-12-22 12:16:43 -05:00
|
|
|
if disk != nil && disk.IsOnline() {
|
|
|
|
continue
|
2020-06-29 16:07:26 -04:00
|
|
|
}
|
2020-12-22 12:16:43 -05:00
|
|
|
er.addPartial(bucket, object, opts.VersionID)
|
|
|
|
break
|
2020-06-29 16:07:26 -04:00
|
|
|
}
|
|
|
|
|
2020-11-19 21:43:58 -05:00
|
|
|
return ObjectInfo{
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
|
|
|
VersionID: opts.VersionID,
|
|
|
|
VersionPurgeStatus: opts.VersionPurgeStatus,
|
|
|
|
ReplicationStatus: replication.StatusType(opts.DeleteMarkerReplicationStatus),
|
|
|
|
}, nil
|
2018-02-09 18:19:30 -05:00
|
|
|
}
|
2020-01-15 21:30:32 -05:00
|
|
|
|
2020-06-29 16:07:26 -04:00
|
|
|
// Send the successful but partial upload/delete, however ignore
|
2020-01-15 21:30:32 -05:00
|
|
|
// if the channel is blocked by other items.
|
2020-06-29 16:07:26 -04:00
|
|
|
func (er erasureObjects) addPartial(bucket, object, versionID string) {
|
2020-01-15 21:30:32 -05:00
|
|
|
select {
|
2020-06-29 16:07:26 -04:00
|
|
|
case er.mrfOpCh <- partialOperation{bucket: bucket, object: object, versionID: versionID}:
|
2020-01-15 21:30:32 -05:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 11:45:59 -05:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
func (er erasureObjects) PutObjectMetadata(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) {
|
2021-02-01 16:52:51 -05:00
|
|
|
// Lock the object before updating tags.
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
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 {
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2021-02-01 16:52:51 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
disks := er.getDisks()
|
2020-01-20 11:45:59 -05:00
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-04-04 16:32:31 -04:00
|
|
|
metaArr, errs := readAllFileInfo(ctx, disks, bucket, object, opts.VersionID, false)
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
readQuorum, _, err := objectQuorumFromMeta(ctx, metaArr, errs, er.defaultParityCount)
|
2020-06-12 23:04:01 -04:00
|
|
|
if err != nil {
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2020-01-20 11:45:59 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// List all online disks.
|
2021-04-21 22:06:08 -04:00
|
|
|
_, modTime, dataDir := listOnlineDisks(disks, metaArr, errs)
|
2020-06-12 23:04:01 -04:00
|
|
|
|
|
|
|
// Pick latest valid metadata.
|
2021-04-21 22:06:08 -04:00
|
|
|
fi, err := pickValidFileInfo(ctx, metaArr, modTime, dataDir, readQuorum)
|
2020-01-20 11:45:59 -05:00
|
|
|
if err != nil {
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
if fi.Deleted {
|
|
|
|
if opts.VersionID == "" {
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, toObjectErr(errFileNotFound, bucket, object)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, toObjectErr(errMethodNotAllowed, bucket, object)
|
2020-06-12 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
for k, v := range opts.UserDefined {
|
|
|
|
fi.Metadata[k] = v
|
2021-04-02 01:12:03 -04:00
|
|
|
}
|
2021-04-04 16:32:31 -04:00
|
|
|
fi.ModTime = opts.MTime
|
|
|
|
fi.VersionID = opts.VersionID
|
2021-04-02 01:12:03 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
if err = er.updateObjectMeta(ctx, bucket, object, fi); err != nil {
|
2021-02-01 16:52:51 -05:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2021-02-01 16:52:51 -05:00
|
|
|
objInfo := fi.ToObjectInfo(bucket, object)
|
|
|
|
return objInfo, nil
|
2021-04-04 16:32:31 -04:00
|
|
|
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
// PutObjectTags - replace or add tags to an existing object
|
|
|
|
func (er erasureObjects) PutObjectTags(ctx context.Context, bucket, object string, tags string, opts ObjectOptions) (ObjectInfo, error) {
|
|
|
|
// Lock the object before updating tags.
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetLock(ctx, globalOperationTimeout)
|
2021-04-04 16:32:31 -04:00
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, err
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2021-04-04 16:32:31 -04:00
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
disks := er.getDisks()
|
|
|
|
|
|
|
|
// Read metadata associated with the object from all disks.
|
2021-04-04 16:32:31 -04:00
|
|
|
metaArr, errs := readAllFileInfo(ctx, disks, bucket, object, opts.VersionID, false)
|
2020-10-28 12:18:35 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
readQuorum, _, err := objectQuorumFromMeta(ctx, metaArr, errs, er.defaultParityCount)
|
2020-10-28 12:18:35 -04:00
|
|
|
if err != nil {
|
2021-04-04 16:32:31 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// List all online disks.
|
2021-04-21 22:06:08 -04:00
|
|
|
_, modTime, dataDir := listOnlineDisks(disks, metaArr, errs)
|
2020-10-28 12:18:35 -04:00
|
|
|
|
|
|
|
// Pick latest valid metadata.
|
2021-04-21 22:06:08 -04:00
|
|
|
fi, err := pickValidFileInfo(ctx, metaArr, modTime, dataDir, readQuorum)
|
2020-10-28 12:18:35 -04:00
|
|
|
if err != nil {
|
2021-04-04 16:32:31 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
if fi.Deleted {
|
|
|
|
if opts.VersionID == "" {
|
|
|
|
return ObjectInfo{}, toObjectErr(errFileNotFound, bucket, object)
|
|
|
|
}
|
|
|
|
return ObjectInfo{}, toObjectErr(errMethodNotAllowed, bucket, object)
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
fi.Metadata[xhttp.AmzObjectTagging] = tags
|
|
|
|
for k, v := range opts.UserDefined {
|
2020-10-28 12:18:35 -04:00
|
|
|
fi.Metadata[k] = v
|
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
if err = er.updateObjectMeta(ctx, bucket, object, fi); err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
return fi.ToObjectInfo(bucket, object), nil
|
|
|
|
}
|
2020-10-28 12:18:35 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
// updateObjectMeta will update the metadata of a file.
|
|
|
|
func (er erasureObjects) updateObjectMeta(ctx context.Context, bucket, object string, fi FileInfo) error {
|
|
|
|
if len(fi.Metadata) == 0 {
|
|
|
|
return nil
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
disks := er.getDisks()
|
2021-04-02 01:12:03 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
g := errgroup.WithNErrs(len(disks))
|
2021-04-02 01:12:03 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
// Start writing `xl.meta` to all disks in parallel.
|
|
|
|
for index := range disks {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
if disks[index] == nil {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
return disks[index].UpdateMetadata(ctx, bucket, object, fi)
|
|
|
|
}, index)
|
2021-04-02 01:12:03 -04:00
|
|
|
}
|
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
// Wait for all the routines.
|
|
|
|
mErrs := g.Wait()
|
2020-10-28 12:18:35 -04:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
return reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, getWriteQuorum(len(disks)))
|
2020-10-28 12:18:35 -04:00
|
|
|
}
|
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// DeleteObjectTags - delete object tags from an existing object
|
2021-02-01 16:52:51 -05:00
|
|
|
func (er erasureObjects) DeleteObjectTags(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) {
|
2020-06-12 23:04:01 -04:00
|
|
|
return er.PutObjectTags(ctx, bucket, object, "", opts)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// GetObjectTags - get object tags from an existing object
|
2020-06-12 23:04:01 -04:00
|
|
|
func (er erasureObjects) GetObjectTags(ctx context.Context, bucket, object string, opts ObjectOptions) (*tags.Tags, error) {
|
2020-01-20 11:45:59 -05:00
|
|
|
// GetObjectInfo will return tag value as well
|
2020-06-12 23:04:01 -04:00
|
|
|
oi, err := er.GetObjectInfo(ctx, bucket, object, opts)
|
2020-01-20 11:45:59 -05:00
|
|
|
if err != nil {
|
2020-05-05 17:18:13 -04:00
|
|
|
return nil, err
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:18:13 -04:00
|
|
|
return tags.ParseObjectTags(oi.UserTags)
|
2020-01-20 11:45:59 -05:00
|
|
|
}
|
2021-04-19 13:30:42 -04:00
|
|
|
|
|
|
|
// TransitionObject - transition object content to target tier.
|
|
|
|
func (er erasureObjects) TransitionObject(ctx context.Context, bucket, object string, opts ObjectOptions) error {
|
|
|
|
tgtClient, err := globalTierConfigMgr.getDriver(opts.Transition.Tier)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-05-17 11:25:48 -04:00
|
|
|
defer NSUpdated(bucket, object)
|
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
// Acquire write lock before starting to transition the object.
|
|
|
|
lk := er.NewNSLock(bucket, object)
|
2021-04-29 23:55:21 -04:00
|
|
|
lkctx, err := lk.GetLock(ctx, globalDeleteOperationTimeout)
|
2021-04-19 13:30:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-29 23:55:21 -04:00
|
|
|
ctx = lkctx.Context()
|
|
|
|
defer lk.Unlock(lkctx.Cancel)
|
2021-04-19 13:30:42 -04:00
|
|
|
|
|
|
|
fi, metaArr, onlineDisks, err := er.getObjectFileInfo(ctx, bucket, object, opts, true)
|
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
if fi.Deleted {
|
|
|
|
if opts.VersionID == "" {
|
|
|
|
return toObjectErr(errFileNotFound, bucket, object)
|
|
|
|
}
|
|
|
|
// Make sure to return object info to provide extra information.
|
|
|
|
return toObjectErr(errMethodNotAllowed, bucket, object)
|
|
|
|
}
|
|
|
|
// verify that the object queued for transition is identical to that on disk.
|
|
|
|
if !opts.MTime.Equal(fi.ModTime) || !strings.EqualFold(opts.Transition.ETag, extractETag(fi.Metadata)) {
|
|
|
|
return toObjectErr(errFileNotFound, bucket, object)
|
|
|
|
}
|
|
|
|
// if object already transitioned, return
|
|
|
|
if fi.TransitionStatus == lifecycle.TransitionComplete {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if fi.XLV1 {
|
|
|
|
if _, err = er.HealObject(ctx, bucket, object, "", madmin.HealOpts{NoLock: true}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Fetch FileInfo again. HealObject migrates object the latest
|
|
|
|
// format. Among other things this changes fi.DataDir and
|
|
|
|
// possibly fi.Data (if data is inlined).
|
|
|
|
fi, metaArr, onlineDisks, err = er.getObjectFileInfo(ctx, bucket, object, opts, true)
|
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
destObj, err := genTransitionObjName()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-11 12:18:37 -04:00
|
|
|
pr, pw := xioutil.WaitPipe()
|
2021-04-19 13:30:42 -04:00
|
|
|
go func() {
|
|
|
|
err := er.getObjectWithFileInfo(ctx, bucket, object, 0, fi.Size, pw, fi, metaArr, onlineDisks)
|
|
|
|
pw.CloseWithError(err)
|
|
|
|
}()
|
2021-05-11 12:18:37 -04:00
|
|
|
|
|
|
|
err = tgtClient.Put(ctx, destObj, pr, fi.Size)
|
|
|
|
pr.CloseWithError(err)
|
|
|
|
if err != nil {
|
2021-04-19 13:30:42 -04:00
|
|
|
logger.LogIf(ctx, fmt.Errorf("Unable to transition %s/%s(%s) to %s tier: %w", bucket, object, opts.VersionID, opts.Transition.Tier, err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fi.TransitionStatus = lifecycle.TransitionComplete
|
|
|
|
fi.TransitionedObjName = destObj
|
|
|
|
fi.TransitionTier = opts.Transition.Tier
|
|
|
|
eventName := event.ObjectTransitionComplete
|
|
|
|
|
|
|
|
storageDisks := er.getDisks()
|
|
|
|
writeQuorum := len(storageDisks)/2 + 1
|
|
|
|
if err = er.deleteObjectVersion(ctx, bucket, object, writeQuorum, fi, false); err != nil {
|
|
|
|
eventName = event.ObjectTransitionFailed
|
|
|
|
}
|
|
|
|
for _, disk := range storageDisks {
|
|
|
|
if disk != nil && disk.IsOnline() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
er.addPartial(bucket, object, opts.VersionID)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
// Notify object deleted event.
|
|
|
|
sendEvent(eventArgs{
|
|
|
|
EventName: eventName,
|
|
|
|
BucketName: bucket,
|
|
|
|
Object: ObjectInfo{
|
|
|
|
Name: object,
|
|
|
|
VersionID: opts.VersionID,
|
|
|
|
},
|
|
|
|
Host: "Internal: [ILM-Transition]",
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestoreTransitionedObject - restore transitioned object content locally on this cluster.
|
|
|
|
// This is similar to PostObjectRestore from AWS GLACIER
|
|
|
|
// storage class. When PostObjectRestore API is called, a temporary copy of the object
|
|
|
|
// is restored locally to the bucket on source cluster until the restore expiry date.
|
|
|
|
// The copy that was transitioned continues to reside in the transitioned tier.
|
|
|
|
func (er erasureObjects) RestoreTransitionedObject(ctx context.Context, bucket, object string, opts ObjectOptions) error {
|
|
|
|
return er.restoreTransitionedObject(ctx, bucket, object, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update restore status header in the metadata
|
2021-04-23 13:52:26 -04:00
|
|
|
func (er erasureObjects) updateRestoreMetadata(ctx context.Context, bucket, object string, objInfo ObjectInfo, opts ObjectOptions, rerr error) error {
|
2021-04-19 13:30:42 -04:00
|
|
|
oi := objInfo.Clone()
|
|
|
|
oi.metadataOnly = true // Perform only metadata updates.
|
|
|
|
|
|
|
|
if rerr == nil {
|
|
|
|
oi.UserDefined[xhttp.AmzRestore] = completedRestoreObj(opts.Transition.RestoreExpiry).String()
|
|
|
|
} else { // allow retry in the case of failure to restore
|
|
|
|
delete(oi.UserDefined, xhttp.AmzRestore)
|
|
|
|
}
|
|
|
|
if _, err := er.CopyObject(ctx, bucket, object, bucket, object, oi, ObjectOptions{
|
|
|
|
VersionID: oi.VersionID,
|
|
|
|
}, ObjectOptions{
|
|
|
|
VersionID: oi.VersionID,
|
|
|
|
}); err != nil {
|
|
|
|
logger.LogIf(ctx, fmt.Errorf("Unable to update transition restore metadata for %s/%s(%s): %s", bucket, object, oi.VersionID, err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// restoreTransitionedObject for multipart object chunks the file stream from remote tier into the same number of parts
|
|
|
|
// as in the xl.meta for this version and rehydrates the part.n into the fi.DataDir for this version as in the xl.meta
|
|
|
|
func (er erasureObjects) restoreTransitionedObject(ctx context.Context, bucket string, object string, opts ObjectOptions) error {
|
2021-04-23 13:52:26 -04:00
|
|
|
setRestoreHeaderFn := func(oi ObjectInfo, rerr error) error {
|
|
|
|
er.updateRestoreMetadata(ctx, bucket, object, oi, opts, rerr)
|
2021-04-19 13:30:42 -04:00
|
|
|
return rerr
|
|
|
|
}
|
|
|
|
var oi ObjectInfo
|
|
|
|
// get the file info on disk for transitioned object
|
|
|
|
actualfi, _, _, err := er.getObjectFileInfo(ctx, bucket, object, opts, false)
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, toObjectErr(err, bucket, object))
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
oi = actualfi.ToObjectInfo(bucket, object)
|
2021-04-24 22:07:27 -04:00
|
|
|
ropts := putRestoreOpts(bucket, object, opts.Transition.RestoreRequest, oi)
|
2021-04-19 13:30:42 -04:00
|
|
|
if len(oi.Parts) == 1 {
|
|
|
|
var rs *HTTPRangeSpec
|
|
|
|
gr, err := getTransitionedObjectReader(ctx, bucket, object, rs, http.Header{}, oi, opts)
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, toObjectErr(err, bucket, object))
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
defer gr.Close()
|
|
|
|
hashReader, err := hash.NewReader(gr, gr.ObjInfo.Size, "", "", gr.ObjInfo.Size)
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, toObjectErr(err, bucket, object))
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
pReader := NewPutObjReader(hashReader)
|
|
|
|
ropts.UserDefined[xhttp.AmzRestore] = completedRestoreObj(opts.Transition.RestoreExpiry).String()
|
|
|
|
_, err = er.PutObject(ctx, bucket, object, pReader, ropts)
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, toObjectErr(err, bucket, object))
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
2021-04-24 22:07:27 -04:00
|
|
|
|
|
|
|
uploadID, err := er.NewMultipartUpload(ctx, bucket, object, ropts)
|
2021-04-19 13:30:42 -04:00
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, err)
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
2021-04-24 22:07:27 -04:00
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
var uploadedParts []CompletePart
|
|
|
|
var rs *HTTPRangeSpec
|
|
|
|
// get reader from the warm backend - note that even in the case of encrypted objects, this stream is still encrypted.
|
|
|
|
gr, err := getTransitionedObjectReader(ctx, bucket, object, rs, http.Header{}, oi, opts)
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, err)
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
defer gr.Close()
|
2021-04-24 22:07:27 -04:00
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
// rehydrate the parts back on disk as per the original xl.meta prior to transition
|
|
|
|
for _, partInfo := range oi.Parts {
|
|
|
|
hr, err := hash.NewReader(gr, partInfo.Size, "", "", partInfo.Size)
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, err)
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
|
|
|
pInfo, err := er.PutObjectPart(ctx, bucket, object, uploadID, partInfo.Number, NewPutObjReader(hr), ObjectOptions{})
|
|
|
|
if err != nil {
|
2021-04-23 13:52:26 -04:00
|
|
|
return setRestoreHeaderFn(oi, err)
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|
2021-04-26 21:24:06 -04:00
|
|
|
if pInfo.Size != partInfo.Size {
|
|
|
|
return setRestoreHeaderFn(oi, InvalidObjectState{Bucket: bucket, Object: object})
|
|
|
|
}
|
2021-04-19 13:30:42 -04:00
|
|
|
uploadedParts = append(uploadedParts, CompletePart{
|
|
|
|
PartNumber: pInfo.PartNumber,
|
|
|
|
ETag: pInfo.ETag,
|
|
|
|
})
|
|
|
|
}
|
2021-04-24 22:04:35 -04:00
|
|
|
_, err = er.CompleteMultipartUpload(ctx, bucket, object, uploadID, uploadedParts, ObjectOptions{
|
2021-04-26 21:24:06 -04:00
|
|
|
MTime: oi.ModTime})
|
|
|
|
return setRestoreHeaderFn(oi, err)
|
2021-04-19 13:30:42 -04:00
|
|
|
}
|