From: Yehuda Sadeh Date: Wed, 10 Oct 2018 23:55:45 +0000 (-0700) Subject: rgw, cls_rgw: propagate storage class to the index X-Git-Tag: v14.1.0~314^2~45 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=85c5a95f3466952007ffb56c6e4ccb783dccda5f;p=ceph.git rgw, cls_rgw: propagate storage class to the index Signed-off-by: Yehuda Sadeh --- diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index 36fbca39e852..6be138155e2e 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -58,6 +58,7 @@ void rgw_bucket_dir_entry_meta::dump(Formatter *f) const utime_t ut(mtime); encode_json("mtime", ut, f); encode_json("etag", etag, f); + encode_json("content_type", content_type, f); encode_json("owner", owner, f); encode_json("owner_display_name", owner_display_name, f); encode_json("content_type", content_type, f); @@ -74,6 +75,7 @@ void rgw_bucket_dir_entry_meta::decode_json(JSONObj *obj) { JSONDecoder::decode_json("mtime", ut, obj); mtime = ut.to_real_time(); JSONDecoder::decode_json("etag", etag, obj); + JSONDecoder::decode_json("content_type", content_type, obj); JSONDecoder::decode_json("owner", owner, obj); JSONDecoder::decode_json("owner_display_name", owner_display_name, obj); JSONDecoder::decode_json("content_type", content_type, obj); diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index 59b583003ba2..7a569b64f8da 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -119,12 +119,13 @@ struct rgw_bucket_dir_entry_meta { string content_type; uint64_t accounted_size; string user_data; + string storage_class; rgw_bucket_dir_entry_meta() : category(RGWObjCategory::None), size(0), accounted_size(0) { } void encode(bufferlist &bl) const { - ENCODE_START(5, 3, bl); + ENCODE_START(6, 3, bl); encode(category, bl); encode(size, bl); encode(mtime, bl); @@ -134,10 +135,11 @@ struct rgw_bucket_dir_entry_meta { encode(content_type, bl); encode(accounted_size, bl); encode(user_data, bl); + encode(storage_class, bl); ENCODE_FINISH(bl); } void decode(bufferlist::const_iterator &bl) { - DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl); + DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl); decode(category, bl); decode(size, bl); decode(mtime, bl); @@ -152,6 +154,8 @@ struct rgw_bucket_dir_entry_meta { accounted_size = size; if (struct_v >= 5) decode(user_data, bl); + if (struct_v >= 6) + decode(storage_class, bl); DECODE_FINISH(bl); } void dump(Formatter *f) const; diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 0c946b63e86a..fc8845e9fdd8 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -683,12 +683,16 @@ struct rgw_placement_rule { storage_class = c; } - const string& get_storage_class() const { + static const string& get_canonical_storage_class(const string& storage_class) { if (storage_class.empty()) { return RGW_STORAGE_CLASS_STANDARD; } return storage_class; } + + const string& get_storage_class() const { + return get_canonical_storage_class(storage_class); + } int compare(const rgw_placement_rule& r) const { int c = name.compare(r.name); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 9d2f1f636566..df379b3e4a9e 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -3590,6 +3590,7 @@ int RGWRados::Object::Write::_do_write_meta(uint64_t size, uint64_t accounted_si string etag; string content_type; bufferlist acl_bl; + string storage_class; map::iterator iter; if (meta.rmattrs) { @@ -3600,6 +3601,8 @@ int RGWRados::Object::Write::_do_write_meta(uint64_t size, uint64_t accounted_si } if (meta.manifest) { + storage_class = meta.manifest->get_tail_placement().placement_rule.storage_class; + /* remove existing manifest attr */ iter = attrs.find(RGW_ATTR_MANIFEST); if (iter != attrs.end()) @@ -3693,7 +3696,8 @@ int RGWRados::Object::Write::_do_write_meta(uint64_t size, uint64_t accounted_si tracepoint(rgw_rados, complete_enter, req_id.c_str()); r = index_op->complete(poolid, epoch, size, accounted_size, - meta.set_mtime, etag, content_type, &acl_bl, + meta.set_mtime, etag, content_type, + storage_class, &acl_bl, meta.category, meta.remove_objs, meta.user_data); tracepoint(rgw_rados, complete_exit, req_id.c_str()); if (r < 0) @@ -6120,10 +6124,15 @@ int RGWRados::set_attrs(void *ctx, const RGWBucketInfo& bucket_info, rgw_obj& ob bufferlist content_type_bl = attrs[RGW_ATTR_CONTENT_TYPE]; string etag(etag_bl.c_str(), etag_bl.length()); string content_type(content_type_bl.c_str(), content_type_bl.length()); + string storage_class; + auto iter = attrs.find(RGW_ATTR_STORAGE_CLASS); + if (iter != attrs.end()) { + storage_class = iter->second.to_str(); + } uint64_t epoch = ref.ioctx.get_last_version(); int64_t poolid = ref.ioctx.get_id(); r = index_op.complete(poolid, epoch, state->size, state->accounted_size, - mtime, etag, content_type, &acl_bl, + mtime, etag, content_type, storage_class, &acl_bl, RGWObjCategory::Main, NULL); } else { int ret = index_op.cancel(); @@ -6346,7 +6355,7 @@ int RGWRados::Bucket::UpdateIndex::prepare(RGWModifyOp op, const string *write_t int RGWRados::Bucket::UpdateIndex::complete(int64_t poolid, uint64_t epoch, uint64_t size, uint64_t accounted_size, ceph::real_time& ut, const string& etag, - const string& content_type, + const string& content_type, const string& storage_class, bufferlist *acl_bl, RGWObjCategory category, list *remove_objs, const string *user_data) @@ -6369,6 +6378,7 @@ int RGWRados::Bucket::UpdateIndex::complete(int64_t poolid, uint64_t epoch, ent.meta.accounted_size = accounted_size; ent.meta.mtime = ut; ent.meta.etag = etag; + ent.meta.storage_class = storage_class; if (user_data) ent.meta.user_data = *user_data; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 7c2baff625f5..fec92774ab1f 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1771,6 +1771,7 @@ public: int complete(int64_t poolid, uint64_t epoch, uint64_t size, uint64_t accounted_size, ceph::real_time& ut, const string& etag, const string& content_type, + const string& storage_class, bufferlist *acl_bl, RGWObjCategory category, list *remove_objs, const string *user_data = nullptr); int complete_del(int64_t poolid, uint64_t epoch, diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 75448748da2c..741e2199d7ed 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -754,7 +754,8 @@ void RGWListBucket_ObjStore_S3::send_versioned_response() if (!iter->is_delete_marker()) { s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str()); s->formatter->dump_int("Size", iter->meta.accounted_size); - s->formatter->dump_string("StorageClass", "STANDARD"); + auto& storage_class = rgw_placement_rule::get_canonical_storage_class(iter->meta.storage_class); + s->formatter->dump_string("StorageClass", storage_class.c_str()); } dump_owner(s, iter->meta.owner, iter->meta.owner_display_name); s->formatter->close_section(); @@ -831,7 +832,8 @@ void RGWListBucket_ObjStore_S3::send_response() dump_time(s, "LastModified", &iter->meta.mtime); s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str()); s->formatter->dump_int("Size", iter->meta.accounted_size); - s->formatter->dump_string("StorageClass", "STANDARD"); + auto& storage_class = rgw_placement_rule::get_canonical_storage_class(iter->meta.storage_class); + s->formatter->dump_string("StorageClass", storage_class.c_str()); dump_owner(s, iter->meta.owner, iter->meta.owner_display_name); if (s->system_request) { s->formatter->dump_string("RgwxTag", iter->tag);