]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: helper function to set reshard status from rgw::BucketReshardState.
authorShilpa Jagannath <smanjara@redhat.com>
Tue, 21 Jul 2020 13:10:09 +0000 (18:40 +0530)
committerCasey Bodley <cbodley@redhat.com>
Fri, 5 Feb 2021 02:05:17 +0000 (21:05 -0500)
Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index 0fd0690f232ac5261a307115d1a2d961442f4e80..2444e39a45ef5df4c2984adf04afa4993ec14279 100644 (file)
@@ -322,7 +322,8 @@ static int set_target_layout(rgw::sal::RGWRadosStore *store,
                              RGWBucketInfo& bucket_info,
                              const DoutPrefixProvider *dpp)
 {
-  assert(!bucket_info.layout.target_index);
+  bucket_info.layout.target_index = std::nullopt; // to ensure empty target_index in case of an abruptly interrupted reshard process
+  ceph_assert(!bucket_info.layout.target_index);
   bucket_info.layout.target_index.emplace();
 
   bucket_info.layout.target_index->layout.normal.num_shards = new_num_shards;
@@ -331,15 +332,7 @@ static int set_target_layout(rgw::sal::RGWRadosStore *store,
   bucket_info.layout.target_index->gen = bucket_info.layout.current_index.gen;
   bucket_info.layout.target_index->gen++;
 
-  bucket_info.layout.resharding = rgw::BucketReshardState::InProgress;
-
-  int ret = store->getRados()->put_bucket_instance_info(bucket_info, true, real_time(), nullptr, dpp);
-  if (ret < 0) {
-    cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl;
-    return ret;
-  }
-
-    ret = store->svc()->bi->init_index(bucket_info, *(bucket_info.layout.target_index));
+  int ret = store->svc()->bi->init_index(bucket_info, *(bucket_info.layout.target_index));
   if (ret < 0) {
       return ret;
   }
@@ -349,6 +342,11 @@ static int set_target_layout(rgw::sal::RGWRadosStore *store,
 
 int RGWBucketReshard::set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp)
 {
+  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;
+    return ret;
+  }
   return ::set_target_layout(store, new_num_shards, bucket_info, dpp);
 }
 
@@ -646,8 +644,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
   //overwrite current_index for the next reshard process
   bucket_info.layout.current_index = *bucket_info.layout.target_index;
   bucket_info.layout.target_index = std::nullopt; // target_layout doesn't need to exist after reshard
-  bucket_info.layout.resharding = rgw::BucketReshardState::None;
-  ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), nullptr, dpp);
+  ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp);
   if (ret < 0) {
     lderr(store->ctx()) << "ERROR: failed writing bucket instance info: " << dendl;
       return ret;
@@ -662,6 +659,15 @@ int RGWBucketReshard::get_status(list<cls_rgw_bucket_instance_entry> *status)
   return store->svc()->bi_rados->get_reshard_status(bucket_info, status);
 }
 
+int RGWBucketReshard::set_reshard_status(rgw::BucketReshardState s, const DoutPrefixProvider* dpp) {
+    bucket_info.layout.resharding = s;
+    int ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), nullptr, dpp);
+    if (ret < 0) {
+      ldout(store->ctx(), 0) << "ERROR: failed to write bucket info, ret=" << ret << dendl;
+      return ret;
+    }
+    return 0;
+}
 
 int RGWBucketReshard::execute(int num_shards, int max_op_entries,
                               const DoutPrefixProvider *dpp,
@@ -727,6 +733,7 @@ error_out:
   // since the real problem is the issue that led to this error code
   // path, we won't touch ret and instead use another variable to
   // temporarily error codes
+
   int ret2 = store->svc()->bi->clean_index(bucket_info, bucket_info.layout.current_index);
   if (ret2 < 0) {
     lderr(store->ctx()) << "Error: " << __func__ <<
@@ -742,9 +749,10 @@ error_out:
       return ret;
   }
 
-  ret = store->svc()->bi->init_index(bucket_info, bucket_info.layout.current_index);
+  ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp);
   if (ret < 0) {
-      return ret;
+    cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl;
+    return ret;
   }
   
   return ret;
index b372ed81941cb1c245b9e5b0ee559971893503c0..a468e3592761e9d7937db50a6b541200a0de51b5 100644 (file)
@@ -86,6 +86,8 @@ private:
   static const std::initializer_list<uint16_t> reshard_primes;
 
   int set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp);
+  int set_reshard_status(rgw::BucketReshardState s, const DoutPrefixProvider* dpp);
+  
   int do_reshard(int num_shards,
                 int max_entries,
                  bool verbose,