]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: code organization fixes and error handling
authorShilpa Jagannath <smanjara@redhat.com>
Tue, 1 Sep 2020 18:25:42 +0000 (23:55 +0530)
committerCasey Bodley <cbodley@redhat.com>
Fri, 5 Feb 2021 02:11:53 +0000 (21:11 -0500)
Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_reshard.cc
src/rgw/services/svc_bi_rados.cc

index 4b9a359005af8bae417ad8c91c941845783f0bef..7830e5105f24c228005dc2ae2fa6846a595884fa 100644 (file)
@@ -1628,8 +1628,7 @@ static int purge_bucket_instance(rgw::sal::RGWRadosStore *store, const RGWBucket
   int max_shards = index.layout.normal.num_shards;
   for (int i = 0; i < max_shards; i++) {
     RGWRados::BucketShard bs(store->getRados());
-    int ret = bs.init(bucket_info.bucket, i, bucket_info.layout.current_index,
-                      nullptr, dpp);
+    int ret = bs.init(bucket_info.bucket, i, index, nullptr, dpp);
     if (ret < 0) {
       cerr << "ERROR: bs.init(bucket=" << bucket_info.bucket << ", shard=" << i
            << "): " << cpp_strerror(-ret) << std::endl;
index 2498c685833ac8a3778f6885f08e602a1dff393d..0979b3863a3335970840ddd6f1de0a5b6faaabc8 100644 (file)
@@ -344,7 +344,7 @@ int RGWBucketReshard::set_target_layout(int new_num_shards, const DoutPrefixProv
 {
   int ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::InProgress, dpp);
   if (ret < 0) {
-    cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl;
+    lderr(store->ctx()) << "ERROR: failed to store updated bucket instance info: " << dendl;
     return ret;
   }
   return ::set_target_layout(store, new_num_shards, bucket_info, dpp);
@@ -710,7 +710,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
 
   // resharding successful, so remove old bucket index shards; use
   // best effort and don't report out an error; the lock isn't needed
-  // at this point since all we're using a best effor to to remove old
+  // at this point since all we're using a best effort to remove old
   // shard objects
 
   ret = store->svc()->bi->clean_index(bucket_info, prev_index);
@@ -752,7 +752,7 @@ error_out:
 
   ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp);
   if (ret < 0) {
-    cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl;
+    lderr(store->ctx()) << "ERROR: failed to store updated bucket instance info: " << dendl;
     return ret;
   }
   
index 453932224a0c7c46ca5d42b1a4404aa63e09f062..22f9fd1ece6a99f87fb512999a71a209d1e9fe00 100644 (file)
@@ -112,6 +112,17 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info,
   return 0;
 }
 
+static char bucket_obj_with_generation(char *buf, size_t len, const string& bucket_oid_base, uint64_t gen_id,
+                                    uint32_t shard_id)
+{
+  return snprintf(buf, len, "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
+}
+
+static char bucket_obj_without_generation(char *buf, size_t len, const string& bucket_oid_base, uint32_t shard_id)
+{
+  return snprintf(buf, len, "%s.%d", bucket_oid_base.c_str(), shard_id);
+}
+
 static void get_bucket_index_objects(const string& bucket_oid_base,
                                      uint32_t num_shards, uint64_t gen_id,
                                      map<int, string> *_bucket_objects,
@@ -125,25 +136,23 @@ static void get_bucket_index_objects(const string& bucket_oid_base,
     if (shard_id < 0) {
       for (uint32_t i = 0; i < num_shards; ++i) {
         if (gen_id) {
-          snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, i);
-          bucket_objects[i] = buf;
-          } else {
-            snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), i);
-            bucket_objects[i] = buf;
-          }
+          bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, i);
+        } else {
+          bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, i);
+        }
+        bucket_objects[i] = buf;
       }
     } else {
-      if ((uint32_t)shard_id > num_shards) {
+      if (static_cast<uint32_t>(shard_id) > num_shards) {
         return;
       } else {
-               if (gen_id) {
-                 snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
-                 bucket_objects[shard_id] = buf;
-               } else {
-                 // for backward compatibility, gen_id(0) will not be added in the object name
-                 snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id);
-                 bucket_objects[shard_id] = buf;
-               }
+        if (gen_id) {
+          bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id);
+        } else {
+          // for backward compatibility, gen_id(0) will not be added in the object name
+          bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id);
+        }
+        bucket_objects[shard_id] = buf;
       }
     }
   }
@@ -166,7 +175,7 @@ static void get_bucket_instance_ids(const RGWBucketInfo& bucket_info,
         (*result)[i] = plain_id + buf;
       }
     } else {
-      if ((uint32_t)shard_id > bucket_info.layout.current_index.layout.normal.num_shards) {
+      if (static_cast<uint32_t>(shard_id) > bucket_info.layout.current_index.layout.normal.num_shards) {
         return;
       }
       snprintf(buf, sizeof(buf), ":%d", shard_id);
@@ -212,12 +221,12 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b
   } else {
     char buf[bucket_oid_base.size() + 64];
     if (gen_id) {
-      snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
+      bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id);
       (*bucket_obj) = buf;
          ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
     } else {
       // for backward compatibility, gen_id(0) will not be added in the object name
-      snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id);
+      bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id);
       (*bucket_obj) = buf;
     }
   }
@@ -240,9 +249,9 @@ int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_ba
         uint32_t sid = bucket_shard_index(obj_key, num_shards);
         char buf[bucket_oid_base.size() + 64];
         if (gen_id) {
-          snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, sid);
+          bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, sid);
         } else {
-          snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid);
+          bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, sid);
         }
         (*bucket_obj) = buf;
         if (shard_id) {