From: Adam C. Emerson Date: Tue, 8 Apr 2025 21:03:12 +0000 (-0400) Subject: rgw/d4n: Use `unique_ptr` rather than bare new/delete X-Git-Tag: v20.3.0~64^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=222965bfb8b604a0215e8a7fe342d4e02d9f491c;p=ceph.git rgw/d4n: Use `unique_ptr` rather than bare new/delete Signed-off-by: Adam C. Emerson --- diff --git a/src/rgw/driver/d4n/rgw_sal_d4n.cc b/src/rgw/driver/d4n/rgw_sal_d4n.cc index 3b9ee0581b3dc..3903e81dfddce 100644 --- a/src/rgw/driver/d4n/rgw_sal_d4n.cc +++ b/src/rgw/driver/d4n/rgw_sal_d4n.cc @@ -41,7 +41,7 @@ D4NFilterDriver::D4NFilterDriver(Driver* _next, boost::asio::io_context& io_cont partition_info.name = "d4n"; partition_info.type = "read-cache"; partition_info.size = g_conf()->rgw_d4n_l1_datacache_size; - cacheDriver = new rgw::cache::SSDDriver(partition_info); + cacheDriver = std::make_unique(partition_info); } D4NFilterDriver::~D4NFilterDriver() = default; @@ -52,9 +52,11 @@ int D4NFilterDriver::initialize(CephContext *cct, const DoutPrefixProvider *dpp) using boost::redis::config; conn = std::make_shared(boost::asio::make_strand(io_context)); - objDir = new rgw::d4n::ObjectDirectory(conn); - blockDir = new rgw::d4n::BlockDirectory(conn); - policyDriver = new rgw::d4n::PolicyDriver(conn, cacheDriver, "lfuda"); + objDir = std::make_unique(conn); + blockDir = std::make_unique(conn); + policyDriver = std::make_unique(conn, + cacheDriver.get(), + "lfuda"); std::string address = cct->_conf->rgw_d4n_address; config cfg; @@ -255,10 +257,10 @@ void D4NFilterDriver::shutdown() // call cancel() on the connection's executor boost::asio::dispatch(conn->get_executor(), [c = conn] { c->cancel(); }); - delete cacheDriver; - delete objDir; - delete blockDir; - delete policyDriver; + cacheDriver.reset(); + objDir.reset(); + blockDir.reset(); + policyDriver.reset(); next->shutdown(); } diff --git a/src/rgw/driver/d4n/rgw_sal_d4n.h b/src/rgw/driver/d4n/rgw_sal_d4n.h index d6c1c85b8e8d6..508bc3a604356 100644 --- a/src/rgw/driver/d4n/rgw_sal_d4n.h +++ b/src/rgw/driver/d4n/rgw_sal_d4n.h @@ -42,10 +42,10 @@ using boost::redis::connection; class D4NFilterDriver : public FilterDriver { private: std::shared_ptr conn; - rgw::cache::CacheDriver* cacheDriver; - rgw::d4n::ObjectDirectory* objDir; - rgw::d4n::BlockDirectory* blockDir; - rgw::d4n::PolicyDriver* policyDriver; + std::unique_ptr cacheDriver; + std::unique_ptr objDir; + std::unique_ptr blockDir; + std::unique_ptr policyDriver; boost::asio::io_context& io_context; public: @@ -64,10 +64,12 @@ class D4NFilterDriver : public FilterDriver { const rgw_placement_rule *ptail_placement_rule, uint64_t olh_epoch, const std::string& unique_tag) override; - rgw::cache::CacheDriver* get_cache_driver() { return cacheDriver; } - rgw::d4n::ObjectDirectory* get_obj_dir() { return objDir; } - rgw::d4n::BlockDirectory* get_block_dir() { return blockDir; } - rgw::d4n::PolicyDriver* get_policy_driver() { return policyDriver; } + rgw::cache::CacheDriver* get_cache_driver() { return cacheDriver.get(); } + + + rgw::d4n::ObjectDirectory* get_obj_dir() { return objDir.get(); } + rgw::d4n::BlockDirectory* get_block_dir() { return blockDir.get(); } + rgw::d4n::PolicyDriver* get_policy_driver() { return policyDriver.get(); } void shutdown() override; };