From 422898d9b32142ce43b1b3fc3f6f101618863e32 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Sat, 31 Oct 2020 09:46:18 -0700 Subject: [PATCH] Clean up metadata cache when deleting bucket (#10802) Metadata caches were left behind when deleting a bucket. --- cmd/metacache-manager.go | 12 ++++++++++++ cmd/notification.go | 3 +++ cmd/peer-rest-server.go | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/metacache-manager.go b/cmd/metacache-manager.go index 36c055c4c..75d62094a 100644 --- a/cmd/metacache-manager.go +++ b/cmd/metacache-manager.go @@ -128,6 +128,18 @@ func (m *metacacheManager) getBucket(ctx context.Context, bucket string) *bucket return b } +// deleteBucketCache will delete the bucket cache if it exists. +func (m *metacacheManager) deleteBucketCache(bucket string) { + m.mu.Lock() + defer m.mu.Unlock() + b, ok := m.buckets[bucket] + if !ok { + return + } + b.deleteAll() + delete(m.buckets, bucket) +} + // deleteAll will delete all caches. func (m *metacacheManager) deleteAll() { m.mu.Lock() diff --git a/cmd/notification.go b/cmd/notification.go index e3777213e..dfabe3e47 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -675,6 +675,9 @@ func (sys *NotificationSys) LoadBucketMetadata(ctx context.Context, bucketName s // DeleteBucketMetadata - calls DeleteBucketMetadata call on all peers func (sys *NotificationSys) DeleteBucketMetadata(ctx context.Context, bucketName string) { globalBucketMetadataSys.Remove(bucketName) + if localMetacacheMgr != nil { + localMetacacheMgr.deleteBucketCache(bucketName) + } ng := WithNPeers(len(sys.peerClients)) for idx, client := range sys.peerClients { diff --git a/cmd/peer-rest-server.go b/cmd/peer-rest-server.go index 7d0a0c3da..2fa872beb 100644 --- a/cmd/peer-rest-server.go +++ b/cmd/peer-rest-server.go @@ -538,7 +538,9 @@ func (s *peerRESTServer) DeleteBucketMetadataHandler(w http.ResponseWriter, r *h } globalBucketMetadataSys.Remove(bucketName) - w.(http.Flusher).Flush() + if localMetacacheMgr != nil { + localMetacacheMgr.deleteBucketCache(bucketName) + } } // LoadBucketMetadataHandler - reloads in memory bucket metadata