]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: - allow clean_index() to take const bucket_index_layout_generation&
authorShilpa Jagannath <smanjara@redhat.com>
Tue, 14 Jul 2020 07:33:31 +0000 (13:03 +0530)
committerCasey Bodley <cbodley@redhat.com>
Thu, 4 Feb 2021 22:19:46 +0000 (17:19 -0500)
     - fix bi_get() to get objects after being resharded

Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_reshard.cc
src/rgw/services/svc_bi.h
src/rgw/services/svc_bi_rados.cc
src/rgw/services/svc_bi_rados.h

index 05f4fd47ccd0b0a6cadb3184019918f9f4aa901f..723c8a81a578022f885427199f99df17f2119c9a 100644 (file)
@@ -6609,7 +6609,7 @@ next:
       do {
         entries.clear();
         ret = store->getRados()->bi_list(bs, object, marker, max_entries, &entries, &is_truncated);
-        if (ret < 0) {
+        if (ret < 0) {            
           cerr << "ERROR: bi_list(): " << cpp_strerror(-ret) << std::endl;
           return -ret;
         }
index 8aaa92b7010b5a25edf140e4a667d5d94b39c981..424de7ef8df5de1f9d41ee07d8d5ae160c039ef6 100644 (file)
@@ -2291,7 +2291,7 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
 
       /* only remove it if it's a different bucket instance */
       if (orig_info.bucket.bucket_id != bucket.bucket_id) {
-       int r = svc.bi->clean_index(info, info.layout.current_index.gen);
+       int r = svc.bi->clean_index(info, info.layout.current_index);
         if (r < 0) {
          ldout(cct, 0) << "WARNING: could not remove bucket index (r=" << r << ")" << dendl;
        }
index 9f80166625d300f57bfb3d0c153547f0e0bbbb57..111b32b502662f39f4a7067aa0eaff4ad6e296ba 100644 (file)
@@ -644,6 +644,7 @@ 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;
@@ -658,6 +659,18 @@ 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
@@ -704,18 +717,6 @@ 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, bucket_info.layout.current_index.gen);
-   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;
 
@@ -730,7 +731,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.target_index->gen);
+  int ret2 = store->svc()->bi->clean_index(bucket_info, bucket_info.layout.current_index);
   if (ret2 < 0) {
     lderr(store->ctx()) << "Error: " << __func__ <<
       " failed to clean up shards from failed incomplete resharding; " <<
index 962471162d059aa6f08e2dfaa10f8b3f7ac34359..746e5f0cbdc314fa6604b4dbcfe16ece49602d61 100644 (file)
@@ -30,7 +30,7 @@ public:
   virtual ~RGWSI_BucketIndex() {}
 
   virtual int init_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0;
-  virtual int clean_index(RGWBucketInfo& bucket_info, uint64_t gen) = 0;
+  virtual int clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0;
 
   virtual int read_stats(const RGWBucketInfo& bucket_info,
                          RGWBucketEnt *stats,
index 6e5f84c3b080ae41b2a9bccfb6b69ef77b1c8009..453932224a0c7c46ca5d42b1a4404aa63e09f062 100644 (file)
@@ -225,7 +225,7 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b
 
 int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_base, const string& obj_key,
                                                      uint32_t num_shards, rgw::BucketHashType hash_type,
-                                                     string *bucket_obj, int *shard_id)
+                                                     uint64_t gen_id, string *bucket_obj, int *shard_id)
 {
   int r = 0;
   switch (hash_type) {
@@ -238,8 +238,12 @@ int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_ba
         }
       } else {
         uint32_t sid = bucket_shard_index(obj_key, num_shards);
-        char buf[bucket_oid_base.size() + 32];
-        snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid);
+        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);
+        } else {
+          snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid);
+        }
         (*bucket_obj) = buf;
         if (shard_id) {
           *shard_id = (int)sid;
@@ -271,7 +275,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
   string oid;
 
   ret = get_bucket_index_object(bucket_oid_base, obj_key, bucket_info.layout.current_index.layout.normal.num_shards,
-        bucket_info.layout.current_index.layout.normal.hash_type, &oid, shard_id);
+        bucket_info.layout.current_index.layout.normal.hash_type, bucket_info.layout.current_index.gen, &oid, shard_id);
   if (ret < 0) {
     ldout(cct, 10) << "get_bucket_index_object() returned ret=" << ret << dendl;
     return ret;
@@ -357,7 +361,7 @@ int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info, const rgw::b
 }
 
 
-int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, uint64_t gen)
+int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout)
 {
   RGWSI_RADOS::Pool index_pool;
 
@@ -370,7 +374,8 @@ int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, uint64_t ge
   dir_oid.append(bucket_info.bucket.bucket_id);
 
   std::map<int, std::string> bucket_objs;
-  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, gen, &bucket_objs);
+  get_bucket_index_objects(dir_oid, idx_layout.layout.normal.num_shards,
+                           idx_layout.gen, &bucket_objs);
 
   return CLSRGWIssueBucketIndexClean(index_pool.ioctx(),
                                     bucket_objs,
index cdc243b82569a41185c63acbe68b69417cbdf138..b46c587a9de75e4eea155cd62f756e3101e27fe1 100644 (file)
@@ -53,7 +53,7 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
                                string *bucket_obj);
   int get_bucket_index_object(const string& bucket_oid_base, const string& obj_key,
                               uint32_t num_shards, rgw::BucketHashType hash_type,
-                              string *bucket_obj, int *shard_id);
+                              uint64_t gen_id, string *bucket_obj, int *shard_id);
 
   int cls_bucket_head(const RGWBucketInfo& bucket_info,
                       const rgw::bucket_index_layout_generation& idx_layout,
@@ -94,7 +94,7 @@ public:
   }
 
   int init_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout);
-  int clean_index(RGWBucketInfo& bucket_info, uint64_t gen);
+  int clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout);
 
   /* RADOS specific */