]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add reshard_pool_ctx
authorOrit Wasserman <owasserm@redhat.com>
Mon, 1 May 2017 06:23:34 +0000 (09:23 +0300)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:38 +0000 (13:17 -0700)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index 708f37a154dab93e5ef00f2f7ee41196032805f2..4b0774eebbd7c283685fb9f2930b75a35e2cdf5a 100644 (file)
@@ -4162,6 +4162,10 @@ int RGWRados::init_complete()
   if (ret < 0)
     return ret;
 
+  ret = open_reshard_pool_ctx();
+  if (ret < 0)
+    return ret;
+
   pools_initialized = true;
 
   gc = new RGWGC();
@@ -4414,6 +4418,11 @@ int RGWRados::open_objexp_pool_ctx()
   return rgw_init_ioctx(get_rados_handle(), get_zone_params().log_pool, objexp_pool_ctx, true);
 }
 
+int RGWRados::open_reshard_pool_ctx()
+{
+  return rgw_init_ioctx(get_rados_handle(), get_zone_params().reshard_pool, reshard_pool_ctx, true);
+}
+
 int RGWRados::init_watch()
 {
   int r = rgw_init_ioctx(&rados[0], get_zone_params().control_pool, control_pool_ctx, true);
index 4b50699d8612075db73bb843f406b9c2a89e6f32..0f1e990a21c6d16866a1d7fbd2e01525a80fe7ff 100644 (file)
@@ -2180,12 +2180,14 @@ class RGWRados
   friend class RGWDataSyncProcessorThread;
   friend class RGWStateLog;
   friend class RGWReplicaLogger;
+  friend class RGWReshard;
 
   /** Open the pool used as root for this gateway */
   int open_root_pool_ctx();
   int open_gc_pool_ctx();
   int open_lc_pool_ctx();
   int open_objexp_pool_ctx();
+  int open_reshard_pool_ctx();
 
   int open_pool_ctx(const rgw_pool& pool, librados::IoCtx&  io_ctx);
   int open_bucket_index_ctx(const RGWBucketInfo& bucket_info, librados::IoCtx& index_ctx);
@@ -2282,6 +2284,7 @@ protected:
   librados::IoCtx gc_pool_ctx;        // .rgw.gc
   librados::IoCtx lc_pool_ctx;        // .rgw.lc
   librados::IoCtx objexp_pool_ctx;
+  librados::IoCtx reshard_pool_ctx;
 
   bool pools_initialized;
 
index 9564dda786b016022130dd09e7044994a1fe996d..896d9b46205234e0dcd6a00efcbbaae6348b3abc 100644 (file)
@@ -20,35 +20,12 @@ RGWReshard::RGWReshard(CephContext *_cct, RGWRados* _store):cct(_cct), store(_st
     max_jobs = cct->_conf->rgw_reshard_max_jobs;
 }
 
-int RGWReshard::get_io_ctx(librados::IoCtx& io_ctx)
-{
-  string reshard_pool = store->get_zone_params().reshard_pool.name;
-  librados::Rados *rad = store->get_rados_handle();
-  int r = rad->ioctx_create(reshard_pool.c_str(), io_ctx);
-  if (r == -ENOENT) {
-    r = store->create_pool(store->get_zone_params().reshard_pool);
-    if (r < 0)
-      return r;
-
-    // retry
-    r = rad->ioctx_create(reshard_pool.c_str(), io_ctx);
-  }
-  if (r < 0)
-    return r;
-
-  return 0;
-}
 
 int RGWReshard::add(cls_rgw_reshard_entry& entry)
 {
   rados::cls::lock::Lock l(reshard_lock_name);
-  librados::IoCtx io_ctx;
-
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
 
-  ret = l.lock_exclusive(&io_ctx, reshard_oid);
+  int ret = l.lock_exclusive(&store->reshard_pool_ctx, reshard_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshard::add failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -59,9 +36,9 @@ int RGWReshard::add(cls_rgw_reshard_entry& entry)
   librados::ObjectWriteOperation op;
   cls_rgw_reshard_add(op, entry);
 
-  ret = io_ctx.operate(reshard_oid, &op);
+  ret = store->reshard_pool_ctx.operate(reshard_oid, &op);
 
-  l.unlock(&io_ctx, reshard_oid);
+  l.unlock(&store->reshard_pool_ctx, reshard_oid);
   return ret;
 }
 
@@ -69,13 +46,8 @@ int RGWReshard::add(cls_rgw_reshard_entry& entry)
 int RGWReshard::list(string& marker, uint32_t max, std::list<cls_rgw_reshard_entry>& entries, bool& is_truncated)
 {
   rados::cls::lock::Lock l(reshard_lock_name);
-  librados::IoCtx io_ctx;
-
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
 
-  ret = l.lock_shared(&io_ctx, reshard_oid);
+  int ret = l.lock_shared(&store->reshard_pool_ctx, reshard_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshard::list failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -83,22 +55,17 @@ int RGWReshard::list(string& marker, uint32_t max, std::list<cls_rgw_reshard_ent
   if (ret < 0)
     return ret;
 
-  ret =  cls_rgw_reshard_list(io_ctx, reshard_oid, marker, max, entries, &is_truncated);
+  ret =  cls_rgw_reshard_list(store->reshard_pool_ctx, reshard_oid, marker, max, entries, &is_truncated);
 
-  l.unlock(&io_ctx, reshard_oid);
+  l.unlock(&store->reshard_pool_ctx, reshard_oid);
   return ret;
 }
 
 int RGWReshard::get(cls_rgw_reshard_entry& entry)
 {
   rados::cls::lock::Lock l(reshard_lock_name);
-  librados::IoCtx io_ctx;
-
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
 
-  ret = l.lock_shared(&io_ctx, reshard_oid);
+  int ret = l.lock_shared(&store->reshard_pool_ctx, reshard_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshardLog::get failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -106,22 +73,17 @@ int RGWReshard::get(cls_rgw_reshard_entry& entry)
   if (ret < 0)
     return ret;
 
-  ret = cls_rgw_reshard_get(io_ctx, reshard_oid, entry);
+  ret = cls_rgw_reshard_get(store->reshard_pool_ctx, reshard_oid, entry);
 
-  l.unlock(&io_ctx, reshard_oid);
+  l.unlock(&store->reshard_pool_ctx, reshard_oid);
   return ret;
 }
 
 int RGWReshard::remove(cls_rgw_reshard_entry& entry)
 {
   rados::cls::lock::Lock l(reshard_lock_name);
-  librados::IoCtx io_ctx;
 
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
-
-  ret = l.lock_exclusive(&io_ctx, reshard_oid);
+  int ret = l.lock_exclusive(&store->reshard_pool_ctx, reshard_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshardLog::remove failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -132,27 +94,22 @@ int RGWReshard::remove(cls_rgw_reshard_entry& entry)
   librados::ObjectWriteOperation op;
   cls_rgw_reshard_remove(op, entry);
 
-  ret =  io_ctx.operate(reshard_oid, &op);
+  ret =  store->reshard_pool_ctx.operate(reshard_oid, &op);
 
-  l.unlock(&io_ctx, reshard_oid);
+  l.unlock(&store->reshard_pool_ctx, reshard_oid);
   return ret;
 }
 
 int RGWReshard::set_bucket_resharding(const string& bucket_instance_oid, cls_rgw_reshard_entry& entry)
 {
   rados::cls::lock::Lock l(reshard_lock_name);
-  librados::IoCtx io_ctx;
-
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
 
   if (entry.new_instance_id.empty()) {
     ldout(cct, 0) << "RGWReshard::" << __func__ << " missing new bucket instance id" << dendl;
     return -EEXIST;
   }
 
-  ret = l.lock_exclusive(&io_ctx, bucket_instance_oid);
+  int ret = l.lock_exclusive(&store->reshard_pool_ctx, bucket_instance_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshardLog::add failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -185,27 +142,22 @@ int RGWReshard::set_bucket_resharding(const string& bucket_instance_oid, cls_rgw
     goto done;
   }
 
-  ret =   cls_rgw_set_bucket_resharding(io_ctx, bucket_instance_oid, instance_entry);
+  ret =   cls_rgw_set_bucket_resharding(store->reshard_pool_ctx, bucket_instance_oid, instance_entry);
   if (ret < 0) {
     ldout(cct, 0) << "RGWReshard::" << __func__ << " ERROR: cls_rgw_set_bucket_reshardind: "
                  << cpp_strerror(-ret) << dendl;
     goto done;
   }
 done:
-  l.unlock(&io_ctx, bucket_instance_oid);
+  l.unlock(&store->reshard_pool_ctx, bucket_instance_oid);
   return ret;
 }
 
 int RGWReshard::clear_bucket_resharding(const string& bucket_instance_oid, cls_rgw_reshard_entry& entry)
 {
   rados::cls::lock::Lock l(bucket_instance_lock_name);
-  librados::IoCtx io_ctx;
-
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
 
-  ret = l.lock_exclusive(&io_ctx, bucket_instance_oid);
+  int ret = l.lock_exclusive(&store->reshard_pool_ctx, bucket_instance_oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshardLog::add failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -235,23 +187,19 @@ int RGWReshard::clear_bucket_resharding(const string& bucket_instance_oid, cls_r
   } catch(buffer::error& err) {
     ldout(cct, 0) << "RGWReshard::" << __func__ << " ERROR: could not decode buffer info, caught buffer::error"
                  << dendl;
-    l.unlock(&io_ctx, bucket_instance_oid);
+    l.unlock(&store->reshard_pool_ctx, bucket_instance_oid);
     return -EIO;
   }
 
-  ret =   cls_rgw_clear_bucket_resharding(io_ctx, bucket_instance_oid, instance_entry);
+  ret =   cls_rgw_clear_bucket_resharding(store->reshard_pool_ctx, bucket_instance_oid, instance_entry);
 
-  l.unlock(&io_ctx, bucket_instance_oid);
+  l.unlock(&store->reshard_pool_ctx, bucket_instance_oid);
   return ret;
 }
 
 int RGWReshard::lock_bucket_index_shared(const string& oid)
 {
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
-
-  ret = instance_lock.lock_shared(&io_ctx, oid);
+  int ret = instance_lock.lock_shared(&store->reshard_pool_ctx, oid);
   if (ret == -EBUSY) {
     ldout(cct, 0) << "RGWReshardLog::add failed to acquire lock on " << reshard_oid << dendl;
     return 0;
@@ -262,10 +210,7 @@ int RGWReshard::lock_bucket_index_shared(const string& oid)
 
 int RGWReshard::unlock_bucket_index(const string& oid)
 {
-  int ret = get_io_ctx(io_ctx);
-  if (ret < 0)
-    return ret;
-  instance_lock.unlock(&io_ctx, oid);
+  instance_lock.unlock(&store->reshard_pool_ctx, oid);
   return 0;
 }
 
@@ -285,7 +230,7 @@ int RGWReshard::block_while_resharding(const string& bucket_instance_oid)
       return ret;
     }
 
-    ret = cls_rgw_get_bucket_resharding(io_ctx, bucket_instance_oid,
+    ret = cls_rgw_get_bucket_resharding(store->reshard_pool_ctx, bucket_instance_oid,
                                        entry, resharding);
     if (ret < 0 && ret != -ENOENT && ret != -ENODATA) {
       ldout(cct, 0) << "RGWReshard::" << __func__ << " ERROR: failed to get bucket resharding :"  <<
index c2436acfbc1f18c445b8769b075b2221739c535a..8ddb91109c02d0a04b95f44302a23de67d4acc15 100644 (file)
 class CephContext;
 class RGWRados;
 
+#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_rgw
+
 class RGWReshard {
     CephContext *cct;
     RGWRados *store;
     string lock_name;
     int max_jobs;
     rados::cls::lock::Lock instance_lock;
-    librados::IoCtx io_ctx;
-
-    int get_io_ctx(librados::IoCtx& io_ctx);
 
   public:
     RGWReshard(CephContext* cct, RGWRados* _store);