From: Shilpa Jagannath Date: Fri, 11 Sep 2020 06:28:55 +0000 (+0530) Subject: rgw: use a helper function to handle repetitive num_shards check X-Git-Tag: v18.0.0~787^2~148 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cb376a4c44e81dce628913b99ccc3b5b372a132d;p=ceph.git rgw: use a helper function to handle repetitive num_shards check Signed-off-by: Shilpa Jagannath --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 23378cd83408..177c8d2343ad 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2934,7 +2934,7 @@ int check_reshard_bucket_params(rgw::sal::RadosStore* store, return -EBUSY; } - int num_source_shards = ((*bucket)->get_info().layout.current_index.layout.normal.num_shards > 0 ? (*bucket)->get_info().layout.current_index.layout.normal.num_shards : 1); + int num_source_shards = rgw::current_num_shards((*bucket)->get_info().layout); if (num_shards <= num_source_shards && !yes_i_really_mean_it) { cerr << "num shards is less or equal to current shards count" << std::endl @@ -7246,7 +7246,7 @@ next: } const auto& index = bucket->get_info().layout.current_index; - int max_shards = index.layout.normal.num_shards; + const int max_shards = rgw::num_shards(index); formatter->open_array_section("entries"); @@ -7313,8 +7313,12 @@ next: } const auto& index = bucket->get_info().layout.current_index; - int max_shards = index.layout.normal.num_shards; + if (index.layout.type == rgw::BucketIndexType::Indexless) { + cerr << "ERROR: indexless bucket has no index to purge" << std::endl; + return EINVAL; + } + const int max_shards = rgw::num_shards(index); for (int i = 0; i < max_shards; i++) { RGWRados::BucketShard bs(static_cast(store)->getRados()); int shard_id = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0 ? i : -1); @@ -7600,7 +7604,7 @@ next: return ret; } - int num_source_shards = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0 ? bucket->get_info().layout.current_index.layout.normal.num_shards : 1); + int num_source_shards = rgw::current_num_shards(bucket->get_info().layout); RGWReshard reshard(static_cast(store), dpp()); cls_rgw_reshard_entry entry; diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index d8cab1734fdb..e4b3dee8fc37 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -1322,7 +1322,7 @@ int RGWBucketAdminOp::set_quota(rgw::sal::Store* store, RGWBucketAdminOpState& o static int purge_bucket_instance(rgw::sal::Store* store, const RGWBucketInfo& bucket_info, const DoutPrefixProvider *dpp) { const auto& index = bucket_info.layout.current_index; - int max_shards = index.layout.normal.num_shards; + const int max_shards = num_shards(index); for (int i = 0; i < max_shards; i++) { RGWRados::BucketShard bs(static_cast(store)->getRados()); int ret = bs.init(bucket_info.bucket, i, index, nullptr, dpp); diff --git a/src/rgw/rgw_bucket_layout.h b/src/rgw/rgw_bucket_layout.h index 6ba752a2d168..b5f0bacb512b 100644 --- a/src/rgw/rgw_bucket_layout.h +++ b/src/rgw/rgw_bucket_layout.h @@ -157,4 +157,19 @@ struct BucketLayout { void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0); void decode(BucketLayout& l, bufferlist::const_iterator& bl); + +inline uint32_t num_shards(const bucket_index_normal_layout& index) { + return index.num_shards; +} +inline uint32_t num_shards(const bucket_index_layout& index) { + ceph_assert(index.type == BucketIndexType::Normal); + return num_shards(index.normal); +} +inline uint32_t num_shards(const bucket_index_layout_generation& index) { + return num_shards(index.layout); +} +inline uint32_t current_num_shards(const BucketLayout& layout) { + return num_shards(layout.current_index); +} + } // namespace rgw diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index f66b790d9d77..0f88672df950 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -9382,8 +9382,7 @@ int RGWRados::check_bucket_shards(const RGWBucketInfo& bucket_info, } bool need_resharding = false; - uint32_t num_source_shards = - (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? bucket_info.layout.current_index.layout.normal.num_shards : 1); + uint32_t num_source_shards = rgw::current_num_shards(bucket_info.layout); const uint32_t max_dynamic_shards = uint32_t(cct->_conf.get_val("rgw_max_dynamic_shards")); @@ -9421,7 +9420,7 @@ int RGWRados::add_bucket_to_reshard(const DoutPrefixProvider *dpp, const RGWBuck { RGWReshard reshard(this->store, dpp); - uint32_t num_source_shards = (bucket_info.layout.current_index.layout.normal.num_shards > 0 ? bucket_info.layout.current_index.layout.normal.num_shards : 1); + uint32_t num_source_shards = rgw::current_num_shards(bucket_info.layout); new_num_shards = std::min(new_num_shards, get_max_bucket_shards()); if (new_num_shards <= num_source_shards) { diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 1b043d8f59bf..a2f34382f5fd 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -473,7 +473,7 @@ int RGWSI_BucketIndex_RADOS::handle_overwrite(const DoutPrefixProvider *dpp, bool old_sync_enabled = orig_info.datasync_flag_enabled(); if (old_sync_enabled != new_sync_enabled) { - int shards_num = info.layout.current_index.layout.normal.num_shards? info.layout.current_index.layout.normal.num_shards : 1; + int shards_num = rgw::current_num_shards(info.layout); int shard_id = info.layout.current_index.layout.normal.num_shards? 0 : -1; const auto& log_layout = info.layout.logs.back();