]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: - take non-optional gen_id in svc_bi_rados functions
authorShilpa Jagannath <smanjara@redhat.com>
Fri, 10 Jul 2020 08:05:25 +0000 (13:35 +0530)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 13:00:20 +0000 (08:00 -0500)
     - call init_index() on target layout during reshard process.
       Takes const rgw::bucket_index_layout_generation&

Signed-off-by: Shilpa Jagannath <smanjara@redhat.com>
src/rgw/rgw_bucket.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 4c80bed0cc5a4b2c2b79acfb3919f923fa014145..4021c98368e2416a7a9d44bead6fbe0871dd84d6 100644 (file)
@@ -2419,7 +2419,7 @@ int RGWMetadataHandlerPut_BucketInstance::put_post(const DoutPrefixProvider *dpp
 
   objv_tracker = bci.info.objv_tracker;
 
-  int ret = bihandler->svc.bi->init_index(dpp, bci.info);
+  int ret = bihandler->svc.bi->init_index(dpp, bci.info, bci.info.layout.current_index);
   if (ret < 0) {
     return ret;
   }
index 877b627757cff4d6c8f7c279a8160ff3d892fbe1..ee6481fa7f3cb20ed2179900775fcc13771c1c94 100644 (file)
@@ -2376,7 +2376,7 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
       info.quota = *pquota_info;
     }
 
-    int r = svc.bi->init_index(dpp, info);
+    int r = svc.bi->init_index(dpp, info, info.layout.current_index);
     if (r < 0) {
       return r;
     }
@@ -2399,7 +2399,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(dpp, info, std::nullopt);
+        int r = svc.bi->clean_index(dpp, info, info.layout.current_index.gen);
         if (r < 0) {
          ldpp_dout(dpp, 0) << "WARNING: could not remove bucket index (r=" << r << ")" << dendl;
        }
@@ -2848,7 +2848,7 @@ int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketIn
   bucket = bucket_info.bucket;
   shard_id = sid;
 
