]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: target_layout to be optional
authorShilpa Manjarabad Jagannath <smanjara@smanjara.remote.csb>
Mon, 6 Jul 2020 09:47:15 +0000 (15:17 +0530)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 12:40:18 +0000 (07:40 -0500)
Signed-off-by: Shilpa Manjarabad Jagannath <smanjara@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket_layout.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_reshard.cc
src/rgw/rgw_sal_rados.cc
src/rgw/services/svc_bi_rados.cc
src/rgw/services/svc_bi_rados.h

index d9b0e3f4654ef940b6947669d84d6dc775c0945d..7d2455f8ee6dc186bf4b3fafd5a188667b756049 100644 (file)
@@ -7225,8 +7225,7 @@ next:
     int i = (specified_shard_id ? shard_id : 0);
     for (; i < max_shards; i++) {
       RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
-      int shard_id = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0  ? i : -1);
-      int ret = bs.init(bucket->get_key(), shard_id, index, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket->get_key(), shard_id, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
       marker.clear();
 
       if (ret < 0) {
@@ -7291,7 +7290,7 @@ next:
     for (int i = 0; i < max_shards; i++) {
       RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
       int shard_id = (bucket->get_info().layout.current_index.layout.normal.num_shards > 0  ? i : -1);
-      int ret = bs.init(bucket->get_key(), shard_id, index, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket->get_key(), shard_id, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
       if (ret < 0) {
         cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << i << "): " << cpp_strerror(-ret) << std::endl;
         return -ret;
index c4ec010873c1de6b7eb67179b21311554749a5a2..5345f1687f3c8a5f0371e10dc6c86517b0187712 100644 (file)
@@ -1357,7 +1357,8 @@ static int purge_bucket_instance(rgw::sal::Store* store, const RGWBucketInfo& bu
   int max_shards = index.layout.normal.num_shards;
   for (int i = 0; i < max_shards; i++) {
     RGWRados::BucketShard bs(static_cast<rgw::sal::RadosStore*>(store)->getRados());
-    int ret = bs.init(bucket_info.bucket, i, bucket_info.layout.current_index, nullptr, dpp);
+    int ret = bs.init(bucket_info.bucket, i, bucket_info.layout.current_index,
+                      std::nullopt, nullptr, dpp);
     if (ret < 0) {
       cerr << "ERROR: bs.init(bucket=" << bucket_info.bucket << ", shard=" << i
            << "): " << cpp_strerror(-ret) << std::endl;
index 6ba752a2d1686ccec1c5d201fd2251a5cb6877c1..7839c519520469c3440dbe2f96d38f4c61884564 100644 (file)
@@ -66,6 +66,7 @@ void decode(bucket_index_layout& l, bufferlist::const_iterator& bl);
 struct bucket_index_layout_generation {
   uint64_t gen = 0;
   bucket_index_layout layout;
+
 };
 
 void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0);
index 433024a508315374d1328d44f839488a17de6457..51fa0e77317d48a1d69567e8196f176ae4f81e45 100644 (file)
@@ -2791,9 +2791,10 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
 }
 
 int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
-                               int sid, const rgw::bucket_index_layout_generation& idx_layout,
+                               int sid, const rgw::bucket_index_layout_generation& current_layout,
+                               std::optional<rgw::bucket_index_layout_generation> target_layout,
                                RGWBucketInfo* bucket_info_out,
-                                const DoutPrefixProvider *dpp)
+                               const DoutPrefixProvider *dpp)
 {
   bucket = _bucket;
   shard_id = sid;
@@ -2811,7 +2812,13 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
 
   string oid;
 
-  ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, idx_layout, &bucket_obj);
+  if (target_layout) {
+    ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, target_layout->layout.normal.num_shards,
+                                                      target_layout->gen, &bucket_obj);
+  } else {
+    ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, 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;
@@ -2839,12 +2846,12 @@ int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketIn
   return 0;
 }
 
-int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& target_layout, int sid)
+int RGWRados::BucketShard::init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& current_layout, int sid)
 {
   bucket = bucket_info.bucket;
   shard_id = sid;
 
-  int ret = store->svc.bi_rados->open_bucket_index_shard(dpp, bucket_info, shard_id, target_layout, &bucket_obj);
+  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);
   if (ret < 0) {
     ldpp_dout(dpp, 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
     return ret;
@@ -8295,7 +8302,9 @@ int RGWRados::bi_list(const DoutPrefixProvider *dpp,
                      list<rgw_cls_bi_entry> *entries, bool *is_truncated)
 {
   BucketShard bs(this);
-  int ret = bs.init(bucket_info.bucket, shard_id, bucket_info.layout.current_index, nullptr /* no RGWBucketInfo */, dpp);
+  int ret = bs.init(bucket_info.bucket, shard_id,
+                   bucket_info.layout.current_index,
+                   std::nullopt, nullptr /* no RGWBucketInfo */, dpp);
   if (ret < 0) {
     ldpp_dout(dpp, 5) << "bs.init() returned ret=" << ret << dendl;
     return ret;
index 60f741b6f17ff3bd6279941fa67e5b7968cdc8d9..f3d7cebe5fdcdb875c898422f3880f212c7f97d0 100644 (file)
@@ -648,7 +648,7 @@ public:
 
     explicit BucketShard(RGWRados *_store) : store(_store), shard_id(-1) {}
     int init(const rgw_bucket& _bucket, const rgw_obj& obj, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
-    int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
+    int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, std::optional<rgw::bucket_index_layout_generation> target_layout, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
     int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj);
     int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
   };
index 412ef8c1c68fe5600a95a4d43f941c18e3b999af..b61307c05e0b8ea293816dffb658401178c52343 100644 (file)
@@ -64,7 +64,6 @@ class BucketReshardShard {
   rgw::sal::RadosStore* store;
   const RGWBucketInfo& bucket_info;
   int num_shard;
-  const rgw::bucket_index_layout_generation& target_layout;
   RGWRados::BucketShard bs;
   vector<rgw_cls_bi_entry> entries;
   map<RGWObjCategory, rgw_bucket_category_stats> stats;
@@ -106,14 +105,14 @@ class BucketReshardShard {
 public:
   BucketReshardShard(const DoutPrefixProvider *dpp, 
                      rgw::sal::RadosStore *_store, const RGWBucketInfo& _bucket_info,
-                     int _num_shard, const rgw::bucket_index_layout_generation& _target_layout,
-                     deque<librados::AioCompletion *>& _completions) :
-    store(_store), bucket_info(_bucket_info), target_layout(_target_layout), bs(store->getRados()),
+                     int _num_shard, deque<librados::AioCompletion *>& _completions) :
+    store(_store), bucket_info(_bucket_info), bs(store->getRados()),
     aio_completions(_completions)
   {
-    num_shard = (target_layout.layout.normal.num_shards > 0 ? _num_shard : -1);
+    num_shard = (bucket_info.layout.target_index->layout.normal.num_shards > 0 ? _num_shard : -1);
 
-    bs.init(bucket_info.bucket, num_shard, target_layout, nullptr /* no RGWBucketInfo */, dpp);
+    bs.init(bucket_info.bucket, num_shard, bucket_info.layout.current_index,
+            bucket_info.layout.target_index, nullptr /* no RGWBucketInfo */, dpp);
 
     max_aio_completions =
       store->ctx()->_conf.get_val<uint64_t>("rgw_reshard_max_aio");
@@ -198,11 +197,11 @@ public:
                       int _num_target_shards) :
     store(_store), target_bucket_info(_target_bucket_info),
     num_target_shards(_num_target_shards)
-  { 
-    const auto& target_layout = *target_bucket_info.layout.target_index;
+  {
+
     target_shards.resize(num_target_shards);
     for (int i = 0; i < num_target_shards; ++i) {
-      target_shards[i] = new BucketReshardShard(dpp, store, target_bucket_info, i, target_layout, completions);
+      target_shards[i] = new BucketReshardShard(dpp, store, target_bucket_info, i, completions);
     }
   }
 
@@ -329,7 +328,9 @@ static int update_num_shards(rgw::sal::RadosStore *store,
                                      map<string, bufferlist>& attrs,
                                       const DoutPrefixProvider *dpp)
 {
-
+  if (!bucket_info.layout.target_index) {
+    bucket_info.layout.target_index.emplace();
+  }
   bucket_info.layout.target_index->layout.normal.num_shards = new_num_shards;
 
   bucket_info.layout.resharding = rgw::BucketReshardState::None;
@@ -402,7 +403,7 @@ public:
       }
       set_status(rgw::BucketReshardState::None, dpp);
     }
-  } 
+  }
 
   int start() {
     int ret = set_status(rgw::BucketReshardState::InProgress, dpp);
@@ -572,13 +573,9 @@ 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) {
-        if (ret == -ENOENT && i < (num_source_shards - 1)) {
-          continue;
-        } else {
-          derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
-          return ret;
-        }
+      if (ret < 0 && ret == -ENOENT) {
+        derr << "ERROR: bi_list(): " << cpp_strerror(-ret) << dendl;
+        return ret;
       }
 
       for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
@@ -739,7 +736,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(dpp, bucket_info, std::nullopt);
+  int ret2 = store->svc()->bi->clean_index(dpp, bucket_info, bucket_info.layout.target_index->gen);
   if (ret2 < 0) {
     ldpp_dout(dpp, -1) << "Error: " << __func__ <<
       " failed to clean up shards from failed incomplete resharding; " <<
index 9f21f13b6de1f78bdae6209c9eeafc43cc9bc8e2..9e890a67b6fe915384502e3009e51ab09df9d880 100644 (file)
@@ -796,7 +796,7 @@ int RadosBucket::purge_instance(const DoutPrefixProvider* dpp)
   for (int i = 0; i < max_shards; i++) {
     RGWRados::BucketShard bs(store->getRados());
     int shard_id = (info.layout.current_index.layout.normal.num_shards > 0  ? i : -1);
-    int ret = bs.init(info.bucket, shard_id, info.layout.current_index, nullptr, dpp);
+    int ret = bs.init(info.bucket, shard_id, info.layout.current_index, std::nullopt, nullptr, dpp);
     if (ret < 0) {
       cerr << "ERROR: bs.init(bucket=" << info.bucket << ", shard=" << shard_id
            << "): " << cpp_strerror(-ret) << std::endl;
index 446b50b465d3280c43615cd9c91bb6c9bcb3e0c0..503de8d22fac927c8b57cfa80174379783e40c6a 100644 (file)
@@ -211,15 +211,16 @@ 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,
-                                                      uint64_t gen_id,
+                                                      std::optional<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;
   } else {
     char buf[bucket_oid_base.size() + 64];
-    if (gen_id != 0) {
+    if (gen_id) {
       snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id);
       (*bucket_obj) = buf;
          ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl;
@@ -294,7 +295,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const DoutPrefixProvider *d
 int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const DoutPrefixProvider *dpp,
                                                      const RGWBucketInfo& bucket_info,
                                                      int shard_id,
-                                                     const rgw::bucket_index_layout_generation& target_layout,
+                                                     uint32_t num_shards,
+                                                     std::optional<uint64_t> gen,
                                                      RGWSI_RADOS::Obj *bucket_obj)
 {
   RGWSI_RADOS::Pool index_pool;
@@ -308,8 +310,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const DoutPrefixProvider *d
 
   string oid;
 
-  get_bucket_index_object(bucket_oid_base, target_layout.layout.normal.num_shards,
-                          shard_id, target_layout.gen, &oid);
+  get_bucket_index_object(bucket_oid_base, num_shards,
+                          shard_id, gen, &oid);
 
   *bucket_obj = svc.rados->obj(index_pool, oid);
 
index 91ab953b43e1ac990ccf0839305d2189061b347a..b927eb37566c478189ac95610ea2c6284bd4f9d5 100644 (file)
@@ -52,11 +52,12 @@ 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,
-                               uint64_t gen_id,
-                               std::string *bucket_obj);
-  int get_bucket_index_object(const std::string& bucket_oid_base, const std::string& obj_key,
+                               std::optional<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,
-                              std::string *bucket_obj, int *shard_id);
+                              std::string* bucket_obj, int* shard_id);
 
   int cls_bucket_head(const DoutPrefixProvider *dpp,
                      const RGWBucketInfo& bucket_info,
@@ -122,7 +123,8 @@ public:
   int open_bucket_index_shard(const DoutPrefixProvider *dpp,
                               const RGWBucketInfo& bucket_info,
                               int shard_id,
-                              const rgw::bucket_index_layout_generation& idx_layout,
+                              uint32_t num_shards,
+                              std::optional<uint64_t> gen,
                               RGWSI_RADOS::Obj *bucket_obj);
 
   int open_bucket_index(const DoutPrefixProvider *dpp,