From 5eca89f08d29ac6aa7b55a3b4fb5b4183bdc0496 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 28 Dec 2016 17:12:50 +0100 Subject: [PATCH] rgw: convey placement rule in RGWBucketEnt and cls_user_bucket_entry. Fixes: http://tracker.ceph.com/issues/17932 Signed-off-by: Radoslaw Zarzynski --- src/cls/user/cls_user_types.cc | 1 + src/cls/user/cls_user_types.h | 10 +++++++++- src/rgw/rgw_common.h | 8 ++++++-- src/rgw/rgw_json_enc.cc | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cls/user/cls_user_types.cc b/src/cls/user/cls_user_types.cc index be3280ca2bd..eea32d7b799 100644 --- a/src/cls/user/cls_user_types.cc +++ b/src/cls/user/cls_user_types.cc @@ -39,6 +39,7 @@ void cls_user_bucket_entry::dump(Formatter *f) const encode_json("creation_time", utime_t(creation_time), f); encode_json("count", count, f); encode_json("user_stats_sync", user_stats_sync, f); + encode_json("placement_rule", placement_rule, f); } void cls_user_gen_test_bucket_entry(cls_user_bucket_entry *entry, int i) diff --git a/src/cls/user/cls_user_types.h b/src/cls/user/cls_user_types.h index 3d0d344324b..41c85d2cd83 100644 --- a/src/cls/user/cls_user_types.h +++ b/src/cls/user/cls_user_types.h @@ -105,10 +105,15 @@ struct cls_user_bucket_entry { uint64_t count; bool user_stats_sync; + /* The placement_rule is necessary to calculate per-storage-policy statics + * of the Swift API. Although the info available in RGWBucketInfo, we need + * to duplicate it here to not affect the performance of buckets listing. */ + std::string placement_rule; + cls_user_bucket_entry() : size(0), size_rounded(0), count(0), user_stats_sync(false) {} void encode(bufferlist& bl) const { - ENCODE_START(7, 5, bl); + ENCODE_START(8, 5, bl); uint64_t s = size; __u32 mt = ceph::real_clock::to_time_t(creation_time); string empty_str; // originally had the bucket name here, but we encode bucket later @@ -121,6 +126,7 @@ struct cls_user_bucket_entry { ::encode(s, bl); ::encode(user_stats_sync, bl); ::encode(creation_time, bl); + ::encode(placement_rule, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { @@ -146,6 +152,8 @@ struct cls_user_bucket_entry { ::decode(user_stats_sync, bl); if (struct_v >= 7) ::decode(creation_time, bl); + if (struct_v >= 8) + ::decode(placement_rule, bl); DECODE_FINISH(bl); } void dump(Formatter *f) const; diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index f1d9dfe4c36..0acc379e68f 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1904,7 +1904,8 @@ struct RGWBucketEnt { size(e.size), size_rounded(e.size_rounded), creation_time(e.creation_time), - count(e.count) { + count(e.count), + placement_rule(std::move(e.placement_rule)) { } RGWBucketEnt& operator=(const RGWBucketEnt&) = default; @@ -1918,7 +1919,7 @@ struct RGWBucketEnt { } void encode(bufferlist& bl) const { - ENCODE_START(6, 5, bl); + ENCODE_START(7, 5, bl); uint64_t s = size; __u32 mt = ceph::real_clock::to_time_t(creation_time); string empty_str; // originally had the bucket name here, but we encode bucket later @@ -1930,6 +1931,7 @@ struct RGWBucketEnt { s = size_rounded; ::encode(s, bl); ::encode(creation_time, bl); + ::encode(placement_rule, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { @@ -1953,6 +1955,8 @@ struct RGWBucketEnt { size_rounded = s; if (struct_v >= 6) ::decode(creation_time, bl); + if (struct_v >= 7) + ::decode(placement_rule, bl); DECODE_FINISH(bl); } void dump(Formatter *f) const; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 4792e62c356..ad7b941bf3a 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -798,6 +798,7 @@ void RGWBucketEnt::dump(Formatter *f) const utime_t ut(creation_time); encode_json("mtime", ut, f); /* mtime / creation time discrepency needed for backward compatibility */ encode_json("count", count, f); + encode_json("placement_rule", placement_rule, f); } void RGWUploadPartInfo::dump(Formatter *f) const -- 2.39.5