From 0b7968cda911add3c13240e03d835c388e31b7cc Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 13 Jan 2014 11:01:59 -0800 Subject: [PATCH] cls_user: header cleanup put stats under a new struct Signed-off-by: Yehuda Sadeh --- src/cls/user/cls_user.cc | 24 ++++++++++++------------ src/cls/user/cls_user_types.cc | 7 ++++++- src/cls/user/cls_user_types.h | 26 ++++++++++++++++++++++---- src/rgw/rgw_admin.cc | 2 +- src/rgw/rgw_rados.cc | 15 +++++++++------ 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/cls/user/cls_user.cc b/src/cls/user/cls_user.cc index ba172898bc296..a20075cc3c17e 100644 --- a/src/cls/user/cls_user.cc +++ b/src/cls/user/cls_user.cc @@ -99,18 +99,18 @@ static int read_header(cls_method_context_t hctx, cls_user_header *header) return 0; } -static void add_header_stats(cls_user_header *header, cls_user_bucket_entry& entry) +static void add_header_stats(cls_user_stats *stats, cls_user_bucket_entry& entry) { - header->total_entries += entry.count; - header->total_bytes += entry.size; - header->total_bytes_rounded += entry.size_rounded; + stats->total_entries += entry.count; + stats->total_bytes += entry.size; + stats->total_bytes_rounded += entry.size_rounded; } -static void dec_header_stats(cls_user_header *header, cls_user_bucket_entry& entry) +static void dec_header_stats(cls_user_stats *stats, cls_user_bucket_entry& entry) { - header->total_bytes -= entry.size; - header->total_bytes_rounded -= entry.size_rounded; - header->total_entries -= entry.count; + stats->total_bytes -= entry.size; + stats->total_bytes_rounded -= entry.size_rounded; + stats->total_entries -= entry.count; } static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out) @@ -150,7 +150,7 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, CLS_LOG(0, "ERROR: get_existing_bucket_entry() key=%s returned %d", key.c_str(), ret); return ret; } else if (ret >= 0 && old_entry.user_stats_sync) { - dec_header_stats(&header, old_entry); + dec_header_stats(&header.stats, old_entry); } CLS_LOG(20, "storing entry for key=%s size=%lld count=%lld", @@ -162,12 +162,12 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, if (ret < 0) return ret; - add_header_stats(&header, entry); + add_header_stats(&header.stats, entry); } bufferlist bl; - CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.total_bytes, (long long)header.total_entries); + CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.stats.total_bytes, (long long)header.stats.total_entries); ::encode(header, bl); @@ -212,7 +212,7 @@ static int cls_user_remove_bucket(cls_method_context_t hctx, bufferlist *in, buf } if (entry.user_stats_sync) { - dec_header_stats(&header, entry); + dec_header_stats(&header.stats, entry); } CLS_LOG(20, "removing entry at %s", key.c_str()); diff --git a/src/cls/user/cls_user_types.cc b/src/cls/user/cls_user_types.cc index 59f0bdcac7a12..7edf2e13a7da6 100644 --- a/src/cls/user/cls_user_types.cc +++ b/src/cls/user/cls_user_types.cc @@ -3,12 +3,17 @@ #include "cls/user/cls_user_types.h" #include "common/Formatter.h" +#include "common/ceph_json.h" -void cls_user_header::dump(Formatter *f) const +void cls_user_stats::dump(Formatter *f) const { f->dump_int("total_entries", total_entries); f->dump_int("total_bytes", total_bytes); f->dump_int("total_bytes_rounded", total_bytes_rounded); } +void cls_user_header::dump(Formatter *f) const +{ + encode_json("stats", stats, f); +} diff --git a/src/cls/user/cls_user_types.h b/src/cls/user/cls_user_types.h index d38bf9d1b39d8..92cdd0be2641d 100644 --- a/src/cls/user/cls_user_types.h +++ b/src/cls/user/cls_user_types.h @@ -109,10 +109,7 @@ struct cls_user_bucket_entry { }; WRITE_CLASS_ENCODER(cls_user_bucket_entry) -/* - * this needs to be compatible with with rgw_bucket, as it replaces it - */ -struct cls_user_header { +struct cls_user_stats { uint64_t total_entries; uint64_t total_bytes; uint64_t total_bytes_rounded; @@ -134,6 +131,27 @@ struct cls_user_header { void dump(Formatter *f) const; }; +WRITE_CLASS_ENCODER(cls_user_stats) + +/* + * this needs to be compatible with with rgw_bucket, as it replaces it + */ +struct cls_user_header { + cls_user_stats stats; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(stats, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(stats, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; +}; WRITE_CLASS_ENCODER(cls_user_header) #endif diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 0bef8864fc06a..7470c7d816275 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1981,7 +1981,7 @@ next: return -ret; } - encode_json("header", header, formatter); + encode_json("stats", header.stats, formatter); formatter->flush(cout); } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index f10003dfefcbd..9d45a6bfbb850 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -4717,12 +4717,13 @@ class RGWGetUserStatsContext : public RGWGetUserHeader_CB { public: RGWGetUserStatsContext(RGWGetUserStats_CB *_cb) : cb(_cb) {} void handle_response(int r, cls_user_header& header) { + cls_user_stats& hs = header.stats; if (r >= 0) { RGWStorageStats stats; - stats.num_kb = (header.total_bytes + 1023) / 1024; - stats.num_kb_rounded = (header.total_bytes_rounded + 1023) / 1024; - stats.num_objects = header.total_entries; + stats.num_kb = (hs.total_bytes + 1023) / 1024; + stats.num_kb_rounded = (hs.total_bytes_rounded + 1023) / 1024; + stats.num_objects = hs.total_entries; cb->set_response(stats); } @@ -4740,9 +4741,11 @@ int RGWRados::get_user_stats(const string& user, RGWStorageStats& stats) if (r < 0) return r; - stats.num_kb = (header.total_bytes + 1023) / 1024; - stats.num_kb_rounded = (header.total_bytes_rounded + 1023) / 1024; - stats.num_objects = header.total_entries; + cls_user_stats& hs = header.stats; + + stats.num_kb = (hs.total_bytes + 1023) / 1024; + stats.num_kb_rounded = (hs.total_bytes_rounded + 1023) / 1024; + stats.num_objects = hs.total_entries; return 0; } -- 2.39.5