From 0b89f6b44bd833fc139f83da43faed14ee614bd6 Mon Sep 17 00:00:00 2001 From: Shilpa Jagannath Date: Tue, 1 Sep 2020 23:55:42 +0530 Subject: [PATCH] rgw: code organization fixes and error handling Signed-off-by: Shilpa Jagannath --- src/rgw/rgw_bucket.cc | 3 +- src/rgw/rgw_reshard.cc | 6 ++-- src/rgw/services/svc_bi_rados.cc | 49 +++++++++++++++++++------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 4b9a359005af8..7830e5105f24c 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -1628,8 +1628,7 @@ 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, index, 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_reshard.cc b/src/rgw/rgw_reshard.cc index 2498c685833ac..0979b3863a333 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -344,7 +344,7 @@ int RGWBucketReshard::set_target_layout(int new_num_shards, const DoutPrefixProv { int ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::InProgress, dpp); if (ret < 0) { - cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl; + lderr(store->ctx()) << "ERROR: failed to store updated bucket instance info: " << dendl; return ret; } return ::set_target_layout(store, new_num_shards, bucket_info, dpp); @@ -710,7 +710,7 @@ int RGWBucketReshard::execute(int num_shards, int max_op_entries, // 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 + // at this point since all we're using a best effort to remove old // shard objects ret = store->svc()->bi->clean_index(bucket_info, prev_index); @@ -752,7 +752,7 @@ error_out: ret = RGWBucketReshard::set_reshard_status(rgw::BucketReshardState::None, dpp); if (ret < 0) { - cerr << "ERROR: failed to store updated bucket instance info: " << cpp_strerror(-ret) << std::endl; + lderr(store->ctx()) << "ERROR: failed to store updated bucket instance info: " << dendl; return ret; } diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 453932224a0c7..22f9fd1ece6a9 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -112,6 +112,17 @@ int RGWSI_BucketIndex_RADOS::open_bucket_index(const RGWBucketInfo& bucket_info, return 0; } +static char bucket_obj_with_generation(char *buf, size_t len, const string& bucket_oid_base, uint64_t gen_id, + uint32_t shard_id) +{ + return snprintf(buf, len, "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); +} + +static char bucket_obj_without_generation(char *buf, size_t len, const string& bucket_oid_base, uint32_t shard_id) +{ + return snprintf(buf, len, "%s.%d", bucket_oid_base.c_str(), shard_id); +} + static void get_bucket_index_objects(const string& bucket_oid_base, uint32_t num_shards, uint64_t gen_id, map *_bucket_objects, @@ -125,25 +136,23 @@ static void get_bucket_index_objects(const string& bucket_oid_base, if (shard_id < 0) { for (uint32_t i = 0; i < num_shards; ++i) { if (gen_id) { - snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, i); - bucket_objects[i] = buf; - } else { - snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), i); - bucket_objects[i] = buf; - } + bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, i); + } else { + bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, i); + } + bucket_objects[i] = buf; } } else { - if ((uint32_t)shard_id > num_shards) { + if (static_cast(shard_id) > num_shards) { return; } else { - if (gen_id) { - snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); - bucket_objects[shard_id] = buf; - } else { - // for backward compatibility, gen_id(0) will not be added in the object name - snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id); - bucket_objects[shard_id] = buf; - } + if (gen_id) { + bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id); + } else { + // for backward compatibility, gen_id(0) will not be added in the object name + bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id); + } + bucket_objects[shard_id] = buf; } } } @@ -166,7 +175,7 @@ static void get_bucket_instance_ids(const RGWBucketInfo& bucket_info, (*result)[i] = plain_id + buf; } } else { - if ((uint32_t)shard_id > bucket_info.layout.current_index.layout.normal.num_shards) { + if (static_cast(shard_id) > bucket_info.layout.current_index.layout.normal.num_shards) { return; } snprintf(buf, sizeof(buf), ":%d", shard_id); @@ -212,12 +221,12 @@ void RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_b } else { char buf[bucket_oid_base.size() + 64]; if (gen_id) { - snprintf(buf, sizeof(buf), "%s.%" PRIu64 ".%d", bucket_oid_base.c_str(), gen_id, shard_id); + bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, shard_id); (*bucket_obj) = buf; ldout(cct, 10) << "bucket_obj is " << (*bucket_obj) << dendl; } else { // for backward compatibility, gen_id(0) will not be added in the object name - snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), shard_id); + bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, shard_id); (*bucket_obj) = buf; } } @@ -240,9 +249,9 @@ int RGWSI_BucketIndex_RADOS::get_bucket_index_object(const string& bucket_oid_ba uint32_t sid = bucket_shard_index(obj_key, num_shards); 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); + bucket_obj_with_generation(buf, sizeof(buf), bucket_oid_base, gen_id, sid); } else { - snprintf(buf, sizeof(buf), "%s.%d", bucket_oid_base.c_str(), sid); + bucket_obj_without_generation(buf, sizeof(buf), bucket_oid_base, sid); } (*bucket_obj) = buf; if (shard_id) { -- 2.39.5