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=7f82bf17f9b78be20b78882dc9f04b01be1560de;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 05f4fd47ccd0b..df670a2d8008f 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -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; diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index bf751eb3b386a..178a402780d9f 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -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; 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 406c7207db789..ec44a4d836fd2 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 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 *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; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 8fe4bc393025e..67a843a931366 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 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); }; diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index a2889bae17190..1e99c067216e3 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -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 entries; map 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& _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"); @@ -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& 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; " << diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 3ec7e7b8eb988..778a005a2df4f 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -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 _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 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); diff --git a/src/rgw/services/svc_bi_rados.h b/src/rgw/services/svc_bi_rados.h index 918697ad035a8..1fbfc7b665846 100644 --- a/src/rgw/services/svc_bi_rados.h +++ b/src/rgw/services/svc_bi_rados.h @@ -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 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 gen, RGWSI_RADOS::Obj *bucket_obj); int open_bucket_index(const RGWBucketInfo& bucket_info,