cls_user: header cleanup

put stats under a new struct

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
Yehuda Sadeh 2014-01-13 11:01:59 -08:00
parent 45b222930d
commit 0b7968cda9
5 changed files with 50 additions and 24 deletions

View File

@ -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());

View File

@ -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);
}

View File

@ -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

View File

@ -1981,7 +1981,7 @@ next:
return -ret;
}
encode_json("header", header, formatter);
encode_json("stats", header.stats, formatter);
formatter->flush(cout);
}

View File

@ -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;
}