-  int ret = store->svc.bi_rados->open_bucket_index_shard(dpp, bucket_info, shard_id, current_layout.layout.normal.num_shards, std::nullopt, &bucket_obj);
+  int ret = store->svc.bi_rados->open_bucket_index_shard(dpp, bucket_info, shard_id, current_layout.layout.normal.num_shards, current_layout.gen, &bucket_obj);
   if (ret < 0) {
     ldpp_dout(dpp, 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
     return ret;
index 75a89171174984ae69e720f834cdce9f42a106b4..1bad304ecfd3a03d3a67ae2adf83fdf445fd2ac1 100644 (file)
@@ -545,6 +545,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
   }
 
   //increment generation number
+  bucket_info.layout.target_index->gen = bucket_info.layout.current_index.gen;
   bucket_info.layout.target_index->gen++;
 
   int num_target_shards = bucket_info.layout.target_index->layout.normal.num_shards;
@@ -574,7 +575,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
     while (is_truncated) {
       entries.clear();
       ret = store->getRados()->bi_list(dpp, bucket_info, i, null_object_filter, marker, max_entries, &entries, &is_truncated);
-      if (ret < 0 && ret == -ENOENT) {
+      if (ret < 0 && ret != -ENOENT) {
         derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
         return ret;
       }
@@ -650,7 +651,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
   } else if (out) {
     (*out) << " " << total_entries << std::endl;
   }
-
+  
   ret = target_shards_mgr.finish();
   if (ret < 0) {
     ldpp_dout(dpp, -1) << "ERROR: failed to reshard" << dendl;
@@ -667,6 +668,11 @@ int RGWBucketReshard::do_reshard(int num_shards,
       return ret;
   }
 
+  ret = store->svc()->bi->init_index(dpp, bucket_info, bucket_info.layout.current_index);
+  if (ret < 0) {
+      return ret;
+  }
+
   return 0;
   // NB: some error clean-up is done by ~BucketInfoReshardUpdate
 } // RGWBucketReshard::do_reshard
@@ -717,7 +723,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
    // 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, std::nullopt);
+   ret = store->svc()->bi->clean_index(dpp, bucket_info, bucket_info.layout.current_index.gen);
    if (ret < 0) {
      lderr(store->ctx()) << "Error: " << __func__ <<
       " failed to clean up old shards; " <<
index e1d009ab3502e94c48360baedcae44c14dea36b4..9005c9dc595c03c0b265b1167381feb713a4bc74 100644 (file)
@@ -29,8 +29,8 @@ public:
   RGWSI_BucketIndex(CephContext *cct) : RGWServiceInstance(cct) {}
   virtual ~RGWSI_BucketIndex() {}
 
-  virtual int init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info) = 0;
-  virtual int clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, std::optional<uint64_t> gen) = 0;
+  virtual int init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0;
+  virtual int clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, uint64_t gen) = 0;
 
   virtual int read_stats(const DoutPrefixProvider *dpp,
                          const RGWBucketInfo& bucket_info,
index 503de8d22fac927c8b57cfa80174379783e40c6a..98bcc7d318d927a32b6f22a39f3adaa532401f45 100644 (file)
@@ -119,12 +119,11 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const DoutPrefixProvider *dpp,
 }
 
 static void get_bucket_index_objects(const string& bucket_oid_base,
-                                     uint32_t num_shards, std::optional<uint64_t> _gen_id,
+                                     uint32_t num_shards, uint64_t gen_id,
                                      map<int, string> *_bucket_objects,
                                      int shard_id = -1)
 {
   auto& bucket_objects = *_bucket_objects;
-  auto gen_id = _gen_id.value_or(0);
   if (!num_shards) {
     bucket_objects[0] = bucket_oid_base;
   } else {
@@ -211,10 +210,9 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const DoutPrefixProvider *dpp,
 void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_base,
                                                       uint32_t num_shards,
                                                       int shard_id,
-                                                      std::optional<uint64_t> _gen_id,
+                                                      uint64_t gen_id,
                                                       string *bucket_obj)
 {
-  auto gen_id = _gen_id.value_or(0);
   if (!num_shards) {
     // By default with no sharding, we use the bucket oid as itself
     (*bucket_obj) = bucket_oid_base;
@@ -296,7 +294,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const DoutPrefixProvider *d
                                                      const RGWBucketInfo& bucket_info,
                                                      int shard_id,
                                                      uint32_t num_shards,
-                                                     std::optional<uint64_t> gen,
+                                                     uint64_t gen,
                                                      RGWSI_RADOS::Obj *bucket_obj)
 {
   RGWSI_RADOS::Pool index_pool;
@@ -348,7 +346,7 @@ int RGWSI_BucketIndex_RADOS::cls_bucket_head(const DoutPrefixProvider *dpp,
   return 0;
 }
 
-int RGWSI_BucketIndex_RADOS::init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info)
+int RGWSI_BucketIndex_RADOS::init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout)
 {
   RGWSI_RADOS::Pool index_pool;
 
@@ -361,14 +359,14 @@ int RGWSI_BucketIndex_RADOS::init_index(const DoutPrefixProvider *dpp, RGWBucket
   dir_oid.append(bucket_info.bucket.bucket_id);
 
   map<int, string> bucket_objs;
-  get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, std::nullopt, &bucket_objs);
+  get_bucket_index_objects(dir_oid, idx_layout.layout.normal.num_shards, idx_layout.gen, &bucket_objs);
 
   return CLSRGWIssueBucketIndexInit(index_pool.ioctx(),
                                    bucket_objs,
                                    cct->_conf->rgw_bucket_index_max_aio)();
 }
 
-int RGWSI_BucketIndex_RADOS::clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, std::optional<uint64_t> gen)
+int RGWSI_BucketIndex_RADOS::clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, uint64_t gen)
 {
   RGWSI_RADOS::Pool index_pool;
 
index b927eb37566c478189ac95610ea2c6284bd4f9d5..17fc86b695cac43a955ce1e5aeea89cef7255372 100644 (file)
@@ -52,8 +52,8 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
   void get_bucket_index_object(const std::string& bucket_oid_base,
                                uint32_t num_shards,
                                int shard_id,
-                               std::optional<uint64_t> gen_id,
-                               std::stringbucket_obj);
+                               uint64_t gen_id,
+                               std::string *bucket_obj);
   int get_bucket_index_object(const std::string& bucket_oid_base,
                              const std::string& obj_key,
                               uint32_t num_shards, rgw::BucketHashType hash_type,
@@ -98,8 +98,10 @@ public:
     return rgw_shards_mod(sid2, num_shards);
   }
 
-  int init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info);
-  int clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, std::optional<uint64_t> gen);
+  int init_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info,
+                const rgw::bucket_index_layout_generation& idx_layout) override;
+  int clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info,
+                 uint64_t gen) override;
 
   /* RADOS specific */
 
@@ -124,7 +126,7 @@ public:
                               const RGWBucketInfo& bucket_info,
                               int shard_id,
                               uint32_t num_shards,
-                              std::optional<uint64_t> gen,
+                              uint64_t gen,
                               RGWSI_RADOS::Obj *bucket_obj);
 
   int open_bucket_index(const DoutPrefixProvider *dpp,