]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: failing to reshard, restore old indexes
authorShilpa Jagannath <smanjara@redhat.com>
Tue, 14 Jul 2020 12:26:05 +0000 (17:56 +0530)
committerCasey Bodley <cbodley@redhat.com>
Fri, 5 Feb 2021 02:03:57 +0000 (21:03 -0500)
Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h

index 111b32b502662f39f4a7067aa0eaff4ad6e296ba..7547b96e29af8f87a8c46090fd7a1dcbf7058193 100644 (file)
@@ -644,7 +644,6 @@ int RGWBucketReshard::do_reshard(int num_shards,
   }
 
   //overwrite current_index for the next reshard process
-  const auto prev_index = bucket_info.layout.current_index;
   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;
@@ -659,18 +658,6 @@ int RGWBucketReshard::do_reshard(int num_shards,
       return ret;
   }
 
-  // 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
-  // shard objects
-
-  ret = store->svc()->bi->clean_index(bucket_info, prev_index);
-  if (ret < 0) {
-    lderr(store->ctx()) << "Error: " << __func__ <<
-    " failed to clean up old shards; " <<
-    "RGWRados::clean_bucket_index returned " << ret << dendl;
-}
-
   return 0;
   // NB: some error clean-up is done by ~BucketInfoReshardUpdate
 } // RGWBucketReshard::do_reshard
@@ -703,7 +690,9 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
       goto error_out;
     }
   }
-
+  
+  // keep a copy of old index layout
+  prev_index = bucket_info.layout.current_index;
 
   ret = do_reshard(num_shards,
                   max_op_entries,
@@ -717,6 +706,18 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
 
   reshard_lock.unlock();
 
+  // 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
+  // shard objects
+
+  ret = store->svc()->bi->clean_index(bucket_info, prev_index);
+  if (ret < 0) {
+    lderr(store->ctx()) << "Error: " << __func__ <<
+    " failed to clean up old shards; " <<
+    "RGWRados::clean_bucket_index returned " << ret << dendl;
+}
+
   ldout(store->ctx(), 1) << __func__ <<
     " INFO: reshard of bucket \"" << bucket_info.bucket.name << "\" completed successfully" << dendl;
 
@@ -738,6 +739,19 @@ error_out:
       "RGWRados::clean_bucket_index returned " << ret2 << dendl;
   }
 
+  // restore old index if reshard fails
+  bucket_info.layout.current_index = prev_index;
+  ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), &bucket_attrs, dpp);
+  if (ret < 0) {
+    lderr(store->ctx()) << "ERROR: failed writing bucket instance info: " << dendl;
+      return ret;
+  }
+
+  ret = store->svc()->bi->init_index(bucket_info, bucket_info.layout.current_index);
+  if (ret < 0) {
+      return ret;
+  }
+  
   return ret;
 } // execute
 
index 02a1e7d464fa2bff13d403e55f2705897558ca56..b372ed81941cb1c245b9e5b0ee559971893503c0 100644 (file)
@@ -76,6 +76,7 @@ private:
   rgw::sal::RGWRadosStore *store;
   RGWBucketInfo bucket_info;
   std::map<string, bufferlist> bucket_attrs;
+  rgw::bucket_index_layout_generation prev_index;
 
   RGWBucketReshardLock reshard_lock;
   RGWBucketReshardLock* outer_reshard_lock;