Skip to content

Commit 0afbd09

Browse files
committed
rgw: notify svc uses vector for watchers
Signed-off-by: Casey Bodley <[email protected]>
1 parent 27168f0 commit 0afbd09

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/rgw/services/svc_notify.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using namespace std;
2020

2121
static string notify_oid_prefix = "notify";
2222

23+
RGWSI_Notify::RGWSI_Notify(CephContext *cct) : RGWServiceInstance(cct) {}
2324
RGWSI_Notify::~RGWSI_Notify()
2425
{
2526
shutdown();
@@ -207,12 +208,12 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y)
207208
if (num_watchers <= 0)
208209
num_watchers = 1;
209210

210-
watchers = new RGWWatcher *[num_watchers];
211-
212211
int error = 0;
213212

214213
notify_objs.resize(num_watchers);
215214

215+
watchers.reserve(num_watchers);
216+
216217
for (int i=0; i < num_watchers; i++) {
217218
string notify_oid;
218219

@@ -239,19 +240,18 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y)
239240
return r;
240241
}
241242

242-
RGWWatcher *watcher = new RGWWatcher(cct, this, i, notify_obj);
243-
watchers[i] = watcher;
243+
auto& watcher = watchers.emplace_back(cct, this, i, notify_obj);
244244

245-
r = watcher->register_watch_async();
245+
r = watcher.register_watch_async();
246246
if (r < 0) {
247247
ldpp_dout(dpp, 0) << "WARNING: register_watch_aio() returned " << r << dendl;
248248
error = r;
249249
continue;
250250
}
251251
}
252252

253-
for (int i = 0; i < num_watchers; ++i) {
254-
int r = watchers[i]->register_watch_finish();
253+
for (auto& watcher : watchers) {
254+
int r = watcher.register_watch_finish();
255255
if (r < 0) {
256256
ldpp_dout(dpp, 0) << "WARNING: async watch returned " << r << dendl;
257257
error = r;
@@ -268,13 +268,10 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y)
268268
void RGWSI_Notify::finalize_watch()
269269
{
270270
for (int i = 0; i < num_watchers; i++) {
271-
RGWWatcher *watcher = watchers[i];
272271
if (watchers_set.find(i) != watchers_set.end())
273-
watcher->unregister_watch();
274-
delete watcher;
272+
watchers[i].unregister_watch();
275273
}
276-
277-
delete[] watchers;
274+
watchers.clear();
278275
}
279276

280277
int RGWSI_Notify::do_start(optional_yield y, const DoutPrefixProvider *dpp)

src/rgw/services/svc_notify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RGWSI_Notify : public RGWServiceInstance
3535
rgw_pool control_pool;
3636

3737
int num_watchers{0};
38-
RGWWatcher **watchers{nullptr};
38+
std::vector<RGWWatcher> watchers;
3939
std::set<int> watchers_set;
4040
std::vector<rgw_rados_ref> notify_objs;
4141

@@ -84,7 +84,7 @@ class RGWSI_Notify : public RGWServiceInstance
8484

8585
void schedule_context(Context *c);
8686
public:
87-
RGWSI_Notify(CephContext *cct): RGWServiceInstance(cct) {}
87+
RGWSI_Notify(CephContext *cct);
8888

8989
virtual ~RGWSI_Notify() override;
9090

0 commit comments

Comments
 (0)