From b882310e2b4672c267a941c11b3a2a520af7ec18 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 23 Dec 2022 07:46:00 -0800 Subject: [PATCH] avoid locks for internal and invalid buckets in MakeBucket() (#16302) --- cmd/admin-bucket-handlers.go | 6 ++--- cmd/admin-handlers-site-replication.go | 24 +++++------------ cmd/admin-handlers.go | 2 +- cmd/benchmark-utils_test.go | 6 ++--- cmd/bucket-handlers.go | 5 ++-- cmd/bucket-policy-handlers_test.go | 6 ++--- cmd/erasure-bucket.go | 15 +---------- cmd/erasure-healing-common_test.go | 6 ++--- cmd/erasure-healing_test.go | 20 +++++++------- cmd/erasure-object_test.go | 30 ++++++++++----------- cmd/erasure-server-pool-decom.go | 2 +- cmd/erasure-server-pool.go | 34 ++++++++++++++++-------- cmd/erasure-sets.go | 6 ++--- cmd/object-api-deleteobject_test.go | 2 +- cmd/object-api-getobjectinfo_test.go | 2 +- cmd/object-api-interface.go | 3 +-- cmd/object-api-listobjects_test.go | 12 ++++----- cmd/object-api-multipart_test.go | 22 ++++++++-------- cmd/object-api-putobject_test.go | 12 ++++----- cmd/object_api_suite_test.go | 36 +++++++++++++------------- cmd/post-policy_test.go | 4 +-- cmd/site-replication.go | 11 +------- cmd/test-utils_test.go | 2 +- 23 files changed, 122 insertions(+), 146 deletions(-) diff --git a/cmd/admin-bucket-handlers.go b/cmd/admin-bucket-handlers.go index 217795347..ef06ce50b 100644 --- a/cmd/admin-bucket-handlers.go +++ b/cmd/admin-bucket-handlers.go @@ -707,7 +707,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r * opts := MakeBucketOptions{ LockEnabled: config.ObjectLockEnabled == "Enabled", } - err = objectAPI.MakeBucketWithLocation(ctx, bucket, opts) + err = objectAPI.MakeBucket(ctx, bucket, opts) if err != nil { if _, ok := err.(BucketExists); !ok { rpt.SetStatus(bucket, fileName, err) @@ -768,7 +768,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r * continue } if _, ok := bucketMap[bucket]; !ok { - if err = objectAPI.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}); err != nil { + if err = objectAPI.MakeBucket(ctx, bucket, MakeBucketOptions{}); err != nil { if _, ok := err.(BucketExists); !ok { rpt.SetStatus(bucket, fileName, err) continue @@ -820,7 +820,7 @@ func (a adminAPIHandlers) ImportBucketMetadataHandler(w http.ResponseWriter, r * bucket, fileName := slc[0], slc[1] // create bucket if it does not exist yet. if _, ok := bucketMap[bucket]; !ok { - err = objectAPI.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objectAPI.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { if _, ok := err.(BucketExists); !ok { rpt.SetStatus(bucket, "", err) diff --git a/cmd/admin-handlers-site-replication.go b/cmd/admin-handlers-site-replication.go index 1e6cfc076..1864f5ae9 100644 --- a/cmd/admin-handlers-site-replication.go +++ b/cmd/admin-handlers-site-replication.go @@ -114,9 +114,6 @@ func (a adminAPIHandlers) SRPeerBucketOps(w http.ResponseWriter, r *http.Request default: err = errSRInvalidRequest(errInvalidArgument) case madmin.MakeWithVersioningBktOp: - _, isLockEnabled := r.Form["lockEnabled"] - _, isVersioningEnabled := r.Form["versioningEnabled"] - _, isForceCreate := r.Form["forceCreate"] createdAtStr := strings.TrimSpace(r.Form.Get("createdAt")) createdAt, cerr := time.Parse(time.RFC3339Nano, createdAtStr) if cerr != nil { @@ -124,27 +121,18 @@ func (a adminAPIHandlers) SRPeerBucketOps(w http.ResponseWriter, r *http.Request } opts := MakeBucketOptions{ - Location: r.Form.Get("location"), - LockEnabled: isLockEnabled, - VersioningEnabled: isVersioningEnabled, - ForceCreate: isForceCreate, + LockEnabled: r.Form.Get("lockEnabled") == "true", + VersioningEnabled: r.Form.Get("versioningEnabled") == "true", + ForceCreate: r.Form.Get("forceCreate") == "true", CreatedAt: createdAt, } err = globalSiteReplicationSys.PeerBucketMakeWithVersioningHandler(ctx, bucket, opts) case madmin.ConfigureReplBktOp: err = globalSiteReplicationSys.PeerBucketConfigureReplHandler(ctx, bucket) - case madmin.DeleteBucketBktOp: - _, noRecreate := r.Form["noRecreate"] + case madmin.DeleteBucketBktOp, madmin.ForceDeleteBucketBktOp: err = globalSiteReplicationSys.PeerBucketDeleteHandler(ctx, bucket, DeleteBucketOptions{ - Force: false, - NoRecreate: noRecreate, - SRDeleteOp: getSRBucketDeleteOp(true), - }) - case madmin.ForceDeleteBucketBktOp: - _, noRecreate := r.Form["noRecreate"] - err = globalSiteReplicationSys.PeerBucketDeleteHandler(ctx, bucket, DeleteBucketOptions{ - Force: true, - NoRecreate: noRecreate, + Force: operation == madmin.ForceDeleteBucketBktOp, + NoRecreate: r.Form.Get("noRecreate") == "true", SRDeleteOp: getSRBucketDeleteOp(true), }) case madmin.PurgeDeletedBucketOp: diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 69aedeb6a..333ed5c25 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -1319,7 +1319,7 @@ func (a adminAPIHandlers) ObjectSpeedTestHandler(w http.ResponseWriter, r *http. } func makeObjectPerfBucket(ctx context.Context, objectAPI ObjectLayer, bucketName string) (bucketExists bool, err error) { - if err = objectAPI.MakeBucketWithLocation(ctx, bucketName, MakeBucketOptions{}); err != nil { + if err = objectAPI.MakeBucket(ctx, bucketName, MakeBucketOptions{}); err != nil { if _, ok := err.(BucketExists); !ok { // Only BucketExists error can be ignored. return false, err diff --git a/cmd/benchmark-utils_test.go b/cmd/benchmark-utils_test.go index fd5df11b9..08bad89e1 100644 --- a/cmd/benchmark-utils_test.go +++ b/cmd/benchmark-utils_test.go @@ -35,7 +35,7 @@ func runPutObjectBenchmark(b *testing.B, obj ObjectLayer, objSize int) { // obtains random bucket name. bucket := getRandomBucketName() // create bucket. - err = obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { b.Fatal(err) } @@ -76,7 +76,7 @@ func runPutObjectPartBenchmark(b *testing.B, obj ObjectLayer, partSize int) { object := getRandomObjectName() // create bucket. - err = obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { b.Fatal(err) } @@ -196,7 +196,7 @@ func runPutObjectBenchmarkParallel(b *testing.B, obj ObjectLayer, objSize int) { // obtains random bucket name. bucket := getRandomBucketName() // create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { b.Fatal(err) } diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index dde08993f..4454fa0c1 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -773,7 +773,6 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req } opts := MakeBucketOptions{ - Location: location, LockEnabled: objectLockEnabled, ForceCreate: forceCreate, } @@ -785,7 +784,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req // exists elsewhere if err == dns.ErrNoEntriesFound || err == dns.ErrNotImplemented { // Proceed to creating a bucket. - if err = objectAPI.MakeBucketWithLocation(ctx, bucket, opts); err != nil { + if err = objectAPI.MakeBucket(ctx, bucket, opts); err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) return } @@ -837,7 +836,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req } // Proceed to creating a bucket. - if err := objectAPI.MakeBucketWithLocation(ctx, bucket, opts); err != nil { + if err := objectAPI.MakeBucket(ctx, bucket, opts); err != nil { if _, ok := err.(BucketExists); ok { // Though bucket exists locally, we send the site-replication // hook to ensure all sites have this bucket. If the hook diff --git a/cmd/bucket-policy-handlers_test.go b/cmd/bucket-policy-handlers_test.go index 7f48b104e..70f396965 100644 --- a/cmd/bucket-policy-handlers_test.go +++ b/cmd/bucket-policy-handlers_test.go @@ -107,7 +107,7 @@ func getAnonWriteOnlyObjectPolicy(bucketName, prefix string) *policy.Policy { // Wrapper for calling Create Bucket and ensure we get one and only one success. func TestCreateBucket(t *testing.T) { - ExecObjectLayerAPITest(t, testCreateBucket, []string{"MakeBucketWithLocation"}) + ExecObjectLayerAPITest(t, testCreateBucket, []string{"MakeBucket"}) } // testCreateBucket - Test for calling Create Bucket and ensure we get one and only one success. @@ -127,7 +127,7 @@ func testCreateBucket(obj ObjectLayer, instanceType, bucketName string, apiRoute defer wg.Done() // Sync start. <-start - if err := obj.MakeBucketWithLocation(GlobalContext, bucketName1, MakeBucketOptions{}); err != nil { + if err := obj.MakeBucket(GlobalContext, bucketName1, MakeBucketOptions{}); err != nil { if _, ok := err.(BucketExists); !ok { t.Logf("unexpected error: %T: %v", err, err) return @@ -162,7 +162,7 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string credentials auth.Credentials, t *testing.T, ) { bucketName1 := fmt.Sprintf("%s-1", bucketName) - if err := obj.MakeBucketWithLocation(GlobalContext, bucketName1, MakeBucketOptions{}); err != nil { + if err := obj.MakeBucket(GlobalContext, bucketName1, MakeBucketOptions{}); err != nil { t.Fatal(err) } diff --git a/cmd/erasure-bucket.go b/cmd/erasure-bucket.go index f3734f2fb..afe26fb83 100644 --- a/cmd/erasure-bucket.go +++ b/cmd/erasure-bucket.go @@ -21,7 +21,6 @@ import ( "context" "errors" - "github.com/minio/minio-go/v7/pkg/s3utils" "github.com/minio/minio/internal/logger" "github.com/minio/minio/internal/sync/errgroup" ) @@ -35,16 +34,7 @@ var bucketMetadataOpIgnoredErrs = append(bucketOpIgnoredErrs, errVolumeNotFound) // Bucket operations // MakeBucket - make a bucket. -func (er erasureObjects) MakeBucketWithLocation(ctx context.Context, bucket string, opts MakeBucketOptions) error { - defer NSUpdated(bucket, slashSeparator) - - // Verify if bucket is valid. - if !isMinioMetaBucketName(bucket) { - if err := s3utils.CheckValidBucketNameStrict(bucket); err != nil { - return BucketNameInvalid{Bucket: bucket} - } - } - +func (er erasureObjects) MakeBucket(ctx context.Context, bucket string, opts MakeBucketOptions) error { storageDisks := er.getDisks() g := errgroup.WithNErrs(len(storageDisks)) @@ -149,9 +139,6 @@ func (er erasureObjects) GetBucketInfo(ctx context.Context, bucket string, opts // DeleteBucket - deletes a bucket. func (er erasureObjects) DeleteBucket(ctx context.Context, bucket string, opts DeleteBucketOptions) error { - // Collect if all disks report volume not found. - defer NSUpdated(bucket, slashSeparator) - storageDisks := er.getDisks() g := errgroup.WithNErrs(len(storageDisks)) diff --git a/cmd/erasure-healing-common_test.go b/cmd/erasure-healing-common_test.go index b109f05df..5f90dffa9 100644 --- a/cmd/erasure-healing-common_test.go +++ b/cmd/erasure-healing-common_test.go @@ -223,7 +223,7 @@ func TestListOnlineDisks(t *testing.T) { } bucket := "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket %v", err) } @@ -398,7 +398,7 @@ func TestListOnlineDisksSmallObjects(t *testing.T) { } bucket := "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket %v", err) } @@ -519,7 +519,7 @@ func TestDisksWithAllParts(t *testing.T) { z := obj.(*erasureServerPools) s := z.serverPools[0].sets[0] erasureDisks := s.getDisks() - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket %v", err) } diff --git a/cmd/erasure-healing_test.go b/cmd/erasure-healing_test.go index 4f1c3f77c..b843acc7f 100644 --- a/cmd/erasure-healing_test.go +++ b/cmd/erasure-healing_test.go @@ -244,7 +244,7 @@ func TestHealing(t *testing.T) { er := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -398,7 +398,7 @@ func TestHealingVersioned(t *testing.T) { er := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{VersioningEnabled: true}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{VersioningEnabled: true}) if err != nil { t.Fatal(err) } @@ -581,7 +581,7 @@ func TestHealingDanglingObject(t *testing.T) { object := getRandomObjectName() data := bytes.Repeat([]byte("a"), 128*1024) - err = objLayer.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -776,7 +776,7 @@ func TestHealCorrectQuorum(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = objLayer.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -907,7 +907,7 @@ func TestHealObjectCorruptedPools(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = objLayer.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -1084,7 +1084,7 @@ func TestHealObjectCorruptedXLMeta(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = objLayer.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -1227,7 +1227,7 @@ func TestHealObjectCorruptedParts(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = objLayer.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -1384,7 +1384,7 @@ func TestHealObjectErasure(t *testing.T) { data := bytes.Repeat([]byte("a"), 5*1024*1024) var opts ObjectOptions - err = obj.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = obj.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -1481,7 +1481,7 @@ func TestHealEmptyDirectoryErasure(t *testing.T) { object := "empty-dir/" var opts ObjectOptions - err = obj.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = obj.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } @@ -1582,7 +1582,7 @@ func TestHealLastDataShard(t *testing.T) { } var opts ObjectOptions - err = obj.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = obj.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket - %v", err) } diff --git a/cmd/erasure-object_test.go b/cmd/erasure-object_test.go index 5189ec869..65d71d742 100644 --- a/cmd/erasure-object_test.go +++ b/cmd/erasure-object_test.go @@ -53,7 +53,7 @@ func TestRepeatPutObjectPart(t *testing.T) { defer objLayer.Shutdown(context.Background()) defer removeRoots(disks) - err = objLayer.MakeBucketWithLocation(ctx, "bucket1", MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, "bucket1", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -101,7 +101,7 @@ func TestErasureDeleteObjectBasic(t *testing.T) { } defer xl.Shutdown(context.Background()) - err = xl.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = xl.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -155,7 +155,7 @@ func TestDeleteObjectsVersioned(t *testing.T) { {bucketName, "dir/obj1"}, } - err = obj.MakeBucketWithLocation(ctx, bucketName, MakeBucketOptions{ + err = obj.MakeBucket(ctx, bucketName, MakeBucketOptions{ VersioningEnabled: true, }) if err != nil { @@ -244,7 +244,7 @@ func TestErasureDeleteObjectsErasureSet(t *testing.T) { {bucketName, "obj_4"}, } - err := erasureSets.MakeBucketWithLocation(ctx, bucketName, MakeBucketOptions{}) + err := erasureSets.MakeBucket(ctx, bucketName, MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -305,7 +305,7 @@ func TestErasureDeleteObjectDiskNotFound(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -374,7 +374,7 @@ func TestErasureDeleteObjectDiskNotFoundErasure4(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -434,7 +434,7 @@ func TestErasureDeleteObjectDiskNotFoundErr(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -505,7 +505,7 @@ func TestGetObjectNoQuorum(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -614,7 +614,7 @@ func TestHeadObjectNoQuorum(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -692,7 +692,7 @@ func TestPutObjectNoQuorum(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -755,7 +755,7 @@ func TestPutObjectNoQuorumSmall(t *testing.T) { xl := z.serverPools[0].sets[0] // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, "bucket", MakeBucketOptions{}) + err = obj.MakeBucket(ctx, "bucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -824,7 +824,7 @@ func TestPutObjectSmallInlineData(t *testing.T) { object := "object" // Create "bucket" - err = obj.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err = obj.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -892,7 +892,7 @@ func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []strin ctx, cancel := context.WithCancel(GlobalContext) defer cancel() - err := obj.MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + err := obj.MakeBucket(ctx, bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("Failed to make a bucket %v", err) } @@ -1091,7 +1091,7 @@ func TestGetObjectInlineNotInline(t *testing.T) { defer removeRoots(fsDirs) // Create a testbucket - err = objLayer.MakeBucketWithLocation(ctx, "testbucket", MakeBucketOptions{}) + err = objLayer.MakeBucket(ctx, "testbucket", MakeBucketOptions{}) if err != nil { t.Fatal(err) } @@ -1161,7 +1161,7 @@ func TestGetObjectWithOutdatedDisks(t *testing.T) { for i, testCase := range testCases { // Step 1: create a bucket - err = z.MakeBucketWithLocation(ctx, testCase.bucket, MakeBucketOptions{VersioningEnabled: testCase.versioned}) + err = z.MakeBucket(ctx, testCase.bucket, MakeBucketOptions{VersioningEnabled: testCase.versioned}) if err != nil { t.Fatalf("Test %d: Failed to create a bucket: %v", i+1, err) } diff --git a/cmd/erasure-server-pool-decom.go b/cmd/erasure-server-pool-decom.go index b3c25e9cf..3c7a1fa96 100644 --- a/cmd/erasure-server-pool-decom.go +++ b/cmd/erasure-server-pool-decom.go @@ -1240,7 +1240,7 @@ func (z *erasureServerPools) StartDecommission(ctx context.Context, idx int) (er pathJoin(minioMetaBucket, bucketMetaPrefix), } { var bucketExists BucketExists - if err = z.MakeBucketWithLocation(ctx, metaBucket, MakeBucketOptions{}); err != nil { + if err = z.MakeBucket(ctx, metaBucket, MakeBucketOptions{}); err != nil { if !errors.As(err, &bucketExists) { return err } diff --git a/cmd/erasure-server-pool.go b/cmd/erasure-server-pool.go index c8dde437e..6c1141697 100644 --- a/cmd/erasure-server-pool.go +++ b/cmd/erasure-server-pool.go @@ -33,6 +33,7 @@ import ( "github.com/dustin/go-humanize" "github.com/minio/madmin-go/v2" + "github.com/minio/minio-go/v7/pkg/s3utils" "github.com/minio/minio-go/v7/pkg/set" "github.com/minio/minio-go/v7/pkg/tags" "github.com/minio/minio/internal/bucket/lifecycle" @@ -687,20 +688,29 @@ func (z *erasureServerPools) NSScanner(ctx context.Context, bf *bloomFilter, upd return firstErr } -// MakeBucketWithLocation - creates a new bucket across all serverPools simultaneously +// MakeBucket - creates a new bucket across all serverPools simultaneously // even if one of the sets fail to create buckets, we proceed all the successful // operations. -func (z *erasureServerPools) MakeBucketWithLocation(ctx context.Context, bucket string, opts MakeBucketOptions) error { +func (z *erasureServerPools) MakeBucket(ctx context.Context, bucket string, opts MakeBucketOptions) error { + defer NSUpdated(bucket, slashSeparator) + g := errgroup.WithNErrs(len(z.serverPools)) - // Lock the bucket name before creating. - lk := z.NewNSLock(minioMetaTmpBucket, bucket+".lck") - lkctx, err := lk.GetLock(ctx, globalOperationTimeout) - if err != nil { - return err + if !isMinioMetaBucketName(bucket) { + // Verify if bucket is valid. + if err := s3utils.CheckValidBucketNameStrict(bucket); err != nil { + return BucketNameInvalid{Bucket: bucket} + } + + // Lock the bucket name before creating. + lk := z.NewNSLock(minioMetaTmpBucket, bucket+".lck") + lkctx, err := lk.GetLock(ctx, globalOperationTimeout) + if err != nil { + return err + } + ctx = lkctx.Context() + defer lk.Unlock(lkctx.Cancel) } - ctx = lkctx.Context() - defer lk.Unlock(lkctx.Cancel) // Create buckets in parallel across all sets. for index := range z.serverPools { @@ -709,7 +719,7 @@ func (z *erasureServerPools) MakeBucketWithLocation(ctx context.Context, bucket if z.IsSuspended(index) { return nil } - return z.serverPools[index].MakeBucketWithLocation(ctx, bucket, opts) + return z.serverPools[index].MakeBucket(ctx, bucket, opts) }, index) } @@ -1644,6 +1654,8 @@ func (z *erasureServerPools) IsTaggingSupported() bool { // even if one of the serverPools fail to delete buckets, we proceed to // undo a successful operation. func (z *erasureServerPools) DeleteBucket(ctx context.Context, bucket string, opts DeleteBucketOptions) error { + defer NSUpdated(bucket, slashSeparator) + g := errgroup.WithNErrs(len(z.serverPools)) // Delete buckets in parallel across all serverPools. @@ -1724,7 +1736,7 @@ func undoDeleteBucketServerPools(ctx context.Context, bucket string, serverPools index := index g.Go(func() error { if errs[index] == nil { - return serverPools[index].MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + return serverPools[index].MakeBucket(ctx, bucket, MakeBucketOptions{}) } return nil }, index) diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index 4cb4728a9..e45508807 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -679,14 +679,14 @@ func (s *erasureSets) Shutdown(ctx context.Context) error { // MakeBucketLocation - creates a new bucket across all sets simultaneously, // then return the first encountered error -func (s *erasureSets) MakeBucketWithLocation(ctx context.Context, bucket string, opts MakeBucketOptions) error { +func (s *erasureSets) MakeBucket(ctx context.Context, bucket string, opts MakeBucketOptions) error { g := errgroup.WithNErrs(len(s.sets)) // Create buckets in parallel across all sets. for index := range s.sets { index := index g.Go(func() error { - return s.sets[index].MakeBucketWithLocation(ctx, bucket, opts) + return s.sets[index].MakeBucket(ctx, bucket, opts) }, index) } @@ -815,7 +815,7 @@ func undoDeleteBucketSets(ctx context.Context, bucket string, sets []*erasureObj index := index g.Go(func() error { if errs[index] == nil { - return sets[index].MakeBucketWithLocation(ctx, bucket, MakeBucketOptions{}) + return sets[index].MakeBucket(ctx, bucket, MakeBucketOptions{}) } return nil }, index) diff --git a/cmd/object-api-deleteobject_test.go b/cmd/object-api-deleteobject_test.go index 3a6f00ea5..eef575493 100644 --- a/cmd/object-api-deleteobject_test.go +++ b/cmd/object-api-deleteobject_test.go @@ -84,7 +84,7 @@ func testDeleteObject(obj ObjectLayer, instanceType string, t TestErrHandler) { } for i, testCase := range testCases { - err := obj.MakeBucketWithLocation(context.Background(), testCase.bucketName, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), testCase.bucketName, MakeBucketOptions{}) if err != nil { t.Fatalf("%s : %s", instanceType, err.Error()) } diff --git a/cmd/object-api-getobjectinfo_test.go b/cmd/object-api-getobjectinfo_test.go index d7d541324..6bee4b56a 100644 --- a/cmd/object-api-getobjectinfo_test.go +++ b/cmd/object-api-getobjectinfo_test.go @@ -31,7 +31,7 @@ func TestGetObjectInfo(t *testing.T) { // Testing GetObjectInfo(). func testGetObjectInfo(obj ObjectLayer, instanceType string, t TestErrHandler) { // This bucket is used for testing getObjectInfo operations. - err := obj.MakeBucketWithLocation(context.Background(), "test-getobjectinfo", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "test-getobjectinfo", MakeBucketOptions{}) if err != nil { t.Fatalf("%s : %s", instanceType, err.Error()) } diff --git a/cmd/object-api-interface.go b/cmd/object-api-interface.go index 7edfa6e6f..91ed9672a 100644 --- a/cmd/object-api-interface.go +++ b/cmd/object-api-interface.go @@ -117,7 +117,6 @@ type TransitionOptions struct { // MakeBucketOptions represents bucket options for ObjectLayer bucket operations type MakeBucketOptions struct { - Location string LockEnabled bool VersioningEnabled bool ForceCreate bool // Create buckets even if they are already created. @@ -200,7 +199,7 @@ type ObjectLayer interface { LocalStorageInfo(ctx context.Context) StorageInfo // Bucket operations. - MakeBucketWithLocation(ctx context.Context, bucket string, opts MakeBucketOptions) error + MakeBucket(ctx context.Context, bucket string, opts MakeBucketOptions) error GetBucketInfo(ctx context.Context, bucket string, opts BucketOptions) (bucketInfo BucketInfo, err error) ListBuckets(ctx context.Context, opts BucketOptions) (buckets []BucketInfo, err error) DeleteBucket(ctx context.Context, bucket string, opts DeleteBucketOptions) error diff --git a/cmd/object-api-listobjects_test.go b/cmd/object-api-listobjects_test.go index 625b1b688..d390a358a 100644 --- a/cmd/object-api-listobjects_test.go +++ b/cmd/object-api-listobjects_test.go @@ -41,7 +41,7 @@ func testListObjectsVersionedFolders(obj ObjectLayer, instanceType string, t1 Te "test-bucket-files", } for _, bucket := range testBuckets { - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{ + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{ VersioningEnabled: true, }) if err != nil { @@ -331,7 +331,7 @@ func _testListObjects(obj ObjectLayer, instanceType string, t1 TestErrHandler, v 6: "test-bucket-custom-delimiter", } for _, bucket := range testBuckets { - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{ + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{ VersioningEnabled: versioned, }) if err != nil { @@ -1036,7 +1036,7 @@ func testDeleteObjectVersion(obj ObjectLayer, instanceType string, t1 TestErrHan "bucket-suspended-version-id", } for _, bucket := range testBuckets { - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{ + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{ VersioningEnabled: true, }) if err != nil { @@ -1123,7 +1123,7 @@ func testListObjectVersions(obj ObjectLayer, instanceType string, t1 TestErrHand "test-bucket-max-keys-prefixes", } for _, bucket := range testBuckets { - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{VersioningEnabled: true}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{VersioningEnabled: true}) if err != nil { t.Fatalf("%s : %s", instanceType, err.Error()) } @@ -1753,7 +1753,7 @@ func testListObjectsContinuation(obj ObjectLayer, instanceType string, t1 TestEr "test-bucket-list-object-continuation-2", } for _, bucket := range testBuckets { - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { t.Fatalf("%s : %s", instanceType, err.Error()) } @@ -1908,7 +1908,7 @@ func BenchmarkListObjects(b *testing.B) { bucket := "ls-benchmark-bucket" // Create a bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { b.Fatal(err) } diff --git a/cmd/object-api-multipart_test.go b/cmd/object-api-multipart_test.go index ab2bbfd8b..efb152bcc 100644 --- a/cmd/object-api-multipart_test.go +++ b/cmd/object-api-multipart_test.go @@ -56,7 +56,7 @@ func testObjectNewMultipartUpload(obj ObjectLayer, instanceType string, t TestEr } // Create bucket before intiating NewMultipartUpload. - err = obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -89,7 +89,7 @@ func testObjectAbortMultipartUpload(obj ObjectLayer, instanceType string, t Test object := "minio-object" opts := ObjectOptions{} // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -136,7 +136,7 @@ func testObjectAPIIsUploadIDExists(obj ObjectLayer, instanceType string, t TestE object := "minio-object" // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -168,7 +168,7 @@ func testObjectAPIPutObjectPart(obj ObjectLayer, instanceType string, t TestErrH object := "minio-object" opts := ObjectOptions{} // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -181,7 +181,7 @@ func testObjectAPIPutObjectPart(obj ObjectLayer, instanceType string, t TestErrH } uploadID := res.UploadID // Creating a dummy bucket for tests. - err = obj.MakeBucketWithLocation(context.Background(), "unused-bucket", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "unused-bucket", MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -316,7 +316,7 @@ func testListMultipartUploads(obj ObjectLayer, instanceType string, t TestErrHan // objectNames[0]. // uploadIds [0]. // Create bucket before initiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucketNames[0], MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketNames[0], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -334,7 +334,7 @@ func testListMultipartUploads(obj ObjectLayer, instanceType string, t TestErrHan // objectNames[0]. // uploadIds [1-3]. // Bucket to test for mutiple upload Id's for a given object. - err = obj.MakeBucketWithLocation(context.Background(), bucketNames[1], MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucketNames[1], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -355,7 +355,7 @@ func testListMultipartUploads(obj ObjectLayer, instanceType string, t TestErrHan // bucketnames[2]. // objectNames[0-2]. // uploadIds [4-9]. - err = obj.MakeBucketWithLocation(context.Background(), bucketNames[2], MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucketNames[2], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -1197,7 +1197,7 @@ func testListObjectPartsDiskNotFound(obj ObjectLayer, instanceType string, disks // objectNames[0]. // uploadIds [0]. // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucketNames[0], MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketNames[0], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -1441,7 +1441,7 @@ func testListObjectParts(obj ObjectLayer, instanceType string, t TestErrHandler) // objectNames[0]. // uploadIds [0]. // Create bucket before intiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucketNames[0], MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketNames[0], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -1682,7 +1682,7 @@ func testObjectCompleteMultipartUpload(obj ObjectLayer, instanceType string, t T // objectNames[0]. // uploadIds [0]. // Create bucket before intiating NewMultipartUpload. - err = obj.MakeBucketWithLocation(context.Background(), bucketNames[0], MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucketNames[0], MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err) diff --git a/cmd/object-api-putobject_test.go b/cmd/object-api-putobject_test.go index a9d3f3b0c..a40ba6d56 100644 --- a/cmd/object-api-putobject_test.go +++ b/cmd/object-api-putobject_test.go @@ -47,14 +47,14 @@ func testObjectAPIPutObject(obj ObjectLayer, instanceType string, t TestErrHandl object := "minio-object" // Create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) } // Creating a dummy bucket for tests. - err = obj.MakeBucketWithLocation(context.Background(), "unused-bucket", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "unused-bucket", MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -223,14 +223,14 @@ func testObjectAPIPutObjectDiskNotFound(obj ObjectLayer, instanceType string, di object := "minio-object" // Create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) } // Creating a dummy bucket for tests. - err = obj.MakeBucketWithLocation(context.Background(), "unused-bucket", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "unused-bucket", MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -335,7 +335,7 @@ func testObjectAPIPutObjectStaleFiles(obj ObjectLayer, instanceType string, disk object := "minio-object" // Create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -380,7 +380,7 @@ func testObjectAPIMultipartPutObjectStaleFiles(obj ObjectLayer, instanceType str object := "minio-object" // Create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucket, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucket, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) diff --git a/cmd/object_api_suite_test.go b/cmd/object_api_suite_test.go index d080d4847..a88add526 100644 --- a/cmd/object_api_suite_test.go +++ b/cmd/object_api_suite_test.go @@ -77,7 +77,7 @@ func TestMakeBucket(t *testing.T) { // Tests validate bucket creation. func testMakeBucket(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "bucket-unknown", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket-unknown", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -91,7 +91,7 @@ func TestMultipartObjectCreation(t *testing.T) { // Tests validate creation of part files during Multipart operation. func testMultipartObjectCreation(obj ObjectLayer, instanceType string, t TestErrHandler) { var opts ObjectOptions - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -137,7 +137,7 @@ func TestMultipartObjectAbort(t *testing.T) { // Tests validate abortion of Multipart operation. func testMultipartObjectAbort(obj ObjectLayer, instanceType string, t TestErrHandler) { var opts ObjectOptions - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -184,7 +184,7 @@ func TestMultipleObjectCreation(t *testing.T) { func testMultipleObjectCreation(obj ObjectLayer, instanceType string, t TestErrHandler) { objects := make(map[string][]byte) var opts ObjectOptions - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -239,7 +239,7 @@ func TestPaging(t *testing.T) { // Tests validate creation of objects and the order of listing using various filters for ListObjects operation. func testPaging(obj ObjectLayer, instanceType string, t TestErrHandler) { - obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) result, err := obj.ListObjects(context.Background(), "bucket", "", "", "", 0) if err != nil { t.Fatalf("%s: %s", instanceType, err) @@ -443,7 +443,7 @@ func TestObjectOverwriteWorks(t *testing.T) { // Tests validate overwriting of an existing object. func testObjectOverwriteWorks(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -497,11 +497,11 @@ func TestBucketRecreateFails(t *testing.T) { // Tests validate that recreation of the bucket fails. func testBucketRecreateFails(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "string", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "string", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } - err = obj.MakeBucketWithLocation(context.Background(), "string", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "string", MakeBucketOptions{}) if err == nil { t.Fatalf("%s: Expected error but found nil.", instanceType) } @@ -602,7 +602,7 @@ func testPutObject(obj ObjectLayer, instanceType string, t TestErrHandler) { length := int64(len(content)) readerEOF := newTestReaderEOF(content) readerNoEOF := newTestReaderNoEOF(content) - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -642,7 +642,7 @@ func TestPutObjectInSubdir(t *testing.T) { // Tests validate PutObject with subdirectory prefix. func testPutObjectInSubdir(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -684,7 +684,7 @@ func testListBuckets(obj ObjectLayer, instanceType string, t TestErrHandler) { } // add one and test exists. - err = obj.MakeBucketWithLocation(context.Background(), "bucket1", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "bucket1", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -698,7 +698,7 @@ func testListBuckets(obj ObjectLayer, instanceType string, t TestErrHandler) { } // add two and test exists. - err = obj.MakeBucketWithLocation(context.Background(), "bucket2", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "bucket2", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -712,7 +712,7 @@ func testListBuckets(obj ObjectLayer, instanceType string, t TestErrHandler) { } // add three and test exists + prefix. - err = obj.MakeBucketWithLocation(context.Background(), "bucket22", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "bucket22", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -736,11 +736,11 @@ func testListBucketsOrder(obj ObjectLayer, instanceType string, t TestErrHandler // if implementation contains a map, order of map keys will vary. // this ensures they return in the same order each time. // add one and test exists. - err := obj.MakeBucketWithLocation(context.Background(), "bucket1", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket1", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } - err = obj.MakeBucketWithLocation(context.Background(), "bucket2", MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), "bucket2", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -789,7 +789,7 @@ func TestNonExistantObjectInBucket(t *testing.T) { // Tests validate that GetObject fails on a non-existent bucket as expected. func testNonExistantObjectInBucket(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -817,7 +817,7 @@ func TestGetDirectoryReturnsObjectNotFound(t *testing.T) { // Tests validate that GetObject on an existing directory fails as expected. func testGetDirectoryReturnsObjectNotFound(obj ObjectLayer, instanceType string, t TestErrHandler) { bucketName := "bucket" - err := obj.MakeBucketWithLocation(context.Background(), bucketName, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketName, MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } @@ -859,7 +859,7 @@ func TestContentType(t *testing.T) { // Test content-type. func testContentType(obj ObjectLayer, instanceType string, t TestErrHandler) { - err := obj.MakeBucketWithLocation(context.Background(), "bucket", MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), "bucket", MakeBucketOptions{}) if err != nil { t.Fatalf("%s: %s", instanceType, err) } diff --git a/cmd/post-policy_test.go b/cmd/post-policy_test.go index 74247ddd2..872982970 100644 --- a/cmd/post-policy_test.go +++ b/cmd/post-policy_test.go @@ -141,7 +141,7 @@ func testPostPolicyBucketHandler(obj ObjectLayer, instanceType string, t TestErr // objectNames[0]. // uploadIds [0]. // Create bucket before initiating NewMultipartUpload. - err := obj.MakeBucketWithLocation(context.Background(), bucketName, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketName, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) @@ -460,7 +460,7 @@ func testPostPolicyBucketHandlerRedirect(obj ObjectLayer, instanceType string, t curTime := UTCNow() curTimePlus5Min := curTime.Add(time.Minute * 5) - err = obj.MakeBucketWithLocation(context.Background(), bucketName, MakeBucketOptions{}) + err = obj.MakeBucket(context.Background(), bucketName, MakeBucketOptions{}) if err != nil { // Failed to create newbucket, abort. t.Fatalf("%s : %s", instanceType, err.Error()) diff --git a/cmd/site-replication.go b/cmd/site-replication.go index 576ba8524..a0eda11c8 100644 --- a/cmd/site-replication.go +++ b/cmd/site-replication.go @@ -682,9 +682,6 @@ func (c *SiteReplicationSys) MakeBucketHook(ctx context.Context, bucket string, } optsMap := make(map[string]string) - if opts.Location != "" { - optsMap["location"] = opts.Location - } if opts.LockEnabled { optsMap["lockEnabled"] = "true" optsMap["versioningEnabled"] = "true" @@ -780,7 +777,7 @@ func (c *SiteReplicationSys) PeerBucketMakeWithVersioningHandler(ctx context.Con return errServerNotInitialized } - err := objAPI.MakeBucketWithLocation(ctx, bucket, opts) + err := objAPI.MakeBucket(ctx, bucket, opts) if err != nil { // Check if this is a bucket exists error. _, ok1 := err.(BucketExists) @@ -3209,7 +3206,6 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI Bucket: bucket, CreatedAt: bucketInfo.Created.UTC(), DeletedAt: bucketInfo.Deleted.UTC(), - Location: globalSite.Region, } if !bucketExists { info.Buckets[bucket] = bms @@ -4280,11 +4276,6 @@ func (c *SiteReplicationSys) healBucket(ctx context.Context, objAPI ObjectLayer, if isMakeBucket { var opts MakeBucketOptions optsMap := make(map[string]string) - if bStatus.Location != "" { - optsMap["location"] = bStatus.Location - opts.Location = bStatus.Location - } - optsMap["versioningEnabled"] = "true" opts.VersioningEnabled = true opts.CreatedAt = bStatus.CreatedAt diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 9416a8b88..eea1e09f7 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -1547,7 +1547,7 @@ func initAPIHandlerTest(ctx context.Context, obj ObjectLayer, endpoints []string bucketName := getRandomBucketName() // Create bucket. - err := obj.MakeBucketWithLocation(context.Background(), bucketName, MakeBucketOptions{}) + err := obj.MakeBucket(context.Background(), bucketName, MakeBucketOptions{}) if err != nil { // failed to create newbucket, return err. return "", nil, err