]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: use vector for librados handles
authorCasey Bodley <cbodley@redhat.com>
Tue, 3 May 2016 14:35:41 +0000 (10:35 -0400)
committerAbhishek Lekshmanan <abhishek@suse.com>
Thu, 14 Jul 2016 08:06:28 +0000 (10:06 +0200)
using a vector instead of an array of pointers cleans up our
initialization/shutdown logic

Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit 02fb39d7f5835ada4d6304f318203444dc7eedc9)

src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index d10d37def25aef82710f6c04063965ee696b3bd1..c1468309a9d65e4135dd545ea00aae7fb338686d 100644 (file)
@@ -2521,7 +2521,7 @@ int RGWRados::unwatch(uint64_t watch_handle)
     ldout(cct, 0) << "ERROR: rados->unwatch2() returned r=" << r << dendl;
     return r;
   }
-  r = rados[0]->watch_flush();
+  r = rados[0].watch_flush();
   if (r < 0) {
     ldout(cct, 0) << "ERROR: rados->watch_flush() returned r=" << r << dendl;
     return r;
@@ -3171,58 +3171,32 @@ void RGWRados::finalize()
 int RGWRados::init_rados()
 {
   int ret = 0;
+  auto count = cct->_conf->rgw_num_rados_handles;
+  auto handles = std::vector<librados::Rados>{count};
 
-  num_rados_handles = cct->_conf->rgw_num_rados_handles;
-
-  rados = new librados::Rados *[num_rados_handles];
-  if (!rados) {
-    ret = -ENOMEM;
-    return ret;
-  }
-
-  for (uint32_t i=0; i < num_rados_handles; i++) {
-
-    rados[i] = new Rados();
-    if (!rados[i]) {
-      ret = -ENOMEM;
-      goto fail;
-    }
-
-    ret = rados[i]->init_with_context(cct);
+  for (auto& r : handles) {
+    ret = r.init_with_context(cct);
     if (ret < 0) {
-      goto fail;
+      return ret;
     }
 
-    ret = rados[i]->connect();
+    ret = r.connect();
     if (ret < 0) {
-      goto fail;
+      return ret;
     }
   }
 
   cr_registry = new RGWCoroutinesManagerRegistry(cct);
   ret =  cr_registry->hook_to_admin_command("cr dump");
   if (ret < 0) {
-    goto fail;
+    return ret;
   }
 
   meta_mgr = new RGWMetadataManager(cct, this);
   data_log = new RGWDataChangesLog(cct, this);
 
-  return ret;
-
-fail:
-  for (uint32_t i=0; i < num_rados_handles; i++) {
-    if (rados[i]) {
-      delete rados[i];
-      rados[i] = NULL;
-    }
-  }
-  num_rados_handles = 0;
-  if (rados) {
-    delete[] rados;
-    rados = NULL;
-  }
-
+  num_rados_handles = count;
+  std::swap(handles, rados);
   return ret;
 }
 
@@ -3965,7 +3939,7 @@ int RGWRados::init_watch()
 {
   const char *control_pool = get_zone_params().control_pool.name.c_str();
 
-  librados::Rados *rad = rados[0];
+  librados::Rados *rad = &rados[0];
   int r = rad->ioctx_create(control_pool, control_pool_ctx);
 
   if (r == -ENOENT) {
@@ -12089,7 +12063,7 @@ void RGWStoreManager::close_storage(RGWRados *store)
 librados::Rados* RGWRados::get_rados_handle()
 {
   if (num_rados_handles == 1) {
-    return rados[0];
+    return &rados[0];
   } else {
     handle_lock.get_read();
     pthread_t id = pthread_self();
@@ -12097,7 +12071,7 @@ librados::Rados* RGWRados::get_rados_handle()
 
     if (it != rados_map.end()) {
       handle_lock.put_read();
-      return rados[it->second];
+      return &rados[it->second];
     } else {
       handle_lock.put_read();
       handle_lock.get_write();
@@ -12109,7 +12083,7 @@ librados::Rados* RGWRados::get_rados_handle()
       rados_map[id] = handle;
       next_rados_handle.inc();
       handle_lock.put_write();
-      return rados[handle];
+      return &rados[handle];
     }
   }
 }
index af290cb44def01a5144df81ed10d450dea7ce4a9..03dd1daf06ae369257a22b7b9dfb23f9c1ba5605 100644 (file)
@@ -1800,7 +1800,7 @@ class RGWRados
 protected:
   CephContext *cct;
 
-  librados::Rados **rados;
+  std::vector<librados::Rados> rados;
   atomic_t next_rados_handle;
   uint32_t num_rados_handles;
   RWLock handle_lock;
@@ -1841,7 +1841,7 @@ public:
                bucket_id_lock("rados_bucket_id"),
                bucket_index_max_shards(0),
                max_bucket_id(0), cct(NULL),
-               rados(NULL), next_rados_handle(0),
+               next_rados_handle(0),
                num_rados_handles(0), handle_lock("rados_handle_lock"),
                binfo_cache(NULL),
                pools_initialized(false),
@@ -1956,17 +1956,7 @@ public:
 
   RGWDataChangesLog *data_log;
 
-  virtual ~RGWRados() {
-    for (uint32_t i=0; i < num_rados_handles; i++) {
-      if (rados[i]) {
-        rados[i]->shutdown();
-        delete rados[i];
-      }
-    }
-    if (rados) {
-      delete[] rados;
-    }
-  }
+  virtual ~RGWRados() = default;
 
   int get_required_alignment(rgw_bucket& bucket, uint64_t *alignment);
   int get_max_chunk_size(rgw_bucket& bucket, uint64_t *max_chunk_size);