]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: renew resharding lock during bucket resharding
authorOrit Wasserman <owasserm@owasserm.redhat.com>
Fri, 21 Sep 2018 07:48:21 +0000 (10:48 +0300)
committerAbhishek Lekshmanan <abhishek@suse.com>
Thu, 29 Nov 2018 12:03:59 +0000 (13:03 +0100)
Signed-off-by: Orit Wasserman <owasserm@owasserm.redhat.com>
(cherry picked from commit 32d85970d4d635a31c35b48fb0fb62c2db11e40a)

src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index 7b311116338d1f0bdf6cdc5a477922c40b2a1bbe..76f5b76e659adb4d9bf4f825ce7858d9e8de2c8b 100644 (file)
@@ -192,7 +192,7 @@ public:
 
 RGWBucketReshard::RGWBucketReshard(RGWRados *_store, const RGWBucketInfo& _bucket_info, const map<string, bufferlist>& _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) {
index 6fe43129906f0fdd642d37594c3895a693a7d076..277dfc410ec34c3ebc773d3b4b7f67562f6e8843 100644 (file)
@@ -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();