From 9a105a6966aa0a40c13cf970a478a8f45c970bbc Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 29 Sep 2016 11:44:00 -0400 Subject: [PATCH] rgw: add accounted_size to RGWObjState RGWRados::get_obj_state() now initializes accounted_size based on the compression attribute, if present Signed-off-by: Casey Bodley --- src/rgw/rgw_rados.cc | 17 ++++++++++++++++- src/rgw/rgw_rados.h | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index cb39809ad6e..cbd1ca3d534 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -8476,8 +8476,23 @@ int RGWRados::get_obj_state_impl(RGWObjectCtx *rctx, rgw_obj& obj, RGWObjState * s->exists = true; s->has_attrs = true; + s->accounted_size = s->size; - map::iterator iter = s->attrset.find(RGW_ATTR_SHADOW_OBJ); + auto iter = s->attrset.find(RGW_ATTR_COMPRESSION); + if (iter != s->attrset.end()) { + // use uncompressed size for accounted_size + try { + RGWCompressionInfo info; + auto p = iter->second.begin(); + ::decode(info, p); + s->accounted_size = info.orig_size; + } catch (buffer::error&) { + dout(0) << "ERROR: could not decode compression info for object: " << obj << dendl; + return -EIO; + } + } + + iter = s->attrset.find(RGW_ATTR_SHADOW_OBJ); if (iter != s->attrset.end()) { bufferlist bl = iter->second; bufferlist::iterator it = bl.begin(); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index e37f758cd0b..cd9121dc14a 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -749,7 +749,8 @@ struct RGWObjState { bool is_atomic; bool has_attrs; bool exists; - uint64_t size; + uint64_t size; //< size of raw object + uint64_t accounted_size{0}; //< size before compression, encryption ceph::real_time mtime; uint64_t epoch; bufferlist obj_tag; @@ -781,6 +782,7 @@ struct RGWObjState { has_attrs = rhs.has_attrs; exists = rhs.exists; size = rhs.size; + accounted_size = rhs.accounted_size; mtime = rhs.mtime; epoch = rhs.epoch; if (rhs.obj_tag.length()) { -- 2.47.3