From 08e9846fd5a040887e2ddbfca36da97777fc76f6 Mon Sep 17 00:00:00 2001 From: Yuval Lifshitz Date: Tue, 9 Mar 2021 12:36:09 +0200 Subject: [PATCH] rgw/notifications: delete bucket notification object when empty Fixes: https://tracker.ceph.com/issues/49650 Signed-off-by: Yuval Lifshitz --- src/rgw/rgw_pubsub.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_pubsub.cc b/src/rgw/rgw_pubsub.cc index 33f650914c55..8d0256d19747 100644 --- a/src/rgw/rgw_pubsub.cc +++ b/src/rgw/rgw_pubsub.cc @@ -603,6 +603,17 @@ int RGWPubSub::Bucket::remove_notification(const string& topic_name, optional_yi bucket_topics.topics.erase(topic_name); + if (bucket_topics.topics.empty()) { + // no more topics - delete the notification object of the bucket + ret = ps->remove(bucket_meta_obj, &objv_tracker, y); + if (ret < 0 && ret != -ENOENT) { + ldout(ps->store->ctx(), 1) << "ERROR: failed to remove bucket topics: ret=" << ret << dendl; + return ret; + } + return 0; + } + + // write back the notifications without the deleted one ret = write_topics(bucket_topics, &objv_tracker, y); if (ret < 0) { ldout(store->ctx(), 1) << "ERROR: failed to write topics info: ret=" << ret << dendl; @@ -631,7 +642,7 @@ int RGWPubSub::Bucket::remove_notifications(optional_yield y) } } - // delete all notification of on a bucket + // delete the notification object of the bucket ret = ps->remove(bucket_meta_obj, nullptr, y); if (ret < 0 && ret != -ENOENT) { ldout(ps->store->ctx(), 1) << "ERROR: failed to remove bucket topics: ret=" << ret << dendl; -- 2.47.3