From ba6e9682e5ad316cefdd76ba3e2194dc80f86b86 Mon Sep 17 00:00:00 2001 From: Poorna Krishnamoorthy Date: Thu, 24 Jun 2021 08:39:58 -0700 Subject: [PATCH] Clean up targets properly on bucket deletion (#12565) --- cmd/bucket-targets.go | 14 ++++++++++++++ cmd/notification.go | 1 + cmd/peer-rest-server.go | 1 + 3 files changed, 16 insertions(+) diff --git a/cmd/bucket-targets.go b/cmd/bucket-targets.go index 828ee8368..f06fc62be 100644 --- a/cmd/bucket-targets.go +++ b/cmd/bucket-targets.go @@ -84,6 +84,20 @@ func (sys *BucketTargetSys) ListBucketTargets(ctx context.Context, bucket string return nil, BucketRemoteTargetNotFound{Bucket: bucket} } +// Delete clears targets present for a bucket +func (sys *BucketTargetSys) Delete(bucket string) { + sys.Lock() + defer sys.Unlock() + tgts, ok := sys.targetsMap[bucket] + if !ok { + return + } + for _, t := range tgts { + delete(sys.arnRemotesMap, t.Arn) + } + delete(sys.targetsMap, bucket) +} + // SetTarget - sets a new minio-go client target for this bucket. func (sys *BucketTargetSys) SetTarget(ctx context.Context, bucket string, tgt *madmin.BucketTarget, update bool) error { if globalIsGateway { diff --git a/cmd/notification.go b/cmd/notification.go index 5d5484546..49f0971f3 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -607,6 +607,7 @@ func (sys *NotificationSys) LoadBucketMetadata(ctx context.Context, bucketName s func (sys *NotificationSys) DeleteBucketMetadata(ctx context.Context, bucketName string) { globalReplicationStats.Delete(bucketName) globalBucketMetadataSys.Remove(bucketName) + globalBucketTargetSys.Delete(bucketName) if localMetacacheMgr != nil { localMetacacheMgr.deleteBucketCache(bucketName) } diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index d55367899..da4d6141a 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -521,6 +521,7 @@ func (s *peerRESTServer) DeleteBucketMetadataHandler(w http.ResponseWriter, r *h globalReplicationStats.Delete(bucketName) globalBucketMetadataSys.Remove(bucketName) + globalBucketTargetSys.Delete(bucketName) if localMetacacheMgr != nil { localMetacacheMgr.deleteBucketCache(bucketName) }