From cbb7a0937669b58f82f2661db0c71db479656fbd Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 15 Jun 2020 22:09:39 -0700 Subject: [PATCH] Allow etcd, cache setup to exit when starting gateway mode (#9842) - Initialize etcd once per call - Fail etcd, cache setup pro-actively for gateway setups - Support deleting/updating bucket notification, tagging, lifecycle, sse-encryption --- cmd/bucket-handlers.go | 8 ++++---- cmd/bucket-metadata-sys.go | 41 ++++++++++++++++++++++++++++++++++++-- cmd/bucket-metadata.go | 4 ++-- cmd/config-current.go | 28 ++++++++++++++++++++------ cmd/erasure-zones.go | 2 +- 5 files changed, 68 insertions(+), 15 deletions(-) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index df6102607..e7492b988 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -45,8 +45,8 @@ import ( ) const ( - objectLockConfig = "object-lock.xml" - bucketTaggingConfigFile = "tagging.xml" + objectLockConfig = "object-lock.xml" + bucketTaggingConfig = "tagging.xml" ) // Check if there are buckets on server without corresponding entry in etcd backend and @@ -1106,7 +1106,7 @@ func (api objectAPIHandlers) PutBucketTaggingHandler(w http.ResponseWriter, r *h return } - if err = globalBucketMetadataSys.Update(bucket, bucketTaggingConfigFile, configData); err != nil { + if err = globalBucketMetadataSys.Update(bucket, bucketTaggingConfig, configData); err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) return } @@ -1174,7 +1174,7 @@ func (api objectAPIHandlers) DeleteBucketTaggingHandler(w http.ResponseWriter, r return } - if err := globalBucketMetadataSys.Update(bucket, bucketTaggingConfigFile, nil); err != nil { + if err := globalBucketMetadataSys.Update(bucket, bucketTaggingConfig, nil); err != nil { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) return } diff --git a/cmd/bucket-metadata-sys.go b/cmd/bucket-metadata-sys.go index 72d001713..66cae850b 100644 --- a/cmd/bucket-metadata-sys.go +++ b/cmd/bucket-metadata-sys.go @@ -77,7 +77,44 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat if globalIsGateway { // This code is needed only for gateway implementations. - if configFile == bucketPolicyConfig { + switch configFile { + case bucketSSEConfig: + if globalGatewayName == "nas" { + meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) + if err != nil { + return err + } + meta.EncryptionConfigXML = configData + return meta.Save(GlobalContext, objAPI) + } + case bucketLifecycleConfig: + if globalGatewayName == "nas" { + meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) + if err != nil { + return err + } + meta.LifecycleConfigXML = configData + return meta.Save(GlobalContext, objAPI) + } + case bucketTaggingConfig: + if globalGatewayName == "nas" { + meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) + if err != nil { + return err + } + meta.TaggingConfigXML = configData + return meta.Save(GlobalContext, objAPI) + } + case bucketNotificationConfig: + if globalGatewayName == "nas" { + meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) + if err != nil { + return err + } + meta.NotificationConfigXML = configData + return meta.Save(GlobalContext, objAPI) + } + case bucketPolicyConfig: if configData == nil { return objAPI.DeleteBucketPolicy(GlobalContext, bucket) } @@ -108,7 +145,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat meta.LifecycleConfigXML = configData case bucketSSEConfig: meta.EncryptionConfigXML = configData - case bucketTaggingConfigFile: + case bucketTaggingConfig: meta.TaggingConfigXML = configData case objectLockConfig: meta.ObjectLockConfigXML = configData diff --git a/cmd/bucket-metadata.go b/cmd/bucket-metadata.go index 0ab18f066..5df3d301d 100644 --- a/cmd/bucket-metadata.go +++ b/cmd/bucket-metadata.go @@ -220,7 +220,7 @@ func (b *BucketMetadata) convertLegacyConfigs(ctx context.Context, objectAPI Obj bucketLifecycleConfig, bucketQuotaConfigFile, bucketSSEConfig, - bucketTaggingConfigFile, + bucketTaggingConfig, objectLockConfig, } @@ -270,7 +270,7 @@ func (b *BucketMetadata) convertLegacyConfigs(ctx context.Context, objectAPI Obj b.LifecycleConfigXML = configData case bucketSSEConfig: b.EncryptionConfigXML = configData - case bucketTaggingConfigFile: + case bucketTaggingConfig: b.TaggingConfigXML = configData case objectLockConfig: b.ObjectLockConfigXML = configData diff --git a/cmd/config-current.go b/cmd/config-current.go index 4c7352ecf..efb2f6775 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -311,6 +311,8 @@ func validateConfig(s config.Config) error { globalNotificationSys.ConfiguredTargetIDs()) } +var syncEtcdOnce sync.Once + func lookupConfigs(s config.Config) { ctx := GlobalContext @@ -325,14 +327,24 @@ func lookupConfigs(s config.Config) { etcdCfg, err := etcd.LookupConfig(s[config.EtcdSubSys][config.Default], globalRootCAs) if err != nil { - logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) + if globalIsGateway { + logger.FatalIf(err, "Unable to initialize etcd config") + } else { + logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) + } } if etcdCfg.Enabled { - globalEtcdClient, err = etcd.New(etcdCfg) - if err != nil { - logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) - } + syncEtcdOnce.Do(func() { + globalEtcdClient, err = etcd.New(etcdCfg) + if err != nil { + if globalIsGateway { + logger.FatalIf(err, "Unable to initialize etcd config") + } else { + logger.LogIf(ctx, fmt.Errorf("Unable to initialize etcd config: %w", err)) + } + } + }) } // Bucket federation is 'true' only when IAM assets are not namespaced @@ -377,7 +389,11 @@ func lookupConfigs(s config.Config) { globalCacheConfig, err = cache.LookupConfig(s[config.CacheSubSys][config.Default]) if err != nil { - logger.LogIf(ctx, fmt.Errorf("Unable to setup cache: %w", err)) + if globalIsGateway { + logger.FatalIf(err, "Unable to setup cache") + } else { + logger.LogIf(ctx, fmt.Errorf("Unable to setup cache: %w", err)) + } } if globalCacheConfig.Enabled { diff --git a/cmd/erasure-zones.go b/cmd/erasure-zones.go index 554b5c906..05c69e434 100644 --- a/cmd/erasure-zones.go +++ b/cmd/erasure-zones.go @@ -1867,7 +1867,7 @@ func (z *erasureZones) getZoneAndSet(id string) (int, int, error) { } } } - return 0, 0, fmt.Errorf("ID(%s) %w", errDiskNotFound) + return 0, 0, fmt.Errorf("DiskID(%s) %w", id, errDiskNotFound) } // IsReady - Returns true, when all the erasure sets are writable.