From: Orit Wasserman Date: Mon, 10 Apr 2017 09:14:07 +0000 (+0300) Subject: rgw: add RGWReshard::clear_bucket_resharding X-Git-Tag: ses5-milestone6~8^2~7^2~87 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b497b06d7bafa13fef20bbe3f81e7cd790201c2;p=ceph.git rgw: add RGWReshard::clear_bucket_resharding Signed-off-by: Orit Wasserman --- diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 5b382ec754d..bae28de06ba 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -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 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; +} + diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index 4b0b32354a2..9a71e307887 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -26,6 +26,8 @@ class RGWReshard { int remove(cls_rgw_reshard_entry& entry); int list(string& marker, uint32_t max, list& 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