From: Shilpa Manjarabad Jagannath Date: Mon, 6 Jul 2020 09:47:15 +0000 (+0530) Subject: rgw: target_layout to be optional X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1736cce9bc8dd37cc55fe32fc55a0e9576c091e5;p=ceph.git rgw: target_layout to be optional Signed-off-by: Shilpa Manjarabad Jagannath --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index d9b0e3f4654ef..7d2455f8ee6dc 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -7225,8 +7225,7 @@ next: int i = (specified_shard_id ? shard_id : 0); for (; i < max_shards; i++) { RGWRados::BucketShard bs(static_cast(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(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; diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index c4ec010873c1d..5345f1687f3c8 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -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(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; diff --git a/src/rgw/rgw_bucket_layout.h b/src/rgw/rgw_bucket_layout.h index 6ba752a2d1686..7839c51952046 100644 --- a/src/rgw/rgw_bucket_layout.h +++ b/src/rgw/rgw_bucket_layout.h @@ -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); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 433024a508315..51fa0e77317d4 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 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 *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; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 60f741b6f17ff..f3d7cebe5fdcd 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 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); }; diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 412ef8c1c68fe..b61307c05e0b8 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -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 entries; map 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& _completions) : - store(_store), bucket_info(_bucket_info), target_layout(_target_layout), bs(store->getRados()), + int _num_shard, deque& _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("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& 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; " << diff --git a/src/rgw/rgw_sal_rados.cc b/src/rgw/rgw_sal_rados.cc index 9f21f13b6de1f..9e890a67b6fe9 100644 --- a/src/rgw/rgw_sal_rados.cc +++ b/src/rgw/rgw_sal_rados.cc @@ -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; diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 446b50b465d32..503de8d22fac9 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -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 _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 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); diff --git a/src/rgw/services/svc_bi_rados.h b/src/rgw/services/svc_bi_rados.h index 91ab953b43e1a..b927eb37566c4 100644 --- a/src/rgw/services/svc_bi_rados.h +++ b/src/rgw/services/svc_bi_rados.h @@ -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 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 gen, RGWSI_RADOS::Obj *bucket_obj); int open_bucket_index(const DoutPrefixProvider *dpp,