@@ -10324,66 +10324,96 @@ int RGWRados::cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBuck
1032410324 return 0 ;
1032510325}
1032610326
10327+
10328+ // uses information that the store has easy access to transition to the shard calculatoin logic
10329+ void RGWRados::calculate_preferred_shards (const DoutPrefixProvider* dpp,
10330+ const uint64_t num_objs,
10331+ const uint32_t num_source_shards,
10332+ bool & need_resharding,
10333+ uint32_t * suggested_num_shards)
10334+ {
10335+ const uint32_t max_dynamic_shards =
10336+ uint32_t (cct->_conf .get_val <uint64_t >(" rgw_max_dynamic_shards" ));
10337+ const uint64_t max_objs_per_shard =
10338+ cct->_conf .get_val <uint64_t >(" rgw_max_objs_per_shard" );
10339+ const bool is_multisite = svc.zone ->need_to_log_data ();
10340+
10341+ RGWBucketReshard::calculate_preferred_shards (dpp,
10342+ max_dynamic_shards,
10343+ max_objs_per_shard,
10344+ is_multisite,
10345+ num_objs,
10346+ num_source_shards,
10347+ need_resharding,
10348+ suggested_num_shards);
10349+ }
10350+
10351+
10352+ // Check whether a bucket is a candidate for dynamic resharding and if
10353+ // so, add it to the reshard queue (log).
10354+ //
10355+ // We implement dynamic reshard reduction (where the number of shards
10356+ // can be reduced) in the following manner. In addition to the maximum
10357+ // number of desired entries per shard, we now set a minimum
1032710358int RGWRados::check_bucket_shards (const RGWBucketInfo& bucket_info,
1032810359 uint64_t num_objs,
10329- const DoutPrefixProvider * dpp, optional_yield y)
10360+ const DoutPrefixProvider* dpp, optional_yield y)
1033010361{
1033110362 if (! cct->_conf .get_val <bool >(" rgw_dynamic_resharding" )) {
10332- return 0 ;
10363+ return 0 ;
1033310364 }
1033410365
1033510366 if (! is_layout_reshardable (bucket_info.layout )) {
1033610367 return 0 ;
1033710368 }
1033810369
10339- bool need_resharding = false ;
10340- uint32_t num_source_shards = rgw::current_num_shards (bucket_info.layout );
10341- const uint32_t max_dynamic_shards =
10342- uint32_t (cct->_conf .get_val <uint64_t >(" rgw_max_dynamic_shards" ));
10343-
10344- if (num_source_shards >= max_dynamic_shards) {
10345- return 0 ;
10346- }
10370+ // TODO: consider per-bucket sync policy here?
1034710371
10372+ bool need_resharding = false ;
1034810373 uint32_t suggested_num_shards = 0 ;
10349- const uint64_t max_objs_per_shard =
10350- cct-> _conf . get_val < uint64_t >( " rgw_max_objs_per_shard " );
10374+ const uint32_t num_source_shards =
10375+ rgw::current_num_shards (bucket_info. layout );
1035110376
10352- // TODO: consider per-bucket sync policy here?
10353- const bool is_multisite = svc.zone ->need_to_log_data ();
10354-
10355- quota_handler->check_bucket_shards (dpp, max_objs_per_shard, num_source_shards,
10356- num_objs, is_multisite, need_resharding,
10357- &suggested_num_shards);
10377+ calculate_preferred_shards (dpp, num_objs, num_source_shards,
10378+ need_resharding, &suggested_num_shards);
1035810379 if (! need_resharding) {
1035910380 return 0 ;
1036010381 }
1036110382
10362- const uint32_t final_num_shards =
10363- RGWBucketReshard::get_preferred_shards (suggested_num_shards,
10364- max_dynamic_shards);
1036510383 // final verification, so we don't reduce number of shards
10366- if (final_num_shards <= num_source_shards) {
10384+ const bool may_reduce =
10385+ uint32_t (cct->_conf .get_val <bool >(" rgw_dynamic_resharding_may_reduce" ));
10386+ if (! may_reduce && suggested_num_shards <= num_source_shards) {
1036710387 return 0 ;
1036810388 }
1036910389
10370- ldpp_dout (dpp, 1 ) << " RGWRados::" << __func__ << " bucket " << bucket_info. bucket . name <<
10371- " needs resharding; current num shards " << bucket_info.layout . current_index . layout . normal . num_shards <<
10372- " ; new num shards " << final_num_shards << " (suggested " <<
10373- suggested_num_shards << " ) " << dendl;
10390+ ldpp_dout (dpp, 1 ) << " RGWRados::" << __func__ <<
10391+ " bucket " << bucket_info.bucket . name <<
10392+ " needs resharding; current num shards " << num_source_shards <<
10393+ " ; new num shards " << suggested_num_shards << dendl;
1037410394
10375- return add_bucket_to_reshard (dpp, bucket_info, final_num_shards , y);
10395+ return add_bucket_to_reshard (dpp, bucket_info, suggested_num_shards , y);
1037610396}
1037710397
10378- int RGWRados::add_bucket_to_reshard (const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, uint32_t new_num_shards, optional_yield y)
10398+ int RGWRados::add_bucket_to_reshard (const DoutPrefixProvider *dpp,
10399+ const RGWBucketInfo& bucket_info,
10400+ uint32_t new_num_shards,
10401+ optional_yield y)
1037910402{
1038010403 RGWReshard reshard (this ->driver , dpp);
1038110404
10382- uint32_t num_source_shards = rgw::current_num_shards (bucket_info.layout );
10383-
10405+ const uint32_t num_source_shards = rgw::current_num_shards (bucket_info.layout );
10406+ const bool may_reduce =
10407+ uint32_t (cct->_conf .get_val <bool >(" rgw_dynamic_resharding_may_reduce" ));
1038410408 new_num_shards = std::min (new_num_shards, get_max_bucket_shards ());
10385- if (new_num_shards <= num_source_shards) {
10386- ldpp_dout (dpp, 20 ) << " not resharding bucket name=" << bucket_info.bucket .name << " , orig_num=" << num_source_shards << " , new_num_shards=" << new_num_shards << dendl;
10409+
10410+ if ((! may_reduce && new_num_shards < num_source_shards) ||
10411+ new_num_shards == num_source_shards) {
10412+ ldpp_dout (dpp, 10 ) << " WARNING: " << __func__ <<
10413+ " : rejecting resharding request for bucket name=" <<
10414+ bucket_info.bucket .name << " , shard count=" << num_source_shards <<
10415+ " , new shard count=" << new_num_shards <<
10416+ " , rgw_dynamic_resharding_may_reduce=" << may_reduce << dendl;
1038710417 return 0 ;
1038810418 }
1038910419
@@ -10394,6 +10424,7 @@ int RGWRados::add_bucket_to_reshard(const DoutPrefixProvider *dpp, const RGWBuck
1039410424 entry.bucket_id = bucket_info.bucket .bucket_id ;
1039510425 entry.old_num_shards = num_source_shards;
1039610426 entry.new_num_shards = new_num_shards;
10427+ entry.initiator = cls_rgw_reshard_initiator::Dynamic;
1039710428
1039810429 return reshard.add (dpp, entry, y);
1039910430}
0 commit comments