]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: change cls rgw reshard status to enum class 30611/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Fri, 27 Sep 2019 00:57:39 +0000 (20:57 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Tue, 11 Feb 2020 18:15:21 +0000 (13:15 -0500)
Get the type safety and reduced impact on global namespace of enum
class.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/cls/rgw/cls_rgw_types.cc
src/cls/rgw/cls_rgw_types.h
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_common.h
src/rgw/rgw_orphan.cc
src/rgw/rgw_reshard.cc

index a2d4580cbaf46f2f7f03baa42b77755ff73d0865..f820003a2ff512f98fe2d10fb5191190d2ba67b5 100644 (file)
@@ -746,11 +746,12 @@ void cls_rgw_bucket_instance_entry::dump(Formatter *f) const
 
 }
 
-void cls_rgw_bucket_instance_entry::generate_test_instances(list<cls_rgw_bucket_instance_entry*>& ls)
+void cls_rgw_bucket_instance_entry::generate_test_instances(
+  list<cls_rgw_bucket_instance_entry*>& 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";
 }
   
index db8a3bcd18a6f0f949f03f6029ee95f5f73d44b4..b97243570641e154d9e6b363960b09c436b32bc1 100644 (file)
@@ -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<cls_rgw_bucket_instance_entry*>& 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)
index e43faddf47d2cc4e79a9a4a8283febb3d76f5ae2..bcfda46bf01ef84587ead137050f58201bb39f40 100644 (file)
@@ -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;
index 630c0aadf60affd92eec910ff14d008e87a2a42b..258919a4bc0a19ff57ca4a5d6f267eba39ad59f0 100644 (file)
@@ -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(),
index c7677b83991f3f4e4d16de6f3f691944a903efbc..07745d6adc3d5991307b0c0370c17b0b6bf2dead 100644 (file)
@@ -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<string, uint32_t> 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;
index 6dcaeaa0d39273fd9d9b58779e76757e894fe7e8..7a1174039cbdf3aac678f645cd85535bf4466ee2 100644 (file)
@@ -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;
index c6662931961cfa0a7e00d067da84d1abc381c5a1..e20d8a392388da2a8d48dc2e76499d891f422b53 100644 (file)
@@ -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;
   }