]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cls_bucket_list_(un)ordered should clear results collection 36163/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Tue, 3 Mar 2020 16:18:11 +0000 (11:18 -0500)
committerJ. Eric Ivancich <ivancich@redhat.com>
Mon, 20 Jul 2020 14:02:38 +0000 (10:02 -0400)
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>
(cherry picked from commit c52039a9e8a49f3a29e2d2ee80e50d7b1b441842)

Conflicts:
    src/rgw/rgw_admin.cc
    src/rgw/rgw_rados.cc

src/rgw/rgw_rados.cc

index a6d3ad67e84a86fe087bd5e19e98bc6a2ad8792d..537e2386350a332a382be83a2e00429f2b37458e 100644 (file)
@@ -2675,6 +2675,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,
@@ -5022,13 +5024,16 @@ int RGWRados::transition_obj(RGWObjectCtx& obj_ctx,
 
 int RGWRados::check_bucket_empty(RGWBucketInfo& bucket_info)
 {
+  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,
@@ -5038,15 +5043,17 @@ int RGWRados::check_bucket_empty(RGWBucketInfo& bucket_info)
                                      ent_list,
                                      &is_truncated,
                                      &marker);
-    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);
 
@@ -9212,6 +9219,8 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
     ", list_versions=" << list_versions <<
     ", expansion_factor=" << expansion_factor << dendl;
 
+  m.clear();
+
   librados::IoCtx index_ctx;
   // key   - oid (for different shards if there is any)
   // value - list result for the corresponding oid (shard), it is filled by
@@ -9388,6 +9397,7 @@ int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
     " start " << start.name << "[" << start.instance <<
     "] num_entries " << num_entries << dendl;
 
+  ent_list.clear();
   static MultipartMetaFilter multipart_meta_filter;
 
   *is_truncated = false;