From: J. Eric Ivancich Date: Fri, 27 Sep 2019 00:57:39 +0000 (-0400) Subject: rgw: change cls rgw reshard status to enum class X-Git-Tag: v15.1.1~450^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F30611%2Fhead;p=ceph.git rgw: change cls rgw reshard status to enum class Get the type safety and reduced impact on global namespace of enum class. Signed-off-by: J. Eric Ivancich --- diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index a2d4580cbaf4..f820003a2ff5 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -746,11 +746,12 @@ void cls_rgw_bucket_instance_entry::dump(Formatter *f) const } -void cls_rgw_bucket_instance_entry::generate_test_instances(list& ls) +void cls_rgw_bucket_instance_entry::generate_test_instances( + list& ls) { ls.push_back(new cls_rgw_bucket_instance_entry); ls.push_back(new cls_rgw_bucket_instance_entry); - ls.back()->reshard_status = CLS_RGW_RESHARD_IN_PROGRESS; + ls.back()->reshard_status = RESHARD_STATUS::IN_PROGRESS; ls.back()->new_bucket_instance_id = "new_instance_id"; } diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index db8a3bcd18a6..b97243570641 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -721,32 +721,32 @@ struct rgw_bucket_category_stats { }; WRITE_CLASS_ENCODER(rgw_bucket_category_stats) -enum cls_rgw_reshard_status { - CLS_RGW_RESHARD_NOT_RESHARDING = 0, - CLS_RGW_RESHARD_IN_PROGRESS = 1, - CLS_RGW_RESHARD_DONE = 2, +enum class cls_rgw_reshard_status : uint8_t { + NOT_RESHARDING = 0, + IN_PROGRESS = 1, + DONE = 2 }; -static inline std::string to_string(const enum cls_rgw_reshard_status status) +static inline std::string to_string(const cls_rgw_reshard_status status) { switch (status) { - case CLS_RGW_RESHARD_NOT_RESHARDING: + case cls_rgw_reshard_status::NOT_RESHARDING: return "not-resharding"; break; - case CLS_RGW_RESHARD_IN_PROGRESS: + case cls_rgw_reshard_status::IN_PROGRESS: return "in-progress"; break; - case CLS_RGW_RESHARD_DONE: + case cls_rgw_reshard_status::DONE: return "done"; break; - default: - break; }; return "Unknown reshard status"; } struct cls_rgw_bucket_instance_entry { - cls_rgw_reshard_status reshard_status{CLS_RGW_RESHARD_NOT_RESHARDING}; + using RESHARD_STATUS = cls_rgw_reshard_status; + + cls_rgw_reshard_status reshard_status{RESHARD_STATUS::NOT_RESHARDING}; string new_bucket_instance_id; int32_t num_shards{-1}; @@ -772,21 +772,23 @@ struct cls_rgw_bucket_instance_entry { static void generate_test_instances(list& o); void clear() { - reshard_status = CLS_RGW_RESHARD_NOT_RESHARDING; + reshard_status = RESHARD_STATUS::NOT_RESHARDING; new_bucket_instance_id.clear(); } - void set_status(const string& new_instance_id, int32_t new_num_shards, cls_rgw_reshard_status s) { + void set_status(const string& new_instance_id, + int32_t new_num_shards, + cls_rgw_reshard_status s) { reshard_status = s; new_bucket_instance_id = new_instance_id; num_shards = new_num_shards; } bool resharding() const { - return reshard_status != CLS_RGW_RESHARD_NOT_RESHARDING; + return reshard_status != RESHARD_STATUS::NOT_RESHARDING; } bool resharding_in_progress() const { - return reshard_status == CLS_RGW_RESHARD_IN_PROGRESS; + return reshard_status == RESHARD_STATUS::IN_PROGRESS; } }; WRITE_CLASS_ENCODER(cls_rgw_bucket_instance_entry) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index e43faddf47d2..bcfda46bf01e 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -2723,7 +2723,7 @@ int check_reshard_bucket_params(rgw::sal::RGWRadosStore *store, return ret; } - if (bucket_info.reshard_status != CLS_RGW_RESHARD_NOT_RESHARDING) { + if (bucket_info.reshard_status != cls_rgw_reshard_status::NOT_RESHARDING) { // if in_progress or done then we have an old BucketInfo cerr << "ERROR: the bucket is currently undergoing resharding and " "cannot be added to the reshard list at this time" << std::endl; diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 630c0aadf60a..258919a4bc0a 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -1673,7 +1673,7 @@ void get_stale_instances(rgw::sal::RGWRadosStore *store, const std::string& buck << cpp_strerror(-r) << dendl; continue; } - if (binfo.reshard_status == CLS_RGW_RESHARD_DONE) + if (binfo.reshard_status == cls_rgw_reshard_status::DONE) stale_instances.emplace_back(std::move(binfo)); else { other_instances.emplace_back(std::move(binfo)); @@ -1700,7 +1700,7 @@ void get_stale_instances(rgw::sal::RGWRadosStore *store, const std::string& buck } // Don't process further in this round if bucket is resharding - if (cur_bucket_info.reshard_status == CLS_RGW_RESHARD_IN_PROGRESS) + if (cur_bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS) return; other_instances.erase(std::remove_if(other_instances.begin(), other_instances.end(), diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index c7677b83991f..07745d6adc3d 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1125,8 +1125,8 @@ struct RGWBucketInfo { RGWQuotaInfo quota; // Represents the number of bucket index object shards: - // - value of 0 indicates there is no sharding (this is by default before this - // feature is implemented). + // - value of 0 indicates there is no sharding (this is by default + // before this feature is implemented). // - value of UINT32_T::MAX indicates this is a blind bucket. uint32_t num_shards{0}; @@ -1148,10 +1148,8 @@ struct RGWBucketInfo { map mdsearch_config; - - - /* resharding */ - uint8_t reshard_status{0}; + // resharding + cls_rgw_reshard_status reshard_status{cls_rgw_reshard_status::NOT_RESHARDING}; string new_bucket_instance_id; RGWObjectLock obj_lock; diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index 6dcaeaa0d392..7a1174039cbd 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -518,7 +518,7 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ return 0; } - if (cur_bucket_info.reshard_status == CLS_RGW_RESHARD_IN_PROGRESS) { + if (cur_bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS) { ldout(store->ctx(), 0) << __func__ << ": reshard in progress. Skipping " << orphan_bucket.name << ": " << orphan_bucket.bucket_id << dendl; diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index c6662931961c..e20d8a392388 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -310,7 +310,7 @@ int RGWBucketReshard::clear_index_shard_reshard_status(rgw::sal::RGWRadosStore* int ret = set_resharding_status(store, bucket_info, bucket_info.bucket.bucket_id, (num_shards < 1 ? 1 : num_shards), - CLS_RGW_RESHARD_NOT_RESHARDING); + cls_rgw_reshard_status::NOT_RESHARDING); if (ret < 0) { ldout(store->ctx(), 0) << "RGWBucketReshard::" << __func__ << " ERROR: error clearing reshard status from index shard " << @@ -336,7 +336,7 @@ static int create_new_bucket_instance(rgw::sal::RGWRadosStore *store, new_bucket_info.objv_tracker.clear(); new_bucket_info.new_bucket_instance_id.clear(); - new_bucket_info.reshard_status = 0; + new_bucket_info.reshard_status = cls_rgw_reshard_status::NOT_RESHARDING; int ret = store->svc()->bi->init_index(new_bucket_info); if (ret < 0) { @@ -413,12 +413,14 @@ public: " clear_index_shard_status returned " << ret << dendl; } bucket_info.new_bucket_instance_id.clear(); - set_status(CLS_RGW_RESHARD_NOT_RESHARDING); // clears new_bucket_instance as well + + // clears new_bucket_instance as well + set_status(cls_rgw_reshard_status::NOT_RESHARDING); } } int start() { - int ret = set_status(CLS_RGW_RESHARD_IN_PROGRESS); + int ret = set_status(cls_rgw_reshard_status::IN_PROGRESS); if (ret < 0) { return ret; } @@ -427,7 +429,7 @@ public: } int complete() { - int ret = set_status(CLS_RGW_RESHARD_DONE); + int ret = set_status(cls_rgw_reshard_status::DONE); if (ret < 0) { return ret; } @@ -711,7 +713,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries, // set resharding status of current bucket_info & shards with // information about planned resharding ret = set_resharding_status(new_bucket_info.bucket.bucket_id, - num_shards, CLS_RGW_RESHARD_IN_PROGRESS); + num_shards, cls_rgw_reshard_status::IN_PROGRESS); if (ret < 0) { goto error_out; }