]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: add RGWReshard::clear_bucket_resharding
authorOrit Wasserman <owasserm@redhat.com>
Mon, 10 Apr 2017 09:14:07 +0000 (12:14 +0300)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:17:31 +0000 (13:17 -0700)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index 5b382ec754d4b23159dc717a19dcfd469a6ccd33..bae28de06ba208fd3e5e756dcd70180ada87beb7 100644 (file)
@@ -12,6 +12,7 @@
 
 const string reshard_oid = "reshard";
 const string reshard_lock_name = "reshard_process";
+const string bucket_instance_lock_name = "bucket_instance_lock";
 
 RGWReshard::RGWReshard(CephContext *_cct, RGWRados* _store):cct(_cct), store(_store)
 {
@@ -217,4 +218,53 @@ done:
   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);
+  if (ret == -EBUSY) {
+    dout(0) << "RGWReshardLog::add failed to acquire lock on " << reshard_oid << dendl;
+    return 0;
+  }
+  if (ret < 0)
+    return ret;
+
+  entry.new_instance_id.clear();
+
+  RGWBucketInfo bucket_info;
+  map<string, bufferlist> attrs;
+  RGWObjectCtx obj_ctx(store);
+
+  ret = store->get_bucket_info(obj_ctx, entry.tenant, entry.bucket_name, bucket_info, nullptr, &attrs);
+  if (ret < 0) {
+    ldout(cct, 0) << "RGWReshard::" << __func__ << " ERROR: could not init bucket: " << cpp_strerror(-ret)
+                 << dendl;
+    return ret;
+  }
+
+  bucket_info.resharding = false;
+  bucket_info.new_bucket_instance_id.clear();
+  cls_rgw_bucket_instance_entry instance_entry;
+
+  try {
+    ::encode(bucket_info, instance_entry.data);
+  } 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);
+    return -EIO;
+  }
+
+  ret =   cls_rgw_clear_bucket_resharding(io_ctx, bucket_instance_oid, instance_entry);
+
+  l.unlock(&io_ctx, bucket_instance_oid);
+  return ret;
+}
+
 
index 4b0b32354a2bd24c342557ed8678eb6eacddfdab..9a71e3078876902345a8ba52c7603ff5aaa6ebbe 100644 (file)
@@ -26,6 +26,8 @@ class RGWReshard {
     int remove(cls_rgw_reshard_entry& entry);
     int list(string& marker, uint32_t max, list<cls_rgw_reshard_entry>& entries, bool& is_truncated);
     int set_bucket_resharding(const string& bucket_instance_oid, cls_rgw_reshard_entry& entry);
+    int clear_bucket_resharding(const string& bucket_instance_oid, cls_rgw_reshard_entry& entry);
+    int get_bucket_instance_info(const rgw_bucket& bucket, RGWBucketInfo& bucket_info);
 };
 
 #endif