]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/d4n: Use `unique_ptr` rather than bare new/delete 62736/head
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 8 Apr 2025 21:03:12 +0000 (17:03 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 11 Apr 2025 16:27:12 +0000 (12:27 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/driver/d4n/rgw_sal_d4n.cc
src/rgw/driver/d4n/rgw_sal_d4n.h

index 3b9ee0581b3dc664b61a757fbe06144253f1aa62..3903e81dfddceb16c03209a943bb94c4d4ae5b35 100644 (file)
@@ -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<rgw::cache::SSDDriver>(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<connection>(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<rgw::d4n::ObjectDirectory>(conn);
+  blockDir = std::make_unique<rgw::d4n::BlockDirectory>(conn);
+  policyDriver = std::make_unique<rgw::d4n::PolicyDriver>(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();
 }
index d6c1c85b8e8d6b57345a8d581397c01c12765abc..508bc3a604356e77a62fe41cc09bfc77e6245b78 100644 (file)
@@ -42,10 +42,10 @@ using boost::redis::connection;
 class D4NFilterDriver : public FilterDriver {
   private:
     std::shared_ptr<connection> conn;
-    rgw::cache::CacheDriver* cacheDriver;
-    rgw::d4n::ObjectDirectory* objDir;
-    rgw::d4n::BlockDirectory* blockDir;
-    rgw::d4n::PolicyDriver* policyDriver;
+    std::unique_ptr<rgw::cache::CacheDriver> cacheDriver;
+    std::unique_ptr<rgw::d4n::ObjectDirectory> objDir;
+    std::unique_ptr<rgw::d4n::BlockDirectory> blockDir;
+    std::unique_ptr<rgw::d4n::PolicyDriver> 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;
 };