]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: list container only shows stats if needed
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 23 Apr 2013 19:31:31 +0000 (12:31 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 24 Apr 2013 15:49:28 +0000 (08:49 -0700)
Fixes: #4759
Add a new request param 'stats' for the swift list containers
request. If set to 'false' it disables stats retrieval, which
makes it go faster. Also, don't dump stats if format is plain,
as they're not going to be dumped.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index d9c0a809ac7116f431889192945585045c00d706..87f1b9886024c2656f7153b914d48181f6c21ad7 100644 (file)
@@ -507,6 +507,36 @@ string& XMLArgs::get(const char *name, bool *exists)
   return get(s, exists);
 }
 
+
+int XMLArgs::get_bool(const string& name, bool *val, bool *exists)
+{
+  map<string, string>::iterator iter;
+  iter = val_map.find(name);
+  bool e = (iter != val_map.end());
+  if (exists)
+    *exists = e;
+
+  if (e) {
+    const char *s = iter->second.c_str();
+
+    if (strcasecmp(s, "false") == 0) {
+      *val = false;
+    } else if (strcasecmp(s, "true") == 0) {
+      *val = true;
+    } else {
+      return -EINVAL;
+    }
+  }
+
+  return 0;
+}
+
+int XMLArgs::get_bool(const char *name, bool *val, bool *exists)
+{
+  string s(name);
+  return get_bool(s, val, exists);
+}
+
 bool verify_bucket_permission(struct req_state *s, int perm)
 {
   if (!s->bucket_acl)
index 2abed2f9f9166a8f9ef70a442565d30203dc6858..f4878f4b2916b97a910eee069701f5a336caa39e 100644 (file)
@@ -219,6 +219,9 @@ class XMLArgs
   /** Get the value for a specific argument parameter */
   string& get(const string& name, bool *exists = NULL);
   string& get(const char *name, bool *exists = NULL);
+  int get_bool(const string& name, bool *val, bool *exists);
+  int get_bool(const char *name, bool *val, bool *exists);
+
   /** see if a parameter is contained in this XMLArgs */
   bool exists(const char *name) {
     map<string, string>::iterator iter = val_map.find(name);
index 4e03b053e5c80af32f7364fe6b39e6335cf56c01..7b8227af9cf8492ba220693b7872d3d461ac5df9 100644 (file)
@@ -649,22 +649,21 @@ int RGWListBuckets::verify_permission()
 
 void RGWListBuckets::execute()
 {
-  ret = get_params();
-  if (ret < 0)
-    return;
-
   bool done;
-
   bool started = false;
   uint64_t total_count = 0;
 
   size_t max_buckets = s->cct->_conf->rgw_list_buckets_max_chunk;
 
+  ret = get_params();
+  if (ret < 0)
+    goto send_end;
+
   do {
     RGWUserBuckets buckets;
     uint64_t read_count = min(limit - total_count, max_buckets);
     ret = rgw_read_user_buckets(store, s->user.user_id, buckets,
-                                marker, read_count, !!(s->prot_flags & RGW_REST_SWIFT));
+                                marker, read_count, should_get_stats());
 
     if (!started) {
       send_response_begin();
@@ -700,6 +699,10 @@ void RGWListBuckets::execute()
     }
   } while (!done);
 
+send_end:
+  if (!started) {
+    send_response_begin();
+  }
   send_response_end();
 }
 
index 334ecd89abb0f48cfec5f04543d015f6a620ea40..16e8f348778da4bcdac0821893b9a17332ace29f 100644 (file)
@@ -143,6 +143,8 @@ public:
   virtual void send_response_end() = 0;
   virtual void send_response() {}
 
+  virtual bool should_get_stats() { return false; }
+
   virtual const char *name() { return "list_buckets"; }
 };
 
index 45ded2c5f17a85e5bf1c510b20f97da1441ecbb8..7457add2e663fdb4d234bed469a9907781eab8eb 100644 (file)
@@ -173,6 +173,9 @@ void RGWListBuckets_ObjStore_S3::send_response_begin()
 
 void RGWListBuckets_ObjStore_S3::send_response_data(RGWUserBuckets& buckets)
 {
+  if (!sent_data)
+    return;
+
   map<string, RGWBucketEnt>& m = buckets.get_buckets();
   map<string, RGWBucketEnt>::iterator iter;
 
@@ -188,8 +191,8 @@ void RGWListBuckets_ObjStore_S3::send_response_end()
   if (sent_data) {
     s->formatter->close_section();
     list_all_buckets_end(s);
+    rgw_flush_formatter_and_reset(s, s->formatter);
   }
-  rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
 int RGWListBucket_ObjStore_S3::get_params()
index bbe2349d27d2deb2ca28a340d939ac27bc64df31..635bd2e7a013b63444410e383ad1267a429ac89c 100644 (file)
@@ -26,6 +26,20 @@ int RGWListBuckets_ObjStore_SWIFT::get_params()
   if (limit == 0)
     limit = limit_max;
 
+  need_stats = (s->format != RGW_FORMAT_PLAIN);
+
+  if (need_stats) {
+    bool stats, exists;
+    int r = s->args.get_bool("stats", &stats, &exists);
+
+    if (r < 0)
+      return r;
+
+    if (exists) {
+      need_stats = stats;
+    }
+  }
+
   return 0;
 }
 
@@ -49,12 +63,17 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_data(RGWUserBuckets& buckets)
   map<string, RGWBucketEnt>& m = buckets.get_buckets();
   map<string, RGWBucketEnt>::iterator iter;
 
+  if (!sent_data)
+    return;
+
   for (iter = m.begin(); iter != m.end(); ++iter) {
     RGWBucketEnt obj = iter->second;
     s->formatter->open_object_section("container");
     s->formatter->dump_string("name", obj.bucket.name);
-    s->formatter->dump_int("count", obj.count);
-    s->formatter->dump_int("bytes", obj.size);
+    if (need_stats) {
+      s->formatter->dump_int("count", obj.count);
+      s->formatter->dump_int("bytes", obj.size);
+    }
     s->formatter->close_section();
     rgw_flush_formatter(s, s->formatter);
   }
@@ -64,9 +83,8 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_end()
 {
   if (sent_data) {
     s->formatter->close_section();
+    rgw_flush_formatter_and_reset(s, s->formatter);
   }
-
-  rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
 int RGWListBucket_ObjStore_SWIFT::get_params()
index fef1b4df528911f1c9a09cb3a77d91dd6f627dde..e721f1cd1c183331b27a1d40a18a3e6271fcbed0 100644 (file)
@@ -14,14 +14,17 @@ public:
 };
 
 class RGWListBuckets_ObjStore_SWIFT : public RGWListBuckets_ObjStore {
+  bool need_stats;
 public:
-  RGWListBuckets_ObjStore_SWIFT() {}
+  RGWListBuckets_ObjStore_SWIFT() : need_stats(true) {}
   ~RGWListBuckets_ObjStore_SWIFT() {}
 
   int get_params();
   void send_response_begin();
   void send_response_data(RGWUserBuckets& buckets);
   void send_response_end();
+
+  bool should_get_stats() { return need_stats; }
 };
 
 class RGWListBucket_ObjStore_SWIFT : public RGWListBucket_ObjStore {