]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: don't iterate through all objects when in namespace
authorYehuda Sadeh <yehuda@inktank.com>
Thu, 7 Mar 2013 03:32:21 +0000 (19:32 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 8 Mar 2013 14:55:03 +0000 (06:55 -0800)
Fixes: #4363
Backport: argonaut, 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 <yehuda@inktank.com>
src/rgw/rgw_rados.cc

index 9675a75b63bd76b03212b976e99bad1486c8ac49..ad5485ffe5ae40ec988876add8e9d1befd3dabe4 100644 (file)
@@ -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<string, RGWObjEnt> 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've iterated past the namespace we're searching -- done now */
+          truncated = false;
+          goto done;
+        }
+
+        /* we're not looking at 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;