]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Adding stats in the header of GET response on account 3612/head
authorYuan Zhou <yuan.zhou@intel.com>
Wed, 4 Feb 2015 07:53:11 +0000 (15:53 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Tue, 10 Feb 2015 03:41:43 +0000 (11:41 +0800)
In Swift the GET request on account returns the stats header also.
This patch adds the missing header in the response content to algin
with Swift API:

X-Timestamp
X-Account-Bytes-Used
X-Account-Container-Count
X-Account-Object-Count
X-Account-Bytes-Used-Actual

Fixes #10684
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_swift.cc

index bd3e07bb66abbd4f1536b20add3fd31701092baf..4c4a94b8d9de9e9cd41ead288012684cb6f89194 100644 (file)
@@ -1005,6 +1005,16 @@ void RGWListBuckets::execute()
       break;
     }
     map<string, RGWBucketEnt>& m = buckets.get_buckets();
+    map<string, RGWBucketEnt>::iterator iter;
+    for (iter = m.begin(); iter != m.end(); ++iter) {
+      RGWBucketEnt& bucket = iter->second;
+      buckets_size += bucket.size;
+      buckets_size_rounded += bucket.size_rounded;
+      buckets_objcount += bucket.count;
+
+      marker = iter->first;
+    }
+    buckets_count += m.size();
 
     total_count += m.size();
 
index cc8338934e9081ad0e820ae74b376205c50f034a..034168ce63fc885834d6c7c9d09ece6c00e34dcb 100644 (file)
@@ -186,10 +186,18 @@ protected:
   string marker;
   uint64_t limit;
   uint64_t limit_max;
+  uint32_t buckets_count;
+  uint64_t buckets_objcount;
+  uint64_t buckets_size;
+  uint64_t buckets_size_rounded;
 
 public:
   RGWListBuckets() : ret(0), sent_data(false) {
     limit = limit_max = RGW_LIST_BUCKETS_LIMIT_MAX;
+    buckets_count = 0;
+    buckets_objcount = 0;
+    buckets_size = 0;
+    buckets_size_rounded = 0;
   }
 
   int verify_permission();
index bf869738330de880d73027a8240d379595948e68..4f656c0324b159964fa14f0b19b146b0cc91e830 100644 (file)
@@ -45,6 +45,24 @@ int RGWListBuckets_ObjStore_SWIFT::get_params()
   return 0;
 }
 
+static void dump_account_metadata(struct req_state *s, uint32_t buckets_count,
+                                  uint64_t buckets_object_count, uint64_t buckets_size, uint64_t buckets_size_rounded)
+{
+  char buf[32];
+  utime_t now = ceph_clock_now(g_ceph_context);
+  snprintf(buf, sizeof(buf), "%0.5f", (double)now);
+  /* Adding X-Timestamp to keep align with Swift API */
+  s->cio->print("X-Timestamp: %s\r\n", buf);
+  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_count);
+  s->cio->print("X-Account-Container-Count: %s\r\n", buf);
+  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_object_count);
+  s->cio->print("X-Account-Object-Count: %s\r\n", buf);
+  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size);
+  s->cio->print("X-Account-Bytes-Used: %s\r\n", buf);
+  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size_rounded);
+  s->cio->print("X-Account-Bytes-Used-Actual: %s\r\n", buf);
+}
+
 void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets)
 {
   if (ret) {
@@ -53,6 +71,8 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets)
     ret = STATUS_NO_CONTENT;
     set_req_state_err(s, ret);
   }
+  /* Adding account stats in the header to keep align with Swift API */
+  dump_account_metadata(s, buckets_count, buckets_objcount, buckets_size, buckets_size_rounded);
   dump_errno(s);
   end_header(s, NULL);
 
@@ -248,20 +268,6 @@ static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket)
   }
 }
 
-static void dump_account_metadata(struct req_state *s, uint32_t buckets_count,
-                                  uint64_t buckets_object_count, uint64_t buckets_size, uint64_t buckets_size_rounded)
-{
-  char buf[32];
-  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_count);
-  s->cio->print("X-Account-Container-Count: %s\r\n", buf);
-  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_object_count);
-  s->cio->print("X-Account-Object-Count: %s\r\n", buf);
-  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size);
-  s->cio->print("X-Account-Bytes-Used: %s\r\n", buf);
-  snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size_rounded);
-  s->cio->print("X-Account-Bytes-Used-Actual: %s\r\n", buf);
-}
-
 void RGWStatAccount_ObjStore_SWIFT::send_response()
 {
   if (ret >= 0) {