]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: use unique_ptr<> to manage lifecycle of Monitor::paxos
authorKefu Chai <kchai@redhat.com>
Sat, 28 Nov 2020 09:09:12 +0000 (17:09 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 6 Dec 2020 11:35:47 +0000 (19:35 +0800)
it is less error-prone, and has better readability.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc

index 66d3a190efbf217d51e7c875e41140dbcf4a5fd2..ba6ab1ebe78e740c2135bbb6613d008ae44166ca 100644 (file)
@@ -238,19 +238,19 @@ Monitor::Monitor(CephContext* cct_, string nm, MonitorDBStore *s,
       g_conf().get_val<uint64_t>("mon_op_history_slow_op_size"),
       g_conf().get_val<std::chrono::seconds>("mon_op_history_slow_op_threshold").count());
 
-  paxos = new Paxos(this, "paxos");
+  paxos = std::make_unique<Paxos>(this, "paxos");
 
-  paxos_service[PAXOS_MDSMAP].reset(new MDSMonitor(this, paxos, "mdsmap"));
-  paxos_service[PAXOS_MONMAP].reset(new MonmapMonitor(this, paxos, "monmap"));
-  paxos_service[PAXOS_OSDMAP].reset(new OSDMonitor(cct, this, paxos, "osdmap"));
-  paxos_service[PAXOS_LOG].reset(new LogMonitor(this, paxos, "logm"));
-  paxos_service[PAXOS_AUTH].reset(new AuthMonitor(this, paxos, "auth"));
-  paxos_service[PAXOS_MGR].reset(new MgrMonitor(this, paxos, "mgr"));
-  paxos_service[PAXOS_MGRSTAT].reset(new MgrStatMonitor(this, paxos, "mgrstat"));
-  paxos_service[PAXOS_HEALTH].reset(new HealthMonitor(this, paxos, "health"));
-  paxos_service[PAXOS_CONFIG].reset(new ConfigMonitor(this, paxos, "config"));
+  paxos_service[PAXOS_MDSMAP].reset(new MDSMonitor(this, paxos.get(), "mdsmap"));
+  paxos_service[PAXOS_MONMAP].reset(new MonmapMonitor(this, paxos.get(), "monmap"));
+  paxos_service[PAXOS_OSDMAP].reset(new OSDMonitor(cct, this, paxos.get(), "osdmap"));
+  paxos_service[PAXOS_LOG].reset(new LogMonitor(this, paxos.get(), "logm"));
+  paxos_service[PAXOS_AUTH].reset(new AuthMonitor(this, paxos.get(), "auth"));
+  paxos_service[PAXOS_MGR].reset(new MgrMonitor(this, paxos.get(), "mgr"));
+  paxos_service[PAXOS_MGRSTAT].reset(new MgrStatMonitor(this, paxos.get(), "mgrstat"));
+  paxos_service[PAXOS_HEALTH].reset(new HealthMonitor(this, paxos.get(), "health"));
+  paxos_service[PAXOS_CONFIG].reset(new ConfigMonitor(this, paxos.get(), "config"));
 
-  config_key_service = new ConfigKeyService(this, paxos);
+  config_key_service = std::make_unique<ConfigKeyService>(this, paxos.get());
 
   bool r = mon_caps.parse("allow *", NULL);
   ceph_assert(r);
@@ -285,8 +285,6 @@ Monitor::~Monitor()
 {
   op_tracker.on_shutdown();
 
-  delete config_key_service;
-  delete paxos;
   delete logger;
   ceph_assert(session_map.sessions.empty());
 }
@@ -1370,7 +1368,7 @@ set<string> Monitor::get_sync_targets_names()
   for (auto& svc : paxos_service) {
     svc->get_store_prefixes(targets);
   }
-  ConfigKeyService *config_key_service_ptr = dynamic_cast<ConfigKeyService*>(config_key_service);
+  auto config_key_service_ptr = dynamic_cast<ConfigKeyService*>(config_key_service.get());
   ceph_assert(config_key_service_ptr);
   config_key_service_ptr->get_store_prefixes(targets);
   return targets;
index 936af1ee91d4504d888ed71f34453b9b4bcfdec4..cf1f9867bde2912fee83c3f9584afec53c2fe124 100644 (file)
@@ -218,7 +218,7 @@ public:
 
   // -- elector --
 private:
-  Paxos *paxos;
+  std::unique_ptr<Paxos> paxos;
   Elector elector;
   friend class Elector;
 
@@ -684,7 +684,7 @@ public:
   friend class LogMonitor;
   friend class ConfigKeyService;
 
-  QuorumService *config_key_service;
+  std::unique_ptr<QuorumService> config_key_service;
 
   // -- sessions --
   MonSessionMap session_map;
index 1ab9957cd84eec55e1c4aa46341d54872299393a..ebc82e669a9586b19e9cc69aa37923fa375544f2 100644 (file)
@@ -9409,7 +9409,7 @@ int OSDMonitor::prepare_command_osd_new(
     }
 
     if (has_lockbox) {
-      svc = (ConfigKeyService*)mon->config_key_service;
+      svc = (ConfigKeyService*)(mon->config_key_service.get());
       err = svc->validate_osd_new(uuid, dmcrypt_key, ss);
       if (err < 0) {
         return err;
@@ -9594,7 +9594,7 @@ int OSDMonitor::prepare_command_osd_destroy(
     }
   }
 
-  ConfigKeyService *svc = (ConfigKeyService*)mon->config_key_service;
+  auto svc = (ConfigKeyService*)(mon->config_key_service.get());
   err = svc->validate_osd_destroy(id, uuid);
   if (err < 0) {
     ceph_assert(err == -ENOENT);