]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: new num shards proportional to number of objects per shard
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 1 Jun 2017 23:55:35 +0000 (16:55 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 5 Jun 2017 20:18:03 +0000 (13:18 -0700)
and also limit number of shards to not exceed the max.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_quota.cc
src/rgw/rgw_quota.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 212ec4ba9dd3415248ecea940f3f06c2f0838e54..2a1307a1f1a2db853cccf3b09ed5e72351ece5b3 100644 (file)
@@ -942,7 +942,7 @@ public:
 
   int check_bucket_shards(uint64_t max_objs_per_shard, uint64_t num_shards,
                          const rgw_user& user, rgw_bucket& bucket, RGWQuotaInfo& bucket_quota,
-                         uint64_t num_objs, bool& need_resharding)
+                         uint64_t num_objs, bool& need_resharding, uint32_t *suggested_num_shards)
   {
     RGWStorageStats bucket_stats;
     int ret = bucket_stats_cache.get_stats(user, bucket, bucket_stats,
@@ -955,6 +955,9 @@ public:
       ldout(store->ctx(), 0) << __func__ << ": resharding needed: stats.num_objects=" << bucket_stats.num_objects
              << " shard max_objects=" <<  max_objs_per_shard * num_shards << dendl;
       need_resharding = true;
+      if (suggested_num_shards) {
+        *suggested_num_shards = (bucket_stats.num_objects  + num_objs) * 2 / max_objs_per_shard;
+      }
     } else {
       need_resharding = false;
     }
index b542c603eea2cfcf82d28368da73d6312b07e1f8..fd2d227fba0c8c68edf0148f819d4d977bf9cece 100644 (file)
@@ -105,7 +105,8 @@ public:
 
   virtual int check_bucket_shards(uint64_t max_objs_per_shard, uint64_t num_shards,
                                  const rgw_user& bucket_owner, rgw_bucket& bucket,
-                                 RGWQuotaInfo& bucket_quota, uint64_t num_objs, bool& need_resharding) = 0;
+                                 RGWQuotaInfo& bucket_quota, uint64_t num_objs, bool& need_resharding,
+                                  uint32_t *suggested_num_shards) = 0;
 
   virtual void update_stats(const rgw_user& bucket_owner, rgw_bucket& bucket, int obj_delta, uint64_t added_bytes, uint64_t removed_bytes) = 0;
 
index 75e4fe05832db39aef7258c3812a1d097a9c2fcc..abc77f30ff11be67baa34c2171be83af759c2000 100644 (file)
@@ -13113,26 +13113,33 @@ int RGWRados::check_bucket_shards(const RGWBucketInfo& bucket_info, rgw_bucket&
 
   bool need_resharding = false;
   int num_source_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1);
+  uint32_t suggested_num_shards;
 
   int ret =  quota_handler->check_bucket_shards((uint64_t)cct->_conf->rgw_max_objs_per_shard,
                                                num_source_shards,  bucket_info.owner, bucket, bucket_quota,
-                                               1, need_resharding);
+                                               1, need_resharding, &suggested_num_shards);
   if (ret < 0) {
     return ret;
   }
 
   if (need_resharding) {
-    return add_bucket_to_reshard(bucket_info);
+    return add_bucket_to_reshard(bucket_info, suggested_num_shards);
   }
 
   return ret;
 }
 
-int RGWRados::add_bucket_to_reshard(const RGWBucketInfo& bucket_info)
+int RGWRados::add_bucket_to_reshard(const RGWBucketInfo& bucket_info, uint32_t new_num_shards)
 {
   RGWReshard reshard(this);
 
-  int num_source_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1);
+  uint32_t num_source_shards = (bucket_info.num_shards > 0 ? bucket_info.num_shards : 1);
+
+  new_num_shards = min(new_num_shards, get_max_bucket_shards());
+  if (new_num_shards <= num_source_shards) {
+    ldout(cct, 20) << "not resharding bucket name=" << bucket_info.bucket.name << ", orig_num=" << num_source_shards << ", new_num_shards=" << new_num_shards << dendl;
+    return 0;
+  }
 
   cls_rgw_reshard_entry entry;
   entry.time = real_clock::now();
@@ -13140,7 +13147,7 @@ int RGWRados::add_bucket_to_reshard(const RGWBucketInfo& bucket_info)
   entry.bucket_name = bucket_info.bucket.name;
   entry.bucket_id = bucket_info.bucket.bucket_id;
   entry.old_num_shards = num_source_shards;
-  entry.new_num_shards = num_source_shards << 1;
+  entry.new_num_shards = new_num_shards;
 
   return reshard.add(entry);
 }
index 9d1a1c7de38a00e84a8c94a392ad16a3f8c3f60f..ce8eac5108865c7468ca50b125c65ab6a375d363 100644 (file)
@@ -3487,7 +3487,7 @@ public:
   int check_bucket_shards(const RGWBucketInfo& bucket_info, rgw_bucket& bucket,
                          RGWQuotaInfo& bucket_quota);
 
-  int add_bucket_to_reshard(const RGWBucketInfo& bucket_info);
+  int add_bucket_to_reshard(const RGWBucketInfo& bucket_info, uint32_t new_num_shards);
 
   uint64_t instance_id();
   const string& zone_id() {