]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: account common prefixes for MaxKeys in bucket listing
authorYehuda Sadeh <yehuda@inktank.com>
Thu, 17 Jul 2014 18:45:44 +0000 (11:45 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 18 Jul 2014 21:56:23 +0000 (14:56 -0700)
To be more in line with the S3 api. Beforehand we didn't account the
common prefixes towards the MaxKeys (a single common prefix counts as a
single key). Also need to adjust the marker now if it is pointing at a
common prefix.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_rados.cc

index ea33bfbc784b86de50c14b8261ea4a668b1cbd1f..383976557f6e3b5f1f3945face94c840d0f7ab2b 100644 (file)
@@ -2257,7 +2257,7 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string&
                            bool *is_truncated, RGWAccessListFilter *filter)
 {
   int count = 0;
-  bool truncated;
+  bool truncated = true;
 
   if (bucket_is_system(bucket)) {
     return -EINVAL;
@@ -2290,7 +2290,16 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string&
 
   string skip_after_delim;
 
-  do {
+  /* if marker points at a common prefix, fast forward it into its upperbound string */
+  if (!delim.empty()) {
+    int delim_pos = cur_marker.find(delim, prefix.size());
+    if (delim_pos >= 0) {
+      cur_marker = cur_marker.substr(0, delim_pos);
+      cur_marker.append(bigger_than_delim);
+    }
+  }
+
+  while (truncated && count < max) {
     if (skip_after_delim > cur_marker) {
       cur_marker = skip_after_delim;
       ldout(cct, 20) << "setting cur_marker=" << cur_marker << dendl;
@@ -2333,12 +2342,21 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string&
         int delim_pos = obj.find(delim, prefix.size());
 
         if (delim_pos >= 0) {
-          common_prefixes[obj.substr(0, delim_pos + 1)] = true;
+          string prefix_key = obj.substr(0, delim_pos + 1);
+
+          if (common_prefixes.find(prefix_key) == common_prefixes.end()) {
+            if (next_marker) {
+              *next_marker = prefix_key;
+            }
+            common_prefixes[prefix_key] = true;
 
-          skip_after_delim = obj.substr(0, delim_pos);
-          skip_after_delim.append(bigger_than_delim);
+            skip_after_delim = obj.substr(0, delim_pos);
+            skip_after_delim.append(bigger_than_delim);
 
-          ldout(cct, 20) << "skip_after_delim=" << skip_after_delim << dendl;
+            ldout(cct, 20) << "skip_after_delim=" << skip_after_delim << dendl;
+
+            count++;
+          }
 
           continue;
         }
@@ -2350,7 +2368,7 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string&
       result.push_back(ent);
       count++;
     }
-  } while (truncated && count < max);
+  }
 
 done:
   if (is_truncated)