From 678b71f587a074af0731202cb058590ea8aff575 Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Tue, 14 Jul 2020 13:03:31 +0530 Subject: [PATCH] rgw: - allow clean_index() to take const bucket_index_layout_generation& - fix bi_get() to get objects after being resharded Signed-off-by: Shilpa Jagannath --- src/rgw/rgw_admin.cc | 2 +- src/rgw/rgw_rados.cc | 2 +- src/rgw/rgw_reshard.cc | 27 ++++++++++++++------------- src/rgw/services/svc_bi.h | 2 +- src/rgw/services/svc_bi_rados.cc | 17 +++++++++++------ src/rgw/services/svc_bi_rados.h | 4 ++-- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 05f4fd47ccd0b..723c8a81a5780 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -6609,7 +6609,7 @@ next: do { entries.clear(); ret = store->getRados()->bi_list(bs, object, marker, max_entries, &entries, &is_truncated); - if (ret < 0) { + if (ret < 0) { cerr << "ERROR: bi_list(): " << cpp_strerror(-ret) << std::endl; return -ret; } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 8aaa92b7010b5..424de7ef8df5d 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2291,7 +2291,7 @@ int RGWRados::create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket, /* only remove it if it's a different bucket instance */ if (orig_info.bucket.bucket_id != bucket.bucket_id) { - int r = svc.bi->clean_index(info, info.layout.current_index.gen); + int r = svc.bi->clean_index(info, info.layout.current_index); if (r < 0) { ldout(cct, 0) << "WARNING: could not remove bucket index (r=" << r << ")" << dendl; } diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 9f80166625d30..111b32b502662 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -644,6 +644,7 @@ int RGWBucketReshard::do_reshard(int num_shards, } //overwrite current_index for the next reshard process + const auto prev_index = bucket_info.layout.current_index; 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; @@ -658,6 +659,18 @@ int RGWBucketReshard::do_reshard(int num_shards, return ret; } + // resharding successful, so remove old bucket index shards; use + // best effort and don't report out an error; the lock isn't needed + // at this point since all we're using a best effor to to remove old + // shard objects + + ret = store->svc()->bi->clean_index(bucket_info, prev_index); + if (ret < 0) { + lderr(store->ctx()) << "Error: " << __func__ << + " failed to clean up old shards; " << + "RGWRados::clean_bucket_index returned " << ret << dendl; +} + return 0; // NB: some error clean-up is done by ~BucketInfoReshardUpdate } // RGWBucketReshard::do_reshard @@ -704,18 +717,6 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries, reshard_lock.unlock(); - // resharding successful, so remove old bucket index shards; use - // best effort and don't report out an error; the lock isn't needed - // at this point since all we're using a best effor to to remove old - // shard objects - - ret = store->svc()->bi->clean_index(bucket_info, bucket_info.layout.current_index.gen); - if (ret < 0) { - lderr(store->ctx()) << "Error: " << __func__ << - " failed to clean up old shards; " << - "RGWRados::clean_bucket_index returned " << ret << dendl; - } - ldout(store->ctx(), 1) << __func__ << " INFO: reshard of bucket \"" << bucket_info.bucket.name << "\" completed successfully" << dendl; @@ -730,7 +731,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, bucket_info.layout.target_index->gen); + int ret2 = store->svc()->bi->clean_index(bucket_info, bucket_info.layout.current_index); 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.h b/src/rgw/services/svc_bi.h index 962471162d059..746e5f0cbdc31 100644 --- a/src/rgw/services/svc_bi.h +++ b/src/rgw/services/svc_bi.h @@ -30,7 +30,7 @@ public: virtual ~RGWSI_BucketIndex() {} virtual int init_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0; - virtual int clean_index(RGWBucketInfo& bucket_info, uint64_t gen) = 0; + virtual int clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0; virtual int read_stats(const RGWBucketInfo& bucket_info, RGWBucketEnt *stats, diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 6e5f84c3b080a..453932224a0c7 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -225,7 +225,7 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_base, const string& obj_key, uint32_t num_shards, rgw::BucketHashType hash_type, - string *bucket_obj, int *shard_id) + uint64_t gen_id, string *bucket_obj, int *shard_id) { int r = 0; switch (hash_type) { @@ -238,8 +238,12 @@ int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_ba } } else { uint32_t sid = bucket_shard_index(obj_key, num_shards); - char buf[bucket_oid_base.size() + 32]; - snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid); + char buf[bucket_oid_base.size() + 64]; + if (gen_id) { + snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, sid); + } else { + snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid); + } (*bucket_obj) = buf; if (shard_id) { *shard_id = (int)sid; @@ -271,7 +275,7 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index_shard(const RGWBucketInfo& bucket string oid; ret = get_bucket_index_object(bucket_oid_base, obj_key, bucket_info.layout.current_index.layout.normal.num_shards, - bucket_info.layout.current_index.layout.normal.hash_type, &oid, shard_id); + bucket_info.layout.current_index.layout.normal.hash_type, bucket_info.layout.current_index.gen, &oid, shard_id); if (ret < 0) { ldout(cct, 10) << "get_bucket_index_object() returned ret=" << ret << dendl; return ret; @@ -357,7 +361,7 @@ int RGWSI_BucketIndex_RADOS::init_index(RGWBucketInfo& bucket_info, const rgw::b } -int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, uint64_t gen) +int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) { RGWSI_RADOS::Pool index_pool; @@ -370,7 +374,8 @@ int RGWSI_BucketIndex_RADOS::clean_index(RGWBucketInfo& bucket_info, uint64_t ge dir_oid.append(bucket_info.bucket.bucket_id); std::map bucket_objs; - get_bucket_index_objects(dir_oid, bucket_info.layout.current_index.layout.normal.num_shards, gen, &bucket_objs); + get_bucket_index_objects(dir_oid, idx_layout.layout.normal.num_shards, + idx_layout.gen, &bucket_objs); return CLSRGWIssueBucketIndexClean(index_pool.ioctx(), bucket_objs, diff --git a/src/rgw/services/svc_bi_rados.h b/src/rgw/services/svc_bi_rados.h index cdc243b82569a..b46c587a9de75 100644 --- a/src/rgw/services/svc_bi_rados.h +++ b/src/rgw/services/svc_bi_rados.h @@ -53,7 +53,7 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex 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, - string *bucket_obj, int *shard_id); + uint64_t gen_id, string *bucket_obj, int *shard_id); int cls_bucket_head(const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, @@ -94,7 +94,7 @@ public: } int init_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout); - int clean_index(RGWBucketInfo& bucket_info, uint64_t gen); + int clean_index(RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout); /* RADOS specific */ -- 2.39.5