From: Yehuda Sadeh Date: Tue, 23 Apr 2013 19:31:31 +0000 (-0700) Subject: rgw: list container only shows stats if needed X-Git-Tag: v0.61~96^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9abec309e89ec738b6b45c328a08fc066ff2e7cc;p=ceph.git rgw: list container only shows stats if needed 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 --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index d9c0a809ac71..87f1b9886024 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -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::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) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 2abed2f9f916..f4878f4b2916 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -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::iterator iter = val_map.find(name); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 4e03b053e5c8..7b8227af9cf8 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -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(); } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 334ecd89abb0..16e8f348778d 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -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"; } }; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 45ded2c5f17a..7457add2e663 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -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& m = buckets.get_buckets(); map::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() diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index bbe2349d27d2..635bd2e7a013 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -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& m = buckets.get_buckets(); map::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() diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index fef1b4df5289..e721f1cd1c18 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -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 {