]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: reshard first cleans up old-style reshards
authorCasey Bodley <cbodley@redhat.com>
Wed, 16 Dec 2020 18:57:28 +0000 (13:57 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 14:16:19 +0000 (09:16 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_reshard.cc

index 00d30fad51686f0972a80fd10d735aebd5e1d50d..8948af31d3b8b3b7c614787663d4bdebd5c0e20d 100644 (file)
@@ -273,6 +273,24 @@ static int set_resharding_status(const DoutPrefixProvider *dpp,
   return 0;
 }
 
+static int remove_old_reshard_instance(rgw::sal::RadosStore* store,
+                                       const rgw_bucket& bucket,
+                                       const DoutPrefixProvider* dpp)
+{
+  RGWBucketInfo info;
+  auto obj_ctx = store->svc()->sysobj->init_obj_ctx();
+  int r = store->getRados()->get_bucket_instance_info(obj_ctx, bucket, info,
+                                                      nullptr, nullptr, null_yield, dpp);
+  if (r < 0) {
+    return r;
+  }
+
+  // delete its shard objects (ignore errors)
+  store->svc()->bi->clean_index(dpp, info, info.layout.current_index);
+  // delete the bucket instance metadata
+  return store->ctl()->bucket->remove_bucket_instance_info(bucket, info, null_yield, dpp);
+}
+
 // initialize a target index layout, create its bucket index shard objects, and
 // write the target layout to the bucket instance metadata
 static int init_target_layout(rgw::sal::RadosStore* store,
@@ -283,6 +301,20 @@ static int init_target_layout(rgw::sal::RadosStore* store,
 {
   uint64_t gen = bucket_info.layout.current_index.gen + 1;
 
+  if (bucket_info.reshard_status == cls_rgw_reshard_status::IN_PROGRESS) {
+    // backward-compatible cleanup of old reshards, where the target was in a
+    // different bucket instance
+    if (!bucket_info.new_bucket_instance_id.empty()) {
+      rgw_bucket new_bucket = bucket_info.bucket;
+      new_bucket.bucket_id = bucket_info.new_bucket_instance_id;
+      ldout(store->ctx(), 10) << __func__ << " removing target bucket instance "
+          "from a previous reshard attempt" << dendl;
+      // ignore errors
+      remove_old_reshard_instance(store, new_bucket, dpp);
+    }
+    bucket_info.reshard_status = cls_rgw_reshard_status::NOT_RESHARDING;
+  }
+
   auto& target = bucket_info.layout.target_index;
   if (target) {
     // a previous reshard failed or stalled, and its reshard lock dropped