]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: notify svc uses vector for watchers
authorCasey Bodley <cbodley@redhat.com>
Wed, 26 Mar 2025 22:25:59 +0000 (18:25 -0400)
committerCasey Bodley <cbodley@redhat.com>
Thu, 27 Mar 2025 13:52:45 +0000 (09:52 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/services/svc_notify.cc
src/rgw/services/svc_notify.h

index 866ea7fd4ac119b854f504d428195fc53fee1c6f..ae49199d99714ed21e705f61670511409df5dfd0 100644 (file)
@@ -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)
index 4f7e9d17ee37e2843c1c5738548a3c4e5c05561c..905200caaf3adc4de3d9c55d1aab1ed5be0e7217 100644 (file)
@@ -35,7 +35,7 @@ private:
   rgw_pool control_pool;
 
   int num_watchers{0};
-  RGWWatcher **watchers{nullptr};
+  std::vector<RGWWatcher> watchers;
   std::set<int> watchers_set;
   std::vector<rgw_rados_ref> 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;