From cf0645552cfa629af638f8d62f061ab5d0fc3021 Mon Sep 17 00:00:00 2001 From: Ali Masarwa Date: Mon, 29 May 2023 17:40:15 +0300 Subject: [PATCH] RGW:notifications: persistent topics are not deleted via radosgw-admin Signed-off-by: Ali Masarwa (cherry picked from commit 8374da4dde710f9e1678c1d2daff895bb084bc20) --- src/rgw/driver/rados/rgw_notify.cc | 66 +++++++++++++++--------------- src/rgw/driver/rados/rgw_notify.h | 3 ++ src/rgw/rgw_admin.cc | 6 +++ 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/rgw/driver/rados/rgw_notify.cc b/src/rgw/driver/rados/rgw_notify.cc index 0821e69a93911..f3c06b1dcc7d1 100644 --- a/src/rgw/driver/rados/rgw_notify.cc +++ b/src/rgw/driver/rados/rgw_notify.cc @@ -52,6 +52,8 @@ auto make_stack_allocator() { return boost::context::protected_fixedsize_stack{128*1024}; } +const std::string Q_LIST_OBJECT_NAME = "queues_list_object"; + class Manager : public DoutPrefixProvider { const size_t max_queue_size; const uint32_t queues_update_period_ms; @@ -59,7 +61,6 @@ class Manager : public DoutPrefixProvider { const uint32_t queue_idle_sleep_us; const utime_t failover_time; CephContext* const cct; - librados::IoCtx& rados_ioctx; static constexpr auto COOKIE_LEN = 16; const std::string lock_cookie; boost::asio::io_context io_context; @@ -68,8 +69,9 @@ class Manager : public DoutPrefixProvider { std::vector workers; const uint32_t stale_reservations_period_s; const uint32_t reservations_cleanup_period_s; - - const std::string Q_LIST_OBJECT_NAME = "queues_list_object"; +public: + librados::IoCtx& rados_ioctx; +private: CephContext *get_cct() const override { return cct; } unsigned get_subsys() const override { return dout_subsys; } @@ -481,12 +483,12 @@ public: queue_idle_sleep_us(_queue_idle_sleep_us), failover_time(std::chrono::milliseconds(failover_time_ms)), cct(_cct), - rados_ioctx(store->getRados()->get_notif_pool_ctx()), lock_cookie(gen_rand_alphanumeric(cct, COOKIE_LEN)), work_guard(boost::asio::make_work_guard(io_context)), worker_count(_worker_count), stale_reservations_period_s(_stale_reservations_period_s), - reservations_cleanup_period_s(_reservations_cleanup_period_s) + reservations_cleanup_period_s(_reservations_cleanup_period_s), + rados_ioctx(store->getRados()->get_notif_pool_ctx()) { spawn::spawn(io_context, [this] (yield_context yield) { process_queues(yield); @@ -541,32 +543,6 @@ public: ldpp_dout(this, 20) << "INFO: queue: " << topic_name << " added to queue list" << dendl; return 0; } - - int remove_persistent_topic(const std::string& topic_name, optional_yield y) { - librados::ObjectWriteOperation op; - op.remove(); - auto ret = rgw_rados_operate(this, rados_ioctx, topic_name, &op, y); - if (ret == -ENOENT) { - // queue already removed - nothing to do - ldpp_dout(this, 20) << "INFO: queue for topic: " << topic_name << " already removed. nothing to do" << dendl; - return 0; - } - if (ret < 0) { - // failed to remove queue - ldpp_dout(this, 1) << "ERROR: failed to remove queue for topic: " << topic_name << ". error: " << ret << dendl; - return ret; - } - - std::set topic_to_remove{{topic_name}}; - op.omap_rm_keys(topic_to_remove); - ret = rgw_rados_operate(this, rados_ioctx, Q_LIST_OBJECT_NAME, &op, y); - if (ret < 0) { - ldpp_dout(this, 1) << "ERROR: failed to remove queue: " << topic_name << " from queue list. error: " << ret << dendl; - return ret; - } - ldpp_dout(this, 20) << "INFO: queue: " << topic_name << " removed from queue list" << dendl; - return 0; - } }; // singleton manager @@ -609,11 +585,37 @@ int add_persistent_topic(const std::string& topic_name, optional_yield y) { return s_manager->add_persistent_topic(topic_name, y); } +int remove_persistent_topic(const DoutPrefixProvider* dpp, librados::IoCtx& rados_ioctx, const std::string& topic_name, optional_yield y) { + librados::ObjectWriteOperation op; + op.remove(); + auto ret = rgw_rados_operate(dpp, rados_ioctx, topic_name, &op, y); + if (ret == -ENOENT) { + // queue already removed - nothing to do + ldpp_dout(dpp, 20) << "INFO: queue for topic: " << topic_name << " already removed. nothing to do" << dendl; + return 0; + } + if (ret < 0) { + // failed to remove queue + ldpp_dout(dpp, 1) << "ERROR: failed to remove queue for topic: " << topic_name << ". error: " << ret << dendl; + return ret; + } + + std::set topic_to_remove{{topic_name}}; + op.omap_rm_keys(topic_to_remove); + ret = rgw_rados_operate(dpp, rados_ioctx, Q_LIST_OBJECT_NAME, &op, y); + if (ret < 0) { + ldpp_dout(dpp, 1) << "ERROR: failed to remove queue: " << topic_name << " from queue list. error: " << ret << dendl; + return ret; + } + ldpp_dout(dpp, 20) << "INFO: queue: " << topic_name << " removed from queue list" << dendl; + return 0; +} + int remove_persistent_topic(const std::string& topic_name, optional_yield y) { if (!s_manager) { return -EAGAIN; } - return s_manager->remove_persistent_topic(topic_name, y); + return remove_persistent_topic(s_manager, s_manager->rados_ioctx, topic_name, y); } rgw::sal::Object* get_object_with_atttributes( diff --git a/src/rgw/driver/rados/rgw_notify.h b/src/rgw/driver/rados/rgw_notify.h index dd2d69c5fdb19..9269611e4a6f3 100644 --- a/src/rgw/driver/rados/rgw_notify.h +++ b/src/rgw/driver/rados/rgw_notify.h @@ -38,6 +38,9 @@ int add_persistent_topic(const std::string& topic_name, optional_yield y); // this operation also remove the topic name from the common (to all RGWs) list of all topics int remove_persistent_topic(const std::string& topic_name, optional_yield y); +// same as the above, expect you need to provide the IoCtx, the above uses rgw::notify::Manager::rados_ioctx +int remove_persistent_topic(const DoutPrefixProvider* dpp, librados::IoCtx& rados_ioctx, const std::string& topic_name, optional_yield y); + // struct holding reservation information // populated in the publish_reserve call // then used to commit or abort the reservation diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 6a181c954d4bb..a99eee264ebef 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -10505,6 +10505,12 @@ next: return EINVAL; } + ret = rgw::notify::remove_persistent_topic(dpp(), static_cast(driver)->getRados()->get_notif_pool_ctx(), topic_name, null_yield); + if (ret < 0) { + cerr << "ERROR: could not remove persistent topic: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + RGWPubSub ps(driver, tenant); ret = ps.remove_topic(dpp(), topic_name, null_yield); -- 2.39.5