From ba42174281cfb55c43cf6204af8800d9c5e89fe6 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 (cherry picked from commit 08e9846fd5a040887e2ddbfca36da97777fc76f6) Conflicts: src/rgw/rgw_pubsub.cc Cherry-pick notes: - RGWPubSub methods take a DoutPrefixProvider as first argument in Pacific --- 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 00d8ffdc8642e..c981fc03f553f 100644 --- a/src/rgw/rgw_pubsub.cc +++ b/src/rgw/rgw_pubsub.cc @@ -602,6 +602,17 @@ int RGWPubSub::Bucket::remove_notification(const DoutPrefixProvider *dpp, const bucket_topics.topics.erase(topic_name); + if (bucket_topics.topics.empty()) { + // no more topics - delete the notification object of the bucket + ret = ps->remove(dpp, 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(dpp, bucket_topics, &objv_tracker, y); if (ret < 0) { ldpp_dout(dpp, 1) << "ERROR: failed to write topics info: ret=" << ret << dendl; @@ -630,7 +641,7 @@ int RGWPubSub::Bucket::remove_notifications(const DoutPrefixProvider *dpp, optio } } - // delete all notification of on a bucket + // delete the notification object of the bucket ret = ps->remove(dpp, bucket_meta_obj, nullptr, y); if (ret < 0 && ret != -ENOENT) { ldpp_dout(dpp, 1) << "ERROR: failed to remove bucket topics: ret=" << ret << dendl; -- 2.39.5