@@ -69,23 +69,13 @@ const std::initializer_list<uint16_t> RGWBucketReshard::reshard_primes = {
6969};
7070
7171
72- uint32_t RGWBucketReshard::get_prime_shard_count (
73- uint32_t shard_count,
74- uint32_t max_dynamic_shards,
75- uint32_t min_dynamic_shards)
76- {
72+ uint32_t RGWBucketReshard::nearest_prime (uint32_t shard_count) {
7773 uint32_t prime_shard_count =
7874 get_prime_shards_greater_or_equal (shard_count);
7975
8076 // if we cannot find a larger prime number, then just use what was
8177 // passed in
82- if (! prime_shard_count) {
83- prime_shard_count = shard_count;
84- }
85-
86- // keep within min/max bounds
87- return std::min (max_dynamic_shards,
88- std::max (min_dynamic_shards, prime_shard_count));
78+ return prime_shard_count ? prime_shard_count : shard_count;
8979}
9080
9181
@@ -96,6 +86,7 @@ uint32_t RGWBucketReshard::get_prime_shard_count(
9686void RGWBucketReshard::calculate_preferred_shards (
9787 const DoutPrefixProvider* dpp,
9888 const uint32_t max_dynamic_shards,
89+ const uint32_t min_layout_shards,
9990 const uint64_t max_objs_per_shard,
10091 const bool is_multisite,
10192 const uint64_t num_objs,
@@ -139,10 +130,13 @@ void RGWBucketReshard::calculate_preferred_shards(
139130 }
140131
141132 if (prefer_prime) {
142- calculated_num_shards = get_prime_shard_count (
143- calculated_num_shards, max_dynamic_shards, min_dynamic_shards);
133+ calculated_num_shards = nearest_prime (calculated_num_shards);
144134 }
145135
136+ calculated_num_shards =
137+ std::min (max_dynamic_shards,
138+ std::max ({ calculated_num_shards, min_dynamic_shards, min_layout_shards }));
139+
146140 ldpp_dout (dpp, 20 ) << __func__ << " : reshard " << verb <<
147141 " suggested; current average (objects/shard) is " <<
148142 float (num_objs) / current_num_shards << " , which is not within " <<
@@ -461,6 +455,7 @@ static int init_target_layout(rgw::sal::RadosStore* store,
461455 rgw::bucket_index_layout_generation target;
462456 target.layout .type = rgw::BucketIndexType::Normal;
463457 target.layout .normal .num_shards = new_num_shards;
458+ target.layout .normal .min_num_shards = current.layout .normal .min_num_shards ;
464459 target.gen = current.gen + 1 ;
465460
466461 if (bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS) {
@@ -1256,7 +1251,7 @@ int RGWBucketReshard::do_reshard(const rgw::bucket_index_layout_generation& curr
12561251 // block the client op and complete the resharding
12571252 ceph_assert (bucket_info.layout .resharding == rgw::BucketReshardState::InProgress);
12581253 ret = reshard_process (current, max_op_entries, target_shards_mgr, verbose_json_out, out,
1259- formatter, bucket_info.layout .resharding , dpp, y);
1254+ formatter, bucket_info.layout .resharding , dpp, y);
12601255 if (ret < 0 ) {
12611256 ldpp_dout (dpp, 0 ) << __func__ << " : failed in progress state of reshard ret = " << ret << dendl;
12621257 return ret;
@@ -1637,6 +1632,9 @@ int RGWReshard::process_entry(const cls_rgw_reshard_entry& entry,
16371632 ret = store->getRados ()->get_bucket_stats (dpp, bucket_info,
16381633 bucket_info.layout .current_index ,
16391634 -1 , nullptr , nullptr , stats, nullptr , nullptr );
1635+ if (ret < 0 ) {
1636+ return clean_up (" unable to access buckets current stats" );
1637+ }
16401638
16411639 // determine current number of bucket entries across shards
16421640 uint64_t num_entries = 0 ;
@@ -1645,15 +1643,17 @@ int RGWReshard::process_entry(const cls_rgw_reshard_entry& entry,
16451643 }
16461644
16471645 const uint32_t current_shard_count =
1648- rgw::num_shards (bucket_info.get_current_index ().layout .normal );
1646+ rgw::current_num_shards (bucket_info.layout );
1647+ const uint32_t min_layout_shards =
1648+ rgw::current_min_layout_shards (bucket_info.layout );
16491649
16501650 bool needs_resharding { false };
16511651 uint32_t suggested_shard_count { 0 };
16521652 // calling this rados function determines various rados values
16531653 // needed to perform the calculation before calling
16541654 // calculating_preferred_shards() in this class
16551655 store->getRados ()->calculate_preferred_shards (
1656- dpp, num_entries, current_shard_count,
1656+ dpp, num_entries, current_shard_count, min_layout_shards,
16571657 needs_resharding, &suggested_shard_count);
16581658
16591659 // if we no longer need resharding or currently need to expand
@@ -1711,7 +1711,6 @@ int RGWReshard::process_entry(const cls_rgw_reshard_entry& entry,
17111711 }
17121712
17131713 // all checkes passed; we can reshard...
1714-
17151714 RGWBucketReshard br (store, bucket_info, bucket_attrs, nullptr );
17161715
17171716 ReshardFaultInjector f; // no fault injected
0 commit comments