rgw: swift bucket report returns both bytes size and actual size

This commit is contained in:
Yehuda Sadeh 2011-11-08 13:42:55 -08:00
parent a04afd0957
commit 7a32cc605e
6 changed files with 23 additions and 9 deletions

View File

@ -451,6 +451,7 @@ int bucket_stats(rgw_bucket& bucket, Formatter *formatter)
const char *cat_name = rgw_obj_category_name(iter->first);
formatter->open_object_section(cat_name);
formatter->dump_int("size_kb", s.num_kb);
formatter->dump_int("size_kb_actual", s.num_kb_rounded);
formatter->dump_int("num_objects", s.num_objects);
formatter->close_section();
formatter->flush(cout);

View File

@ -498,6 +498,7 @@ struct RGWBucketStats
{
RGWObjCategory category;
uint64_t num_kb;
uint64_t num_kb_rounded;
uint64_t num_objects;
};
@ -594,11 +595,12 @@ struct RGWObjEnt {
struct RGWBucketEnt {
rgw_bucket bucket;
size_t size;
size_t size_rounded;
time_t mtime;
uint64_t count;
void encode(bufferlist& bl) const {
__u8 struct_v = 3;
__u8 struct_v = 4;
::encode(struct_v, bl);
uint64_t s = size;
__u32 mt = mtime;
@ -607,6 +609,8 @@ struct RGWBucketEnt {
::encode(mt, bl);
::encode(count, bl);
::encode(bucket, bl);
s = size_rounded;
::encode(s, bl);
}
void decode(bufferlist::iterator& bl) {
__u8 struct_v;
@ -622,10 +626,14 @@ struct RGWBucketEnt {
::decode(count, bl);
if (struct_v >= 3)
::decode(bucket, bl);
if (struct_v >= 4)
::decode(s, bl);
size_rounded = s;
}
void clear() {
bucket.clear();
size = 0;
size_rounded = 0;
mtime = 0;
count = 0;
}

View File

@ -296,15 +296,12 @@ void RGWGetObj::execute()
if (ret < 0)
goto done;
dout(0) << __FILE__ << ":" << __LINE__ << ": ofs=" << ofs << " end=" << end << " total_len=" << total_len << dendl;
obj.init(s->bucket, s->object_str);
rgwstore->set_atomic(s->obj_ctx, obj);
ret = rgwstore->prepare_get_obj(s->obj_ctx, obj, &ofs, &end, &attrs, mod_ptr,
unmod_ptr, &lastmod, if_match, if_nomatch, &total_len, &s->obj_size, &handle, &s->err);
if (ret < 0)
goto done;
dout(0) << __FILE__ << ":" << __LINE__ << ": ofs=" << ofs << " end=" << end << " total_len=" << total_len << dendl;
start = ofs;
@ -314,7 +311,6 @@ dout(0) << __FILE__ << ":" << __LINE__ << ": ofs=" << ofs << " end=" << end << "
perfcounter->inc(l_rgw_get_b, end - ofs);
while (ofs <= end) {
dout(0) << __FILE__ << ":" << __LINE__ << ": ofs=" << ofs << " end=" << end << " total_len=" << total_len << dendl;
data = NULL;
ret = rgwstore->get_obj(s->obj_ctx, &handle, obj, &data, ofs, end);
if (ret < 0) {
@ -421,6 +417,7 @@ void RGWStatAccount::execute()
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;
}
buckets_count = m.size();

View File

@ -121,6 +121,7 @@ protected:
uint32_t buckets_count;
uint64_t buckets_objcount;
uint64_t buckets_size;
uint64_t buckets_size_rounded;
public:
virtual void init(struct req_state *s) {
@ -129,6 +130,7 @@ public:
buckets_count = 0;
buckets_objcount = 0;
buckets_size = 0;
buckets_size_rounded = 0;
}
RGWStatAccount() {}

View File

@ -1779,7 +1779,8 @@ int RGWRados::get_bucket_stats(rgw_bucket& bucket, map<RGWObjCategory, RGWBucket
RGWBucketStats& s = stats[category];
struct rgw_bucket_category_stats& stats = iter->second;
s.category = (RGWObjCategory)iter->first;
s.num_kb = ((stats.total_size_rounded + 1023) / 1024);
s.num_kb = ((stats.total_size + 1023) / 1024);
s.num_kb_rounded = ((stats.total_size_rounded + 1023) / 1024);
s.num_objects = stats.num_entries;
}
@ -1975,7 +1976,8 @@ int RGWRados::update_containers_stats(map<string, RGWBucketEnt>& m)
if (iter != header.stats.end()) {
struct rgw_bucket_category_stats& stats = iter->second;
ent.count = stats.num_entries;
ent.size = stats.total_size_rounded;
ent.size = stats.total_size;
ent.size_rounded = stats.total_size_rounded;
}
}

View File

@ -189,10 +189,12 @@ static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket)
CGI_PRINTF(s,"X-Container-Object-Count: %s\n", buf);
snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size);
CGI_PRINTF(s,"X-Container-Bytes-Used: %s\n", buf);
snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size_rounded);
CGI_PRINTF(s,"X-Container-Bytes-Used-Actual: %s\n", buf);
}
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_object_count, uint64_t buckets_size, uint64_t buckets_size_rounded)
{
char buf[32];
snprintf(buf, sizeof(buf), "%lld", (long long)buckets_count);
@ -201,13 +203,15 @@ static void dump_account_metadata(struct req_state *s, uint32_t buckets_count,
CGI_PRINTF(s,"X-Account-Object-Count: %s\n", buf);
snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size);
CGI_PRINTF(s,"X-Account-Bytes-Used: %s\n", buf);
snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size_rounded);
CGI_PRINTF(s,"X-Account-Bytes-Used-Actual: %s\n", buf);
}
void RGWStatAccount_REST_SWIFT::send_response()
{
if (ret >= 0) {
ret = STATUS_NO_CONTENT;
dump_account_metadata(s, buckets_count, buckets_objcount, buckets_size);
dump_account_metadata(s, buckets_count, buckets_objcount, buckets_size, buckets_size_rounded);
}
set_req_state_err(s, ret);