]> 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)
committerCasey Bodley <cbodley@redhat.com>
Thu, 4 Feb 2021 22:19:46 +0000 (17:19 -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/services/svc_bi_rados.cc
src/rgw/services/svc_bi_rados.h

index 05f4fd47ccd0b0a6cadb3184019918f9f4aa901f..df670a2d8008f5b30b57907d0be92c795bf7898d 100644 (file)
@@ -6598,7 +6598,7 @@ next:
     int i = (specified_shard_id ? shard_id : 0);
     for (; i < max_shards; i++) {
       RGWRados::BucketShard bs(store->getRados());
-      int ret = bs.init(bucket, i, index, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket, i, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
       marker.clear();
 
       if (ret < 0) {
@@ -6662,7 +6662,7 @@ next:
 
     for (int i = 0; i < max_shards; i++) {
       RGWRados::BucketShard bs(store->getRados());
-      int ret = bs.init(bucket, i, index, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket, i, 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 bf751eb3b386a4a6fa43d41fd05604c3848a0812..178a402780d9fb2ab47e94bb9d6a57c28d5c4514 100644 (file)
@@ -1628,7 +1628,8 @@ static int purge_bucket_instance(rgw::sal::RGWRadosStore *store, const RGWBucket
   int max_shards = index.layout.normal.num_shards;
   for (int i = 0; i < max_shards; i++) {
     RGWRados::BucketShard bs(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 406c7207db7891b9e3a682ecd9d0d3584be7215a..ec44a4d836fd23b84ec32716b69415a84e8ec625 100644 (file)
@@ -2665,9 +2665,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;
@@ -2685,10 +2686,16 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
 
   string oid;
 
-  ret = store->svc.bi_rados->open_bucket_index_shard(*bucket_info_p, shard_id, idx_layout, &bucket_obj);
+  if (target_layout) {
+    ret = store->svc.bi_rados->open_bucket_index_shard(*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(*bucket_info_p, shard_id, current_layout.layout.normal.num_shards,
+                                                      current_layout.gen, &bucket_obj);
+  }
   if (ret < 0) {
-    ldout(store->ctx(), 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
-    return ret;
+  ldout(store->ctx(), 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
+  return ret;
   }
   ldout(store->ctx(), 20) << " bucket index oid: " << bucket_obj.get_raw_obj() << dendl;
 
@@ -2713,12 +2720,12 @@ int RGWRados::BucketShard::init(const RGWBucketInfo& bucket_info,
   return 0;
 }
 
-int RGWRados::BucketShard::init(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& target_layout, int sid)
+int RGWRados::BucketShard::init(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(bucket_info, shard_id, target_layout, &bucket_obj);
+  int ret = store->svc.bi_rados->open_bucket_index_shard(bucket_info, shard_id, current_layout.layout.normal.num_shards, std::nullopt, &bucket_obj);
   if (ret < 0) {
     ldout(store->ctx(), 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
     return ret;
@@ -8131,7 +8138,8 @@ int RGWRados::bi_remove(BucketShard& bs)
 int RGWRados::bi_list(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, int shard_id, const string& filter_obj, const string& marker, uint32_t max, 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) {
     ldout(cct, 5) << "bs.init() returned ret=" << ret << dendl;
     return ret;
index 8fe4bc393025e66c8c32d14743c293ebadb70b59..67a843a931366d4cfa59a2f7370b07b842afc9e6 100644 (file)
@@ -690,8 +690,12 @@ public:
     RGWSI_RADOS::Obj bucket_obj;
 
     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, const rgw_obj& obj,
+             RGWBucketInfo* out, const DoutPrefixProvider *dpp);
+    int init(const rgw_bucket& _bucket, int sid,
+             const rgw::bucket_index_layout_generation& current_layout,
+             std::optional<rgw::bucket_index_layout_generation> target_layout,
+             RGWBucketInfo* out, const DoutPrefixProvider *dpp);
     int init(const RGWBucketInfo& bucket_info, const rgw_obj& obj);
     int init(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
   };
index a2889bae171903c153b3b26a89a57c31e28a44b3..1e99c067216e3cc9ff1edee704d92a1ab3f7d714 100644 (file)
@@ -62,7 +62,6 @@ class BucketReshardShard {
   rgw::sal::RGWRadosStore *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;
@@ -104,14 +103,14 @@ class BucketReshardShard {
 public:
   BucketReshardShard(const DoutPrefixProvider *dpp, 
                      rgw::sal::RGWRadosStore *_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");
@@ -196,11 +195,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);
     }
   }
 
@@ -324,7 +323,9 @@ static int update_num_shards(rgw::sal::RGWRadosStore *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;
@@ -397,7 +398,7 @@ public:
       }
       set_status(rgw::BucketReshardState::None, dpp);
     }
-  } 
+  }
 
   int start() {
     int ret = set_status(rgw::BucketReshardState::InProgress, dpp);
@@ -557,13 +558,9 @@ int RGWBucketReshard::do_reshard(int num_shards,
     while (is_truncated) {
       entries.clear();
       ret = store->getRados()->bi_list(dpp, bucket_info, i, string(), 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) {
@@ -725,7 +722,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, std::nullopt);
+  int ret2 = store->svc()->bi->clean_index(bucket_info, bucket_info.layout.target_index->gen);
   if (ret2 < 0) {
     lderr(store->ctx()) << "Error: " << __func__ <<
       " failed to clean up shards from failed incomplete resharding; " <<
index 3ec7e7b8eb9889953239530c00f3e57e4524e92e..778a005a2df4f36a874c7e286d98241d9a60f725 100644 (file)
@@ -204,15 +204,16 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info,
 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;
@@ -285,7 +286,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
 
 int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(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;
@@ -299,8 +301,8 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket
 
   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 918697ad035a869a3ad137581ab02a0623f560ce..1fbfc7b6658468bf77802e6fbbfa26325ece02a3 100644 (file)
@@ -49,7 +49,7 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex
   void 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);
   int get_bucket_index_object(const string& bucket_oid_base, const string& obj_key,
                               uint32_t num_shards, rgw::BucketHashType hash_type,
@@ -115,7 +115,8 @@ public:
 
   int open_bucket_index_shard(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 RGWBucketInfo& bucket_info,