You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
276 lines
8.4 KiB
276 lines
8.4 KiB
9 years ago
|
/*
|
||
5 years ago
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
||
9 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
7 years ago
|
"context"
|
||
9 years ago
|
"sort"
|
||
7 years ago
|
|
||
6 years ago
|
"github.com/minio/minio-go/v6/pkg/s3utils"
|
||
7 years ago
|
"github.com/minio/minio/cmd/logger"
|
||
5 years ago
|
"github.com/minio/minio/pkg/sync/errgroup"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
// list all errors that can be ignore in a bucket operation.
|
||
|
var bucketOpIgnoredErrs = append(baseIgnoredErrs, errDiskAccessDenied)
|
||
|
|
||
8 years ago
|
// list all errors that can be ignored in a bucket metadata operation.
|
||
|
var bucketMetadataOpIgnoredErrs = append(bucketOpIgnoredErrs, errVolumeNotFound)
|
||
|
|
||
9 years ago
|
/// Bucket operations
|
||
|
|
||
|
// MakeBucket - make a bucket.
|
||
5 years ago
|
func (er erasureObjects) MakeBucketWithLocation(ctx context.Context, bucket string, opts BucketOptions) error {
|
||
9 years ago
|
// Verify if bucket is valid.
|
||
6 years ago
|
if err := s3utils.CheckValidBucketNameStrict(bucket); err != nil {
|
||
7 years ago
|
return BucketNameInvalid{Bucket: bucket}
|
||
9 years ago
|
}
|
||
|
|
||
5 years ago
|
storageDisks := er.getDisks()
|
||
9 years ago
|
|
||
5 years ago
|
g := errgroup.WithNErrs(len(storageDisks))
|
||
9 years ago
|
|
||
|
// Make a volume entry on all underlying storage disks.
|
||
5 years ago
|
for index := range storageDisks {
|
||
|
index := index
|
||
|
g.Go(func() error {
|
||
|
if storageDisks[index] != nil {
|
||
|
if err := storageDisks[index].MakeVol(bucket); err != nil {
|
||
|
if err != errVolumeExists {
|
||
|
logger.LogIf(ctx, err)
|
||
|
}
|
||
|
return err
|
||
7 years ago
|
}
|
||
5 years ago
|
return nil
|
||
9 years ago
|
}
|
||
5 years ago
|
return errDiskNotFound
|
||
|
}, index)
|
||
9 years ago
|
}
|
||
|
|
||
5 years ago
|
writeQuorum := getWriteQuorum(len(storageDisks))
|
||
5 years ago
|
err := reduceWriteQuorumErrs(ctx, g.Wait(), bucketOpIgnoredErrs, writeQuorum)
|
||
8 years ago
|
return toObjectErr(err, bucket)
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
5 years ago
|
func undoDeleteBucket(storageDisks []StorageAPI, bucket string) {
|
||
|
g := errgroup.WithNErrs(len(storageDisks))
|
||
8 years ago
|
// Undo previous make bucket entry on all underlying storage disks.
|
||
5 years ago
|
for index := range storageDisks {
|
||
|
if storageDisks[index] == nil {
|
||
8 years ago
|
continue
|
||
|
}
|
||
5 years ago
|
index := index
|
||
|
g.Go(func() error {
|
||
|
_ = storageDisks[index].MakeVol(bucket)
|
||
|
return nil
|
||
|
}, index)
|
||
8 years ago
|
}
|
||
|
|
||
|
// Wait for all make vol to finish.
|
||
5 years ago
|
g.Wait()
|
||
8 years ago
|
}
|
||
|
|
||
9 years ago
|
// getBucketInfo - returns the BucketInfo from one of the load balanced disks.
|
||
5 years ago
|
func (er erasureObjects) getBucketInfo(ctx context.Context, bucketName string) (bucketInfo BucketInfo, err error) {
|
||
8 years ago
|
var bucketErrs []error
|
||
5 years ago
|
for _, disk := range er.getLoadBalancedDisks() {
|
||
9 years ago
|
if disk == nil {
|
||
8 years ago
|
bucketErrs = append(bucketErrs, errDiskNotFound)
|
||
9 years ago
|
continue
|
||
|
}
|
||
8 years ago
|
volInfo, serr := disk.StatVol(bucketName)
|
||
|
if serr == nil {
|
||
6 years ago
|
return BucketInfo(volInfo), nil
|
||
9 years ago
|
}
|
||
7 years ago
|
err = serr
|
||
9 years ago
|
// For any reason disk went offline continue and pick the next one.
|
||
7 years ago
|
if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
|
||
8 years ago
|
bucketErrs = append(bucketErrs, err)
|
||
9 years ago
|
continue
|
||
9 years ago
|
}
|
||
8 years ago
|
// Any error which cannot be ignored, we return quickly.
|
||
|
return BucketInfo{}, err
|
||
9 years ago
|
}
|
||
8 years ago
|
// If all our errors were ignored, then we try to
|
||
|
// reduce to one error based on read quorum.
|
||
|
// `nil` is deliberately passed for ignoredErrs
|
||
|
// because these errors were already ignored.
|
||
5 years ago
|
readQuorum := getReadQuorum(len(er.getDisks()))
|
||
7 years ago
|
return BucketInfo{}, reduceReadQuorumErrs(ctx, bucketErrs, nil, readQuorum)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// GetBucketInfo - returns BucketInfo for a bucket.
|
||
5 years ago
|
func (er erasureObjects) GetBucketInfo(ctx context.Context, bucket string) (bi BucketInfo, e error) {
|
||
|
bucketInfo, err := er.getBucketInfo(ctx, bucket)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
return bi, toObjectErr(err, bucket)
|
||
9 years ago
|
}
|
||
9 years ago
|
return bucketInfo, nil
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// listBuckets - returns list of all buckets from a disk picked at random.
|
||
5 years ago
|
func (er erasureObjects) listBuckets(ctx context.Context) (bucketsInfo []BucketInfo, err error) {
|
||
|
for _, disk := range er.getLoadBalancedDisks() {
|
||
9 years ago
|
if disk == nil {
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
var volsInfo []VolInfo
|
||
|
volsInfo, err = disk.ListVols()
|
||
|
if err == nil {
|
||
|
// NOTE: The assumption here is that volumes across all disks in
|
||
|
// readQuorum have consistent view i.e they all have same number
|
||
|
// of buckets. This is essentially not verified since healing
|
||
|
// should take care of this.
|
||
|
var bucketsInfo []BucketInfo
|
||
|
for _, volInfo := range volsInfo {
|
||
6 years ago
|
if isReservedOrInvalidBucket(volInfo.Name, true) {
|
||
8 years ago
|
continue
|
||
|
}
|
||
6 years ago
|
bucketsInfo = append(bucketsInfo, BucketInfo(volInfo))
|
||
9 years ago
|
}
|
||
8 years ago
|
// For buckets info empty, loop once again to check
|
||
8 years ago
|
// if we have, can happen if disks were down.
|
||
8 years ago
|
if len(bucketsInfo) == 0 {
|
||
|
continue
|
||
|
}
|
||
9 years ago
|
return bucketsInfo, nil
|
||
9 years ago
|
}
|
||
7 years ago
|
logger.LogIf(ctx, err)
|
||
9 years ago
|
// Ignore any disks not found.
|
||
7 years ago
|
if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
|
||
9 years ago
|
continue
|
||
|
}
|
||
9 years ago
|
break
|
||
9 years ago
|
}
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// ListBuckets - lists all the buckets, sorted by its name.
|
||
5 years ago
|
func (er erasureObjects) ListBuckets(ctx context.Context) ([]BucketInfo, error) {
|
||
|
bucketInfos, err := er.listBuckets(ctx)
|
||
9 years ago
|
if err != nil {
|
||
|
return nil, toObjectErr(err)
|
||
|
}
|
||
9 years ago
|
// Sort by bucket name before returning.
|
||
9 years ago
|
sort.Sort(byBucketName(bucketInfos))
|
||
|
return bucketInfos, nil
|
||
|
}
|
||
|
|
||
6 years ago
|
// Dangling buckets should be handled appropriately, in this following situation
|
||
|
// we actually have quorum error to be `nil` but we have some disks where
|
||
|
// the bucket delete returned `errVolumeNotEmpty` but this is not correct
|
||
|
// can only happen if there are dangling objects in a bucket. Under such
|
||
|
// a situation we simply attempt a full delete of the bucket including
|
||
|
// the dangling objects. All of this happens under a lock and there
|
||
|
// is no way a user can create buckets and sneak in objects into namespace,
|
||
|
// so it is safer to do.
|
||
|
func deleteDanglingBucket(ctx context.Context, storageDisks []StorageAPI, dErrs []error, bucket string) {
|
||
|
for index, err := range dErrs {
|
||
|
if err == errVolumeNotEmpty {
|
||
|
// Attempt to delete bucket again.
|
||
5 years ago
|
if derr := storageDisks[index].DeleteVol(bucket, false); derr == errVolumeNotEmpty {
|
||
6 years ago
|
_ = cleanupDir(ctx, storageDisks[index], bucket, "")
|
||
|
|
||
5 years ago
|
_ = storageDisks[index].DeleteVol(bucket, false)
|
||
6 years ago
|
|
||
|
// Cleanup all the previously incomplete multiparts.
|
||
|
_ = cleanupDir(ctx, storageDisks[index], minioMetaMultipartBucket, bucket)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
// DeleteBucket - deletes a bucket.
|
||
5 years ago
|
func (er erasureObjects) DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error {
|
||
9 years ago
|
// Collect if all disks report volume not found.
|
||
5 years ago
|
storageDisks := er.getDisks()
|
||
6 years ago
|
|
||
5 years ago
|
g := errgroup.WithNErrs(len(storageDisks))
|
||
|
|
||
|
for index := range storageDisks {
|
||
|
index := index
|
||
|
g.Go(func() error {
|
||
|
if storageDisks[index] != nil {
|
||
5 years ago
|
if err := storageDisks[index].DeleteVol(bucket, forceDelete); err != nil {
|
||
5 years ago
|
return err
|
||
|
}
|
||
|
err := cleanupDir(ctx, storageDisks[index], minioMetaMultipartBucket, bucket)
|
||
|
if err != nil && err != errVolumeNotFound {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
9 years ago
|
}
|
||
5 years ago
|
return errDiskNotFound
|
||
|
}, index)
|
||
9 years ago
|
}
|
||
|
|
||
|
// Wait for all the delete vols to finish.
|
||
5 years ago
|
dErrs := g.Wait()
|
||
7 years ago
|
|
||
5 years ago
|
if forceDelete {
|
||
|
for _, err := range dErrs {
|
||
|
if err != nil {
|
||
|
undoDeleteBucket(storageDisks, bucket)
|
||
|
return toObjectErr(err, bucket)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
5 years ago
|
writeQuorum := getWriteQuorum(len(storageDisks))
|
||
7 years ago
|
err := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum)
|
||
5 years ago
|
if err == errErasureWriteQuorum {
|
||
5 years ago
|
undoDeleteBucket(storageDisks, bucket)
|
||
9 years ago
|
}
|
||
7 years ago
|
if err != nil {
|
||
|
return toObjectErr(err, bucket)
|
||
|
}
|
||
|
|
||
6 years ago
|
// If we reduce quorum to nil, means we have deleted buckets properly
|
||
|
// on some servers in quorum, we should look for volumeNotEmpty errors
|
||
|
// and delete those buckets as well.
|
||
|
deleteDanglingBucket(ctx, storageDisks, dErrs, bucket)
|
||
|
|
||
7 years ago
|
return nil
|
||
|
}
|
||
|
|
||
|
// IsNotificationSupported returns whether bucket notification is applicable for this layer.
|
||
5 years ago
|
func (er erasureObjects) IsNotificationSupported() bool {
|
||
7 years ago
|
return true
|
||
|
}
|
||
|
|
||
6 years ago
|
// IsListenBucketSupported returns whether listen bucket notification is applicable for this layer.
|
||
5 years ago
|
func (er erasureObjects) IsListenBucketSupported() bool {
|
||
6 years ago
|
return true
|
||
|
}
|
||
|
|
||
6 years ago
|
// IsEncryptionSupported returns whether server side encryption is implemented for this layer.
|
||
5 years ago
|
func (er erasureObjects) IsEncryptionSupported() bool {
|
||
7 years ago
|
return true
|
||
9 years ago
|
}
|
||
6 years ago
|
|
||
|
// IsCompressionSupported returns whether compression is applicable for this layer.
|
||
5 years ago
|
func (er erasureObjects) IsCompressionSupported() bool {
|
||
6 years ago
|
return true
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
// IsTaggingSupported indicates whether erasureObjects implements tagging support.
|
||
|
func (er erasureObjects) IsTaggingSupported() bool {
|
||
5 years ago
|
return true
|
||
|
}
|