From 072054711a1d6b71bc01cd1aa366f7cb44dc20e3 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Fri, 21 Sep 2018 10:48:21 +0300 Subject: [PATCH] rgw: renew resharding lock during bucket resharding Signed-off-by: Orit Wasserman (cherry picked from commit 32d85970d4d635a31c35b48fb0fb62c2db11e40a) --- src/rgw/rgw_reshard.cc | 37 ++++++++++++++++++++++++++++++++++++- src/rgw/rgw_reshard.h | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 7b311116338d1..76f5b76e659ad 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -192,7 +192,7 @@ public: RGWBucketReshard::RGWBucketReshard(RGWRados *_store, const RGWBucketInfo& _bucket_info, const map& _bucket_attrs) : store(_store), bucket_info(_bucket_info), bucket_attrs(_bucket_attrs), - reshard_lock(reshard_lock_name) { + reshard_lock(reshard_lock_name), locked_bucket(false) { const rgw_bucket& b = bucket_info.bucket; reshard_oid = b.tenant + (b.tenant.empty() ? "" : ":") + b.name + ":" + b.bucket_id; @@ -213,6 +213,8 @@ int RGWBucketReshard::lock_bucket() ldout(store->ctx(), 0) << "RGWReshard::add failed to acquire lock on " << reshard_oid << " ret=" << ret << dendl; return ret; } + lock_start_time = ceph_clock_now(); + locked_bucket = true; return 0; } @@ -222,6 +224,28 @@ void RGWBucketReshard::unlock_bucket() if (ret < 0) { ldout(store->ctx(), 0) << "WARNING: RGWReshard::add failed to drop lock on " << reshard_oid << " ret=" << ret << dendl; } + locked_bucket = false; +} + + +int RGWBucketReshard::renew_lock_bucket() +{ + if (!locked_bucket) { + return 0; + } + + utime_t now = ceph_clock_now(); + /* do you need to renew lock? */ + if (now > lock_start_time + store->ctx()->_conf->rgw_reshard_bucket_lock_duration/ 2) { + reshard_lock.set_renew(true); + int ret = reshard_lock.lock_exclusive(&store->reshard_pool_ctx, reshard_oid); + if (ret == -EBUSY) { /* already locked by another processor */ + ldout(store->ctx(), 5) << __func__ << "(): failed to acquire lock on " << reshard_oid << dendl; + return ret; + } + lock_start_time = now; + } + return 0; } int RGWBucketReshard::set_resharding_status(const string& new_instance_id, int32_t num_shards, cls_rgw_reshard_status status) @@ -467,8 +491,19 @@ int RGWBucketReshard::do_reshard( (*out) << " " << total_entries; } } + ret = renew_lock_bucket(); + if (ret < 0) { + lderr(store->ctx()) << "Error renewing bucket lock: " << ret << dendl; + return -ret; + } + ret = renew_lock_bucket(); + if (ret < 0) { + lderr(store->ctx()) << "Error renewing bucket lock: " << ret << dendl; + return -ret; + } } } + if (verbose) { formatter->close_section(); if (out) { diff --git a/src/rgw/rgw_reshard.h b/src/rgw/rgw_reshard.h index 6fe43129906f0..277dfc410ec34 100644 --- a/src/rgw/rgw_reshard.h +++ b/src/rgw/rgw_reshard.h @@ -23,9 +23,12 @@ class RGWBucketReshard { string reshard_oid; rados::cls::lock::Lock reshard_lock; + utime_t lock_start_time; + bool locked_bucket; int lock_bucket(); void unlock_bucket(); + int renew_lock_bucket(); int set_resharding_status(const string& new_instance_id, int32_t num_shards, cls_rgw_reshard_status status); int clear_resharding(); -- 2.39.5