From 0afbd09a244b4518a5531d0b542b83f3b24983ea Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 26 Mar 2025 18:25:59 -0400 Subject: [PATCH] rgw: notify svc uses vector for watchers Signed-off-by: Casey Bodley --- src/rgw/services/svc_notify.cc | 21 +++++++++------------ src/rgw/services/svc_notify.h | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/rgw/services/svc_notify.cc b/src/rgw/services/svc_notify.cc index 866ea7fd4ac..ae49199d997 100644 --- a/src/rgw/services/svc_notify.cc +++ b/src/rgw/services/svc_notify.cc @@ -20,6 +20,7 @@ using namespace std; static string notify_oid_prefix = "notify"; +RGWSI_Notify::RGWSI_Notify(CephContext *cct) : RGWServiceInstance(cct) {} RGWSI_Notify::~RGWSI_Notify() { shutdown(); @@ -207,12 +208,12 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y) if (num_watchers <= 0) num_watchers = 1; - watchers = new RGWWatcher *[num_watchers]; - int error = 0; notify_objs.resize(num_watchers); + watchers.reserve(num_watchers); + for (int i=0; i < num_watchers; i++) { string notify_oid; @@ -239,10 +240,9 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y) return r; } - RGWWatcher *watcher = new RGWWatcher(cct, this, i, notify_obj); - watchers[i] = watcher; + auto& watcher = watchers.emplace_back(cct, this, i, notify_obj); - r = watcher->register_watch_async(); + r = watcher.register_watch_async(); if (r < 0) { ldpp_dout(dpp, 0) << "WARNING: register_watch_aio() returned " << r << dendl; error = r; @@ -250,8 +250,8 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y) } } - for (int i = 0; i < num_watchers; ++i) { - int r = watchers[i]->register_watch_finish(); + for (auto& watcher : watchers) { + int r = watcher.register_watch_finish(); if (r < 0) { ldpp_dout(dpp, 0) << "WARNING: async watch returned " << r << dendl; error = r; @@ -268,13 +268,10 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y) void RGWSI_Notify::finalize_watch() { for (int i = 0; i < num_watchers; i++) { - RGWWatcher *watcher = watchers[i]; if (watchers_set.find(i) != watchers_set.end()) - watcher->unregister_watch(); - delete watcher; + watchers[i].unregister_watch(); } - - delete[] watchers; + watchers.clear(); } int RGWSI_Notify::do_start(optional_yield y, const DoutPrefixProvider *dpp) diff --git a/src/rgw/services/svc_notify.h b/src/rgw/services/svc_notify.h index 4f7e9d17ee3..905200caaf3 100644 --- a/src/rgw/services/svc_notify.h +++ b/src/rgw/services/svc_notify.h @@ -35,7 +35,7 @@ private: rgw_pool control_pool; int num_watchers{0}; - RGWWatcher **watchers{nullptr}; + std::vector watchers; std::set watchers_set; std::vector notify_objs; @@ -84,7 +84,7 @@ private: void schedule_context(Context *c); public: - RGWSI_Notify(CephContext *cct): RGWServiceInstance(cct) {} + RGWSI_Notify(CephContext *cct); virtual ~RGWSI_Notify() override; -- 2.39.5