]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cls_bucket_list_(un)ordered should clear results collection 33702/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Tue, 3 Mar 2020 16:18:11 +0000 (11:18 -0500)
committerJ. Eric Ivancich <ivancich@redhat.com>
Thu, 5 Mar 2020 16:39:36 +0000 (11:39 -0500)
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 <ivancich@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc

index ff7da8e27c374e4e685b458f3199217055983f0f..99285b4444346307a162e750eb406159ae1883ec 100644 (file)
@@ -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,
index 89faeaaa6b202a200f0f2105be63d63f929a463a..3f6c32c8d48673f5075ae84fcde2f2b5f88532d6 100644 (file)
@@ -2063,6 +2063,8 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max_p,
 
   while (truncated && count <= max) {
     std::vector<rgw_bucket_dir_entry> 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<rgw_bucket_dir_entry> 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;