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-04-29 17:24:10 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-04-29 17:24:10 -04:00
|
|
|
|
2017-09-19 15:40:27 -04:00
|
|
|
import (
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2017-09-19 15:40:27 -04:00
|
|
|
"io"
|
2018-09-20 22:22:09 -04:00
|
|
|
"net/http"
|
2020-07-08 20:36:56 -04:00
|
|
|
"time"
|
2017-09-19 15:40:27 -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/encrypt"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/tags"
|
2021-09-18 16:31:35 -04:00
|
|
|
"github.com/minio/minio/internal/bucket/replication"
|
2021-05-30 00:16:42 -04:00
|
|
|
"github.com/minio/pkg/bucket/policy"
|
2017-09-19 15:40:27 -04:00
|
|
|
)
|
2016-04-29 17:24:10 -04:00
|
|
|
|
2020-07-17 16:01:22 -04:00
|
|
|
// CheckPreconditionFn returns true if precondition check failed.
|
|
|
|
type CheckPreconditionFn func(o ObjectInfo) bool
|
2019-03-06 15:38:41 -05:00
|
|
|
|
2019-11-20 16:18:09 -05:00
|
|
|
// GetObjectInfoFn is the signature of GetObjectInfo function.
|
2020-06-12 23:04:01 -04:00
|
|
|
type GetObjectInfoFn func(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error)
|
2019-11-20 16:18:09 -05:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// ObjectOptions represents object options for ObjectLayer object operations
|
2018-09-10 12:42:43 -04:00
|
|
|
type ObjectOptions struct {
|
2020-11-12 15:12:09 -05:00
|
|
|
ServerSideEncryption encrypt.ServerSide
|
|
|
|
VersionSuspended bool // indicates if the bucket was previously versioned but is currently suspended.
|
|
|
|
Versioned bool // indicates if the bucket is versioned
|
|
|
|
WalkVersions bool // indicates if the we are interested in walking versions
|
|
|
|
VersionID string // Specifies the versionID which needs to be overwritten or read
|
|
|
|
MTime time.Time // Is only set in POST/PUT operations
|
|
|
|
Expires time.Time // Is only used in POST/PUT operations
|
|
|
|
|
2021-09-18 16:31:35 -04:00
|
|
|
DeleteMarker bool // Is only set in DELETE operations for delete marker replication
|
|
|
|
UserDefined map[string]string // only set in case of POST/PUT operations
|
|
|
|
PartNumber int // only useful in case of GetObject/HeadObject
|
|
|
|
CheckPrecondFn CheckPreconditionFn // only set during GetObject/HeadObject/CopyObjectPart preconditional valuation
|
|
|
|
DeleteReplication ReplicationState // Represents internal replication state needed for Delete replication
|
|
|
|
Transition TransitionOptions
|
|
|
|
Expiration ExpirationOptions
|
|
|
|
|
|
|
|
NoLock bool // indicates to lower layers if the caller is expecting to hold locks.
|
|
|
|
ProxyRequest bool // only set for GET/HEAD in active-active replication scenario
|
|
|
|
ProxyHeaderSet bool // only set for GET/HEAD in active-active replication scenario
|
|
|
|
ReplicationRequest bool // true only if replication request
|
|
|
|
ReplicationSourceTaggingTimestamp time.Time // set if MinIOSourceTaggingTimestamp received
|
|
|
|
ReplicationSourceLegalholdTimestamp time.Time // set if MinIOSourceObjectLegalholdTimestamp received
|
|
|
|
ReplicationSourceRetentionTimestamp time.Time // set if MinIOSourceObjectRetentionTimestamp received
|
|
|
|
DeletePrefix bool // set true to enforce a prefix deletion, only application for DeleteObject API,
|
2021-06-15 21:43:14 -04:00
|
|
|
|
2021-04-24 22:07:27 -04:00
|
|
|
// Use the maximum parity (N/2), used when saving server configuration files
|
2021-03-09 13:19:47 -05:00
|
|
|
MaxParity bool
|
2018-09-10 12:42:43 -04:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:06:47 -04:00
|
|
|
// ExpirationOptions represents object options for object expiration at objectLayer.
|
|
|
|
type ExpirationOptions struct {
|
|
|
|
Expire bool
|
|
|
|
}
|
|
|
|
|
2021-04-19 13:30:42 -04:00
|
|
|
// TransitionOptions represents object options for transition ObjectLayer operation
|
|
|
|
type TransitionOptions struct {
|
|
|
|
Status string
|
|
|
|
Tier string
|
|
|
|
ETag string
|
|
|
|
RestoreRequest *RestoreObjectRequest
|
|
|
|
RestoreExpiry time.Time
|
|
|
|
ExpireRestored bool
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// BucketOptions represents bucket options for ObjectLayer bucket operations
|
|
|
|
type BucketOptions struct {
|
|
|
|
Location string
|
|
|
|
LockEnabled bool
|
|
|
|
VersioningEnabled bool
|
|
|
|
}
|
|
|
|
|
2021-10-06 13:24:40 -04:00
|
|
|
// DeleteBucketOptions provides options for DeleteBucket calls.
|
|
|
|
type DeleteBucketOptions struct {
|
|
|
|
Force bool // Force deletion
|
|
|
|
NoRecreate bool // Do not recreate on delete failures
|
|
|
|
}
|
|
|
|
|
2021-09-18 16:31:35 -04:00
|
|
|
// SetReplicaStatus sets replica status and timestamp for delete operations in ObjectOptions
|
|
|
|
func (o *ObjectOptions) SetReplicaStatus(st replication.StatusType) {
|
|
|
|
o.DeleteReplication.ReplicaStatus = st
|
|
|
|
o.DeleteReplication.ReplicaTimeStamp = UTCNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMarkerReplicationStatus - returns replication status of delete marker from DeleteReplication state in ObjectOptions
|
|
|
|
func (o *ObjectOptions) DeleteMarkerReplicationStatus() replication.StatusType {
|
|
|
|
return o.DeleteReplication.CompositeReplicationStatus()
|
|
|
|
}
|
|
|
|
|
|
|
|
// VersionPurgeStatus - returns version purge status from DeleteReplication state in ObjectOptions
|
|
|
|
func (o *ObjectOptions) VersionPurgeStatus() VersionPurgeStatusType {
|
|
|
|
return o.DeleteReplication.CompositeVersionPurgeStatus()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDeleteReplicationState sets the delete replication options.
|
|
|
|
func (o *ObjectOptions) SetDeleteReplicationState(dsc ReplicateDecision, vID string) {
|
|
|
|
o.DeleteReplication = ReplicationState{
|
|
|
|
ReplicateDecisionStr: dsc.String(),
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case o.VersionID == "":
|
|
|
|
o.DeleteReplication.ReplicationStatusInternal = dsc.PendingStatus()
|
|
|
|
o.DeleteReplication.Targets = replicationStatusesMap(o.DeleteReplication.ReplicationStatusInternal)
|
|
|
|
default:
|
|
|
|
o.DeleteReplication.VersionPurgeStatusInternal = dsc.PendingStatus()
|
|
|
|
o.DeleteReplication.PurgeTargets = versionPurgeStatusesMap(o.DeleteReplication.VersionPurgeStatusInternal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutReplicationState gets ReplicationState for PUT operation from ObjectOptions
|
|
|
|
func (o *ObjectOptions) PutReplicationState() (r ReplicationState) {
|
|
|
|
rstatus, ok := o.UserDefined[ReservedMetadataPrefixLower+ReplicationStatus]
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.ReplicationStatusInternal = rstatus
|
|
|
|
r.Targets = replicationStatusesMap(rstatus)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:39:46 -04:00
|
|
|
// LockType represents required locking for ObjectLayer operations
|
|
|
|
type LockType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
noLock LockType = iota
|
|
|
|
readLock
|
|
|
|
writeLock
|
|
|
|
)
|
|
|
|
|
2021-01-18 23:35:38 -05:00
|
|
|
// BackendMetrics - represents bytes served from backend
|
|
|
|
type BackendMetrics struct {
|
|
|
|
bytesReceived uint64
|
|
|
|
bytesSent uint64
|
|
|
|
requestStats RequestStats
|
|
|
|
}
|
|
|
|
|
2016-04-29 17:24:10 -04:00
|
|
|
// ObjectLayer implements primitives for object API layer.
|
|
|
|
type ObjectLayer interface {
|
2019-11-13 15:17:45 -05:00
|
|
|
// Locking operations on object.
|
2020-11-04 11:25:42 -05:00
|
|
|
NewNSLock(bucket string, objects ...string) RWLocker
|
2019-11-13 15:17:45 -05:00
|
|
|
|
2016-05-26 17:13:10 -04:00
|
|
|
// Storage operations.
|
2018-03-14 15:01:47 -04:00
|
|
|
Shutdown(context.Context) error
|
2021-09-18 16:31:35 -04:00
|
|
|
NSScanner(ctx context.Context, bf *bloomFilter, updates chan<- DataUsageInfo, wantCycle uint32) error
|
2020-12-21 12:35:19 -05:00
|
|
|
|
2021-03-04 17:36:23 -05:00
|
|
|
BackendInfo() madmin.BackendInfo
|
2021-03-02 20:28:04 -05:00
|
|
|
StorageInfo(ctx context.Context) (StorageInfo, []error)
|
|
|
|
LocalStorageInfo(ctx context.Context) (StorageInfo, []error)
|
2016-05-26 17:13:10 -04:00
|
|
|
|
2016-04-29 17:24:10 -04:00
|
|
|
// Bucket operations.
|
2020-06-12 23:04:01 -04:00
|
|
|
MakeBucketWithLocation(ctx context.Context, bucket string, opts BucketOptions) error
|
2018-03-14 15:01:47 -04:00
|
|
|
GetBucketInfo(ctx context.Context, bucket string) (bucketInfo BucketInfo, err error)
|
|
|
|
ListBuckets(ctx context.Context) (buckets []BucketInfo, err error)
|
2021-10-06 13:24:40 -04:00
|
|
|
DeleteBucket(ctx context.Context, bucket string, opts DeleteBucketOptions) error
|
2018-03-14 15:01:47 -04:00
|
|
|
ListObjects(ctx context.Context, bucket, prefix, marker, delimiter string, maxKeys int) (result ListObjectsInfo, err error)
|
|
|
|
ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (result ListObjectsV2Info, err error)
|
2020-06-12 23:04:01 -04:00
|
|
|
ListObjectVersions(ctx context.Context, bucket, prefix, marker, versionMarker, delimiter string, maxKeys int) (result ListObjectVersionsInfo, err error)
|
|
|
|
// Walk lists all objects including versions, delete markers.
|
2020-07-11 01:21:04 -04:00
|
|
|
Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error
|
2016-04-29 17:24:10 -04:00
|
|
|
|
|
|
|
// Object operations.
|
2018-09-10 12:42:43 -04:00
|
|
|
|
2018-09-20 22:22:09 -04:00
|
|
|
// GetObjectNInfo returns a GetObjectReader that satisfies the
|
|
|
|
// ReadCloser interface. The Close method unlocks the object
|
|
|
|
// after reading, so it must always be called after usage.
|
|
|
|
//
|
|
|
|
// IMPORTANTLY, when implementations return err != nil, this
|
|
|
|
// function MUST NOT return a non-nil ReadCloser.
|
2018-09-27 06:06:45 -04:00
|
|
|
GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (reader *GetObjectReader, err error)
|
2018-09-10 12:42:43 -04:00
|
|
|
GetObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error)
|
2019-02-09 00:31:06 -05:00
|
|
|
PutObject(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error)
|
2018-09-10 12:42:43 -04:00
|
|
|
CopyObject(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (objInfo ObjectInfo, err error)
|
2020-06-12 23:04:01 -04:00
|
|
|
DeleteObject(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error)
|
|
|
|
DeleteObjects(ctx context.Context, bucket string, objects []ObjectToDelete, opts ObjectOptions) ([]DeletedObject, []error)
|
2021-04-19 13:30:42 -04:00
|
|
|
TransitionObject(ctx context.Context, bucket, object string, opts ObjectOptions) error
|
|
|
|
RestoreTransitionedObject(ctx context.Context, bucket, object string, opts ObjectOptions) error
|
2016-04-29 17:24:10 -04:00
|
|
|
|
|
|
|
// Multipart operations.
|
2018-03-14 15:01:47 -04:00
|
|
|
ListMultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, err error)
|
2019-02-09 00:31:06 -05:00
|
|
|
NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (uploadID string, err error)
|
2018-03-14 15:01:47 -04:00
|
|
|
CopyObjectPart(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, uploadID string, partID int,
|
2018-09-10 12:42:43 -04:00
|
|
|
startOffset int64, length int64, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (info PartInfo, err error)
|
2018-11-14 20:36:41 -05:00
|
|
|
PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, data *PutObjReader, opts ObjectOptions) (info PartInfo, err error)
|
2020-05-28 15:36:20 -04:00
|
|
|
GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (info MultipartInfo, err error)
|
2019-01-05 17:16:43 -05:00
|
|
|
ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker int, maxParts int, opts ObjectOptions) (result ListPartsInfo, err error)
|
2020-09-14 18:57:13 -04:00
|
|
|
AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) error
|
2018-11-14 20:36:41 -05:00
|
|
|
CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart, opts ObjectOptions) (objInfo ObjectInfo, err error)
|
2016-10-14 22:57:40 -04:00
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// Policy operations
|
2018-04-24 18:53:30 -04:00
|
|
|
SetBucketPolicy(context.Context, string, *policy.Policy) error
|
|
|
|
GetBucketPolicy(context.Context, string) (*policy.Policy, error)
|
2018-03-14 15:01:47 -04:00
|
|
|
DeleteBucketPolicy(context.Context, string) error
|
2018-02-09 18:19:30 -05:00
|
|
|
|
|
|
|
// Supported operations check
|
|
|
|
IsNotificationSupported() bool
|
2020-07-20 15:52:49 -04:00
|
|
|
IsListenSupported() bool
|
2018-02-09 18:19:30 -05:00
|
|
|
IsEncryptionSupported() bool
|
2020-06-03 16:18:54 -04:00
|
|
|
IsTaggingSupported() bool
|
2018-09-27 23:36:17 -04:00
|
|
|
IsCompressionSupported() bool
|
2019-07-19 16:20:33 -04:00
|
|
|
|
2021-01-22 15:09:24 -05:00
|
|
|
SetDriveCounts() []int // list of erasure stripe size for each pool in order.
|
|
|
|
|
|
|
|
// Healing operations.
|
|
|
|
HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error)
|
|
|
|
HealBucket(ctx context.Context, bucket string, opts madmin.HealOpts) (madmin.HealResultItem, error)
|
|
|
|
HealObject(ctx context.Context, bucket, object, versionID string, opts madmin.HealOpts) (madmin.HealResultItem, error)
|
|
|
|
HealObjects(ctx context.Context, bucket, prefix string, opts madmin.HealOpts, fn HealObjectFn) error
|
|
|
|
|
2019-12-06 02:16:06 -05:00
|
|
|
// Backend related metrics
|
2021-01-18 23:35:38 -05:00
|
|
|
GetMetrics(ctx context.Context) (*BackendMetrics, error)
|
2019-12-28 11:54:43 -05:00
|
|
|
|
2020-07-20 21:31:22 -04:00
|
|
|
// Returns health of the backend
|
|
|
|
Health(ctx context.Context, opts HealthOptions) HealthResult
|
2021-02-09 04:00:44 -05:00
|
|
|
ReadHealth(ctx context.Context) bool
|
2020-01-20 11:45:59 -05:00
|
|
|
|
2021-04-04 16:32:31 -04:00
|
|
|
// Metadata operations
|
|
|
|
PutObjectMetadata(context.Context, string, string, ObjectOptions) (ObjectInfo, error)
|
|
|
|
|
2020-01-20 11:45:59 -05:00
|
|
|
// ObjectTagging operations
|
2021-02-01 16:52:51 -05:00
|
|
|
PutObjectTags(context.Context, string, string, string, ObjectOptions) (ObjectInfo, error)
|
2020-06-12 23:04:01 -04:00
|
|
|
GetObjectTags(context.Context, string, string, ObjectOptions) (*tags.Tags, error)
|
2021-02-01 16:52:51 -05:00
|
|
|
DeleteObjectTags(context.Context, string, string, ObjectOptions) (ObjectInfo, error)
|
2016-04-29 17:24:10 -04:00
|
|
|
}
|
2021-02-26 12:52:02 -05:00
|
|
|
|
|
|
|
// GetObject - TODO(aead): This function just acts as an adapter for GetObject tests and benchmarks
|
|
|
|
// since the GetObject method of the ObjectLayer interface has been removed. Once, the
|
|
|
|
// tests are adjusted to use GetObjectNInfo this function can be removed.
|
|
|
|
func GetObject(ctx context.Context, api ObjectLayer, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) (err error) {
|
|
|
|
var header http.Header
|
|
|
|
if etag != "" {
|
|
|
|
header.Set("ETag", etag)
|
|
|
|
}
|
|
|
|
Range := &HTTPRangeSpec{Start: startOffset, End: startOffset + length}
|
|
|
|
|
|
|
|
reader, err := api.GetObjectNInfo(ctx, bucket, object, Range, header, readLock, opts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
_, err = io.Copy(writer, reader)
|
|
|
|
return err
|
|
|
|
}
|