]> 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)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 13:40:38 +0000 (08:40 -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 4021c98368e2416a7a9d44bead6fbe0871dd84d6..7b8beb80671211bf0561f16eced83491fc036874 100644 (file)
@@ -1357,8 +1357,7 @@ static int purge_bucket_instance(rgw::sal::Store* store, const RGWBucketInfo& bu
   int max_shards = index.layout.normal.num_shards;
   for (int i = 0; i < max_shards; i++) {
     RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(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 a312cdd731f8df63d320d67db62a174bd43cd0ca..8c6f5a82050bde0da499693139384af1a0e84c56 100644 (file)
@@ -349,7 +349,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);
@@ -725,7 +725,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(dpp, bucket_info, prev_index);
@@ -766,7 +766,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 b5c2c10c264c77e40929967925db536d43ec3ccb..1b043d8f59bf054ca6a91b5e6f847843153d98f0 100644 (file)
@@ -118,6 +118,17 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const DoutPrefixProvider *dpp,
   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,
@@ -131,25 +142,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;
       }
     }
   }
@@ -172,7 +181,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);
@@ -219,12 +228,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;
     }
   }
@@ -247,9 +256,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) {