From 9a09634d91b146586948c8d07160505b8d957ebb Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 6 Mar 2013 19:32:21 -0800 Subject: rgw: don't iteraste through all objects when in namespace Fixes: #4363 Backport: argnaut, bobtail When listing objects in namespace don't iterate through all the objects, only go though the ones that starts with the namespace prefix Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rados.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 9675a75b63b..f413066c125 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -689,11 +689,22 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string& int count = 0; string cur_marker = marker; bool truncated; + string ns_prefix; if (bucket_is_system(bucket)) { return -EINVAL; } result.clear(); + if (!ns.empty()) { + ns_prefix = "_"; + ns_prefix += ns + "_"; + if (cur_marker < ns_prefix) { + cur_marker = ns_prefix; + } else if (cur_marker.substr(0, ns.size()) > ns_prefix) { + truncated = false; + goto done; + } + } do { std::map ent_map; @@ -707,8 +718,16 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string& string obj = eiter->first; string key = obj; - if (!rgw_obj::translate_raw_obj_to_obj_in_ns(obj, ns)) + if (!rgw_obj::translate_raw_obj_to_obj_in_ns(obj, ns)) { + if (!ns.empty()) { + /* we're not under the namespace anymore, we're done */ + truncated = false; + goto done; + } + + /* we're not under the namespace this object is in, next! */ continue; + } if (filter && !filter->filter(obj, key)) continue; @@ -732,6 +751,7 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string& } } while (truncated && count < max); +done: if (is_truncated) *is_truncated = truncated; -- cgit v1.2.1