]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: make RGWBucketInfo non-const in functions using guard_reshard()
authorShilpa Manjarabad Jagannath <smanjara@smanjara.remote.csb>
Thu, 9 Jul 2020 07:18:52 +0000 (12:48 +0530)
committerCasey Bodley <cbodley@redhat.com>
Fri, 27 May 2022 19:47:31 +0000 (15:47 -0400)
 - remove unused 'instance_id' from cls_rgw_reshard_entry
 - other minor fixes

Signed-off-by: Shilpa Manjarabad Jagannath <smanjara@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_reshard.cc
src/rgw/rgw_reshard.h
src/rgw/rgw_sal_rados.cc

index 07321701c4e3339a55f6a4be3b12c59687578cff..23378cd834083cf1af3cc746b643ab4a3aa345a4 100644 (file)
@@ -7253,7 +7253,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 ret = bs.init(bucket->get_key(), shard_id, index, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket->get_key(), i, index, nullptr /* no RGWBucketInfo */, dpp());
       marker.clear();
 
       if (ret < 0) {
@@ -7318,7 +7318,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, std::nullopt, nullptr /* no RGWBucketInfo */, dpp());
+      int ret = bs.init(bucket->get_key(), shard_id, index, nullptr /* no RGWBucketInfo */, dpp());
       if (ret < 0) {
         cerr << "ERROR: bs.init(bucket=" << bucket << ", shard=" << i << "): " << cpp_strerror(-ret) << std::endl;
         return -ret;
index 2dfcb371db7b27f47ab727a3246b2ba499896f1b..4a58c3411d7aff0bccd71ef471818bf894a70f0a 100644 (file)
@@ -1326,7 +1326,7 @@ static int purge_bucket_instance(rgw::sal::Store* store, const RGWBucketInfo& bu
   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,
-                      std::nullopt, nullptr, dpp);
+                      nullptr, dpp);
     if (ret < 0) {
       cerr << "ERROR: bs.init(bucket=" << bucket_info.bucket << ", shard=" << i
            << "): " << cpp_strerror(-ret) << std::endl;
index 7317789b528b289433186549cc4f0bae48256405..d22724a663b80fcc6620abca3c09a7a882ae47e3 100644 (file)
@@ -2620,7 +2620,9 @@ done_err:
  * fixes an issue where head objects were supposed to have a locator created, but ended
  * up without one
  */
-int RGWRados::fix_tail_obj_locator(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, rgw_obj_key& key, bool fix, bool *need_fix, optional_yield y)
+int RGWRados::fix_tail_obj_locator(const DoutPrefixProvider *dpp,
+                                   RGWBucketInfo& bucket_info, rgw_obj_key& key,
+                                   bool fix, bool *need_fix, optional_yield y)
 {
   std::unique_ptr<rgw::sal::Bucket> bucket;
   store->get_bucket(nullptr, bucket_info, &bucket);
@@ -2730,8 +2732,7 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
 }
 
 int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
-                               int sid, const rgw::bucket_index_layout_generation& current_layout,
-                               std::optional<rgw::bucket_index_layout_generation> target_layout,
+                               int sid, std::optional<rgw::bucket_index_layout_generation> idx_layout,
                                RGWBucketInfo* bucket_info_out,
                                const DoutPrefixProvider *dpp)
 {
@@ -2751,13 +2752,9 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket,
 
   string oid;
 
-  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);
-  }
+  ret = store->svc.bi_rados->open_bucket_index_shard(dpp, *bucket_info_p, shard_id, idx_layout->layout.normal.num_shards,
+                                                    idx_layout->gen, &bucket_obj);
+
   if (ret < 0) {
     ldpp_dout(dpp, 0) << "ERROR: open_bucket_index_shard() returned ret=" << ret << dendl;
     return ret;
@@ -5056,9 +5053,8 @@ int RGWRados::bucket_set_reshard(const DoutPrefixProvider *dpp, const RGWBucketI
   return CLSRGWIssueSetBucketResharding(index_pool.ioctx(), bucket_objs, entry, cct->_conf->rgw_bucket_index_max_aio)();
 }
 
-int RGWRados::defer_gc(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, optional_yield y)
+int RGWRados::defer_gc(const DoutPrefixProvider *dpp, RGWObjectCtx* rctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, optional_yield y)
 {
-  RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
   std::string oid, key;
   get_obj_bucket_and_oid_loc(obj->get_obj(), oid, key);
   if (!rctx)
@@ -5921,11 +5917,11 @@ int RGWRados::Object::prepare_atomic_modification(const DoutPrefixProvider *dpp,
  * bl: the contents of the attr
  * Returns: 0 on success, -ERR# otherwise.
  */
-int RGWRados::set_attr(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, const char *name, bufferlist& bl)
+int RGWRados::set_attr(const DoutPrefixProvider *dpp, RGWObjectCtx* rctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, const char *name, bufferlist& bl)
 {
   map<string, bufferlist> attrs;
   attrs[name] = bl;
-  return set_attrs(dpp, ctx, bucket_info, obj, attrs, NULL, null_yield);
+  return set_attrs(dpp, rctx, bucket_info, obj, attrs, NULL, null_yield);
 }
 
 int RGWRados::set_attrs(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* src_obj,
@@ -7557,7 +7553,7 @@ void RGWRados::gen_rand_obj_instance_name(rgw_obj *target_obj)
   gen_rand_obj_instance_name(&target_obj->key);
 }
 
-int RGWRados::get_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh)
+int RGWRados::get_olh(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh)
 {
   map<string, bufferlist> attrset;
 
@@ -7609,7 +7605,7 @@ void RGWRados::check_pending_olh_entries(const DoutPrefixProvider *dpp,
   }
 }
 
-int RGWRados::remove_olh_pending_entries(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, map<string, bufferlist>& pending_attrs)
+int RGWRados::remove_olh_pending_entries(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, map<string, bufferlist>& pending_attrs)
 {
   rgw_rados_ref ref;
   int r = get_obj_head_ref(dpp, bucket_info, olh_obj, &ref);
@@ -7648,7 +7644,7 @@ int RGWRados::follow_olh(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_in
   rgw_filter_attrset(state->attrset, RGW_ATTR_OLH_PENDING_PREFIX, &pending_entries);
 
   map<string, bufferlist> rm_pending_entries;
-  check_pending_olh_entries(dpp,pending_entries, &rm_pending_entries);
+  check_pending_olh_entries(dpp, pending_entries, &rm_pending_entries);
 
   if (!rm_pending_entries.empty()) {
     int ret = remove_olh_pending_entries(dpp, bucket_info, *state, olh_obj->get_obj(), rm_pending_entries);
@@ -8299,7 +8295,7 @@ int RGWRados::bi_list(const DoutPrefixProvider *dpp,
   BucketShard bs(this);
   int ret = bs.init(bucket_info.bucket, shard_id,
                    bucket_info.layout.current_index,
-                   std::nullopt, nullptr /* no RGWBucketInfo */, dpp);
+                   nullptr /* no RGWBucketInfo */, dpp);
   if (ret < 0) {
     ldpp_dout(dpp, 5) << "bs.init() returned ret=" << ret << dendl;
     return ret;
index e39bf06d5c78dc14d477dade8047feb3aa2cb8f9..cd49a467045919fcc9d46ad7798c693e10ee293c 100644 (file)
@@ -647,8 +647,11 @@ 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, std::optional<rgw::bucket_index_layout_generation> target_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,
+            std::optional<rgw::bucket_index_layout_generation> current_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);
 
@@ -1245,7 +1248,7 @@ public:
    * bl: the contents of the attr
    * Returns: 0 on success, -ERR# otherwise.
    */
-  int set_attr(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, const char *name, bufferlist& bl);
+  int set_attr(const DoutPrefixProvider *dpp, RGWObjectCtx* ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, const char *name, bufferlist& bl);
 
   int set_attrs(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj,
                         std::map<std::string, bufferlist>& attrs,
@@ -1330,9 +1333,9 @@ public:
                           uint64_t olh_epoch, optional_yield y, rgw_zone_set *zones_trace = nullptr);
 
   void check_pending_olh_entries(const DoutPrefixProvider *dpp, std::map<std::string, bufferlist>& pending_entries, std::map<std::string, bufferlist> *rm_pending_entries);
-  int remove_olh_pending_entries(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, std::map<std::string, bufferlist>& pending_attrs);
+  int remove_olh_pending_entries(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, std::map<std::string, bufferlist>& pending_attrs);
   int follow_olh(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, RGWObjectCtx& ctx, RGWObjState *state, rgw::sal::Object* olh_obj, rgw_obj *target);
-  int get_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh);
+  int get_olh(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh);
 
   void gen_rand_obj_instance_name(rgw_obj_key *target_key);
   void gen_rand_obj_instance_name(rgw_obj *target);
@@ -1480,7 +1483,7 @@ public:
   int list_gc_objs(int *index, std::string& marker, uint32_t max, bool expired_only, std::list<cls_rgw_gc_obj_info>& result, bool *truncated, bool& processing_queue);
   int process_gc(bool expired_only);
   bool process_expire_objects(const DoutPrefixProvider *dpp);
-  int defer_gc(const DoutPrefixProvider *dpp, void *ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, optional_yield y);
+  int defer_gc(const DoutPrefixProvider *dpp, RGWObjectCtx* ctx, RGWBucketInfo& bucket_info, rgw::sal::Object* obj, optional_yield y);
 
   int process_lc(const std::unique_ptr<rgw::sal::Bucket>& optional_bucket);
   int list_lc_progress(std::string& marker, uint32_t max_entries,
@@ -1500,7 +1503,8 @@ public:
                     librados::IoCtx& dst_ioctx,
                     const std::string& dst_oid, const std::string& dst_locator);
   int fix_head_obj_locator(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, bool copy_obj, bool remove_bad, rgw_obj_key& key);
-  int fix_tail_obj_locator(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, rgw_obj_key& key, bool fix, bool *need_fix, optional_yield y);
+  int fix_tail_obj_locator(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info,
+                           rgw_obj_key& key, bool fix, bool *need_fix, optional_yield y);
 
   int check_quota(const DoutPrefixProvider *dpp, const rgw_user& bucket_owner, rgw_bucket& bucket,
                   RGWQuota& quota, uint64_t obj_size,
index b61307c05e0b8ea293816dffb658401178c52343..75a89171174984ae69e720f834cdce9f42a106b4 100644 (file)
@@ -111,8 +111,8 @@ public:
   {
     num_shard = (bucket_info.layout.target_index->layout.normal.num_shards > 0 ? _num_shard : -1);
 
-    bs.init(bucket_info.bucket, num_shard, bucket_info.layout.current_index,
-            bucket_info.layout.target_index, nullptr /* no RGWBucketInfo */, dpp);
+    bs.init(bucket_info.bucket, num_shard, bucket_info.layout.target_index,
+            nullptr /* no RGWBucketInfo */, dpp);
 
     max_aio_completions =
       store->ctx()->_conf.get_val<uint64_t>("rgw_reshard_max_aio");
@@ -322,18 +322,18 @@ int RGWBucketReshard::clear_index_shard_reshard_status(const DoutPrefixProvider
   return 0;
 }
 
-static int update_num_shards(rgw::sal::RadosStore *store,
-                                     int new_num_shards,
-                                     RGWBucketInfo& bucket_info,
-                                     map<string, bufferlist>& attrs,
-                                      const DoutPrefixProvider *dpp)
+static int set_target_layout(rgw::sal::RadosStore *store,
+                             int new_num_shards,
+                             RGWBucketInfo& bucket_info,
+                             map<string, bufferlist>& attrs,
+                             const DoutPrefixProvider *dpp)
 {
-  if (!bucket_info.layout.target_index) {
-    bucket_info.layout.target_index.emplace();
-  }
+  assert(!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;
+  bucket_info.layout.resharding = rgw::BucketReshardState::InProgress;
 
   int ret = static_cast<rgw::sal::RadosStore*>(store)->getRados()->put_bucket_instance_info(bucket_info, true, real_time(), &attrs, dpp);
   if (ret < 0) {
@@ -344,9 +344,9 @@ static int update_num_shards(rgw::sal::RadosStore *store,
   return 0;
 }
 
-int RGWBucketReshard::update_num_shards(int new_num_shards, const DoutPrefixProvider *dpp)
+int RGWBucketReshard::set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp)
 {
-  return ::update_num_shards(store, new_num_shards, bucket_info, bucket_attrs, dpp);
+  return ::set_target_layout(store, new_num_shards, bucket_info, bucket_attrs, dpp);
 }
 
 int RGWBucketReshard::cancel(const DoutPrefixProvider *dpp)
@@ -537,6 +537,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
   // complete successfully
   BucketInfoReshardUpdate bucket_info_updater(dpp, store, bucket_info, bucket_attrs);
 
+
   int ret = bucket_info_updater.start();
   if (ret < 0) {
     ldpp_dout(dpp, 0) << __func__ << ": failed to update bucket info ret=" << ret << dendl;
@@ -658,6 +659,7 @@ int RGWBucketReshard::do_reshard(int num_shards,
 
   //overwrite current_index for the next reshard process
   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;
   ret = store->getRados()->put_bucket_instance_info(bucket_info, false, real_time(), &bucket_attrs, dpp);
   if (ret < 0) {
@@ -685,7 +687,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries,
     return ret;
   }
 
-  ret = update_num_shards(num_shards, dpp);
+  ret = set_target_layout(num_shards, dpp); //modifies existing bucket
   if (ret < 0) {
     // shard state is uncertain, but this will attempt to remove them anyway
     goto error_out;
index 02c097331f3fd21f76d8cdc5e2dffe988e513db6..c75dd169f87f259153514bc5bf7f3e2598bfe51b 100644 (file)
@@ -84,7 +84,7 @@ private:
   // allocated in at once
   static const std::initializer_list<uint16_t> reshard_primes;
 
-  int update_num_shards(int new_num_shards, const DoutPrefixProvider *dpp);
+  int set_target_layout(int new_num_shards, const DoutPrefixProvider *dpp);
   int do_reshard(int num_shards,
                 int max_entries,
                  bool verbose,
index 4ef6d9066eed122a5b76d4ca1a531fac560b94aa..23af25ae4568ee1bae661568d852d6c17f81850f 100644 (file)
@@ -800,7 +800,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, std::nullopt, nullptr, dpp);
+    int ret = bs.init(info.bucket, shard_id, info.layout.current_index, nullptr, dpp);
     if (ret < 0) {
       cerr << "ERROR: bs.init(bucket=" << info.bucket << ", shard=" << shard_id
            << "): " << cpp_strerror(-ret) << std::endl;