]> git.apps.os.sepia.ceph.com Git - ceph-ci.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)
committerJ. Eric Ivancich <ivancich@redhat.com>
Wed, 24 Oct 2018 17:00:39 +0000 (13:00 -0400)
Signed-off-by: Orit Wasserman <owasserm@owasserm.redhat.com>
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index c95ab7e4728b251535665b2d3c8dde0fa406c0c7..a3f37934e3624b84509fbd9dc5fac183cffe1574 100644 (file)
@@ -191,7 +191,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;
 
@@ -212,6 +212,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;
 }
 
@@ -221,6 +223,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)
@@ -466,8 +490,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 c6e56e14fca3196d413f2cb57aaef7b9a3a7af8a..1c26b6a062440cb5d8794e6e3a24d4d67d9d1393 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();