From c52039a9e8a49f3a29e2d2ee80e50d7b1b441842 Mon Sep 17 00:00:00 2001 From: "J. Eric Ivancich" Date: Tue, 3 Mar 2020 11:18:11 -0500 Subject: [PATCH] rgw: cls_bucket_list_(un)ordered should clear results collection Each call to cls_bucket_list_(un)ordered should have an empty collection to populate with results. Rather than rely on the caller to insure this, it's more reliable to have these functions do the clear. Additionally in some cases, a reserve call was added to the collection to pre-allocate the space needed for the expected number of results. This will potentially result in fewer re-allocations plus copies. Signed-off-by: J. Eric Ivancich --- src/rgw/rgw_admin.cc | 2 ++ src/rgw/rgw_rados.cc | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index ff7da8e27c374..99285b4444346 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -6762,6 +6762,8 @@ next: uint16_t expansion_factor = 1; while (is_truncated) { RGWRados::ent_map_t result; + result.reserve(NUM_ENTRIES); + int r = store->getRados()->cls_bucket_list_ordered( bucket_info, RGW_NO_SHARD, marker, empty_prefix, empty_delimiter, diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 89faeaaa6b202..3f6c32c8d4867 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2063,6 +2063,8 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max_p, while (truncated && count <= max) { std::vector ent_list; + ent_list.reserve(read_ahead); + int r = store->cls_bucket_list_unordered(target->get_bucket_info(), shard_id, cur_marker, @@ -4476,13 +4478,16 @@ int RGWRados::transition_obj(RGWObjectCtx& obj_ctx, int RGWRados::check_bucket_empty(RGWBucketInfo& bucket_info, optional_yield y) { + constexpr uint NUM_ENTRIES = 1000u; + rgw_obj_index_key marker; string prefix; bool is_truncated; do { std::vector ent_list; - constexpr uint NUM_ENTRIES = 1000u; + ent_list.reserve(NUM_ENTRIES); + int r = cls_bucket_list_unordered(bucket_info, RGW_NO_SHARD, marker, @@ -4493,15 +4498,17 @@ int RGWRados::check_bucket_empty(RGWBucketInfo& bucket_info, optional_yield y) &is_truncated, &marker, y); - if (r < 0) + if (r < 0) { return r; + } string ns; for (auto const& dirent : ent_list) { rgw_obj_key obj; - if (rgw_obj_key::oid_to_key_in_ns(dirent.key.name, &obj, ns)) + if (rgw_obj_key::oid_to_key_in_ns(dirent.key.name, &obj, ns)) { return -ENOTEMPTY; + } } } while (is_truncated); @@ -8200,6 +8207,8 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info, ", list_versions=" << list_versions << ", expansion_factor=" << expansion_factor << dendl; + m.clear(); + RGWSI_RADOS::Pool index_pool; // key - oid (for different shards if there is any) // value - list result for the corresponding oid (shard), it is filled by @@ -8422,7 +8431,7 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info, count << ", which is truncated" << dendl; } - if (last_entry_visited != nullptr) { + if (last_entry_visited != nullptr && last_entry) { // since we'll not need this any more, might as well move it... *last_entry = std::move(last_entry_visited->key); ldout(cct, 20) << "RGWRados::" << __func__ << @@ -8451,6 +8460,7 @@ int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info, " start_after " << start_after.name << "[" << start_after.instance << "] num_entries " << num_entries << dendl; + ent_list.clear(); static MultipartMetaFilter multipart_meta_filter; *is_truncated = false; -- 2.39.5