From 681f65b4b9e11144f25f08ccc0d1dc670a319144 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Fri, 2 Sep 2016 17:44:17 +0200 Subject: [PATCH] Cleanup of compression-related code in RGWGetObj::execute. Signed-off-by: Adam Kupczyk --- src/rgw/rgw_op.cc | 115 +++++++++++++------------------------------ src/rgw/rgw_op.h | 3 -- src/rgw/rgw_rados.cc | 3 ++ 3 files changed, 36 insertions(+), 85 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index fcbf0466b8c..cf44068d19e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1340,14 +1340,15 @@ void RGWGetObj::execute() gc_invalidate_time = ceph_clock_now(s->cct); gc_invalidate_time += (s->cct->_conf->rgw_gc_obj_min_wait / 2); + bool need_decompress; + int64_t ofs_x, end_x; + RGWGetObj_CB cb(this); RGWGetDataCB* filter = (RGWGetDataCB*)&cb; boost::optional decompress; map::iterator attr_iter; perfcounter->inc(l_rgw_get); - int64_t new_ofs, new_end; - int cret; RGWRados::Object op_target(store, s->bucket_info, *static_cast(s->obj_ctx), obj); RGWRados::Object::Read read_op(&op_target); @@ -1360,9 +1361,6 @@ void RGWGetObj::execute() if (op_ret < 0) goto done_err; - new_ofs = ofs; - new_end = end; - read_op.conds.mod_ptr = mod_ptr; read_op.conds.unmod_ptr = unmod_ptr; read_op.conds.high_precision_time = s->system_request; /* system request need to use high precision time */ @@ -1379,64 +1377,6 @@ void RGWGetObj::execute() if (op_ret < 0) goto done_err; - op_ret = read_op.range_to_ofs(s->obj_size, new_ofs, new_end); - // check erange error later - total_len = (new_ofs <= new_end ? new_end + 1 - new_ofs : 0); - - cret = rgw_compression_info_from_attrset(attrs, need_decompress, cs_info); - if (cret < 0) { - lderr(s->cct) << "ERROR: failed to decode compression info, cannot decompress" << dendl; - if (op_ret == 0) - op_ret = cret; - goto done_err; - } - - if (op_ret == -ERANGE && !need_decompress) - goto done_err; - - if (need_decompress) { - op_ret = 0; - s->obj_size = cs_info.orig_size; - - if (partial_content) { - // recheck user range for correctness - if (ofs < 0) { - ofs += cs_info.orig_size; - if (ofs < 0) - ofs = 0; - end = cs_info.orig_size - 1; - } else if (end < 0) { - end = cs_info.orig_size - 1; - } - - if ((unsigned)ofs >= cs_info.orig_size) { - lderr(s->cct) << "ERROR: begin of the bytes range more than object size (" << cs_info.orig_size - << ")" << dendl; - op_ret = -ERANGE; - goto done_err; - } else - new_ofs = ofs; - - if ((unsigned)end >= cs_info.orig_size) { - ldout(s->cct, 5) << "WARNING: end of the bytes range more than object size (" << cs_info.orig_size - << ")" << dendl; - new_end = cs_info.orig_size - 1; - } else - new_end = end; - - total_len = new_end - new_ofs + 1; - - } else - total_len = cs_info.orig_size; - } - - // for range requests with obj size 0 - if (range_str && !(s->obj_size)) { - total_len = 0; - op_ret = -ERANGE; - goto done_err; - } - /* start gettorrent */ if (torrent.get_flag()) { @@ -1459,6 +1399,29 @@ void RGWGetObj::execute() } /* end gettorrent */ + op_ret = rgw_compression_info_from_attrset(attrs, need_decompress, cs_info); + if (op_ret < 0) { + lderr(s->cct) << "ERROR: failed to decode compression info, cannot decompress" << dendl; + goto done_err; + } + if (need_decompress) { + s->obj_size = cs_info.orig_size; + decompress = boost::in_place(s->cct, &cs_info, partial_content, filter); + filter = &*decompress; + } + + // for range requests with obj size 0 + if (range_str && !(s->obj_size)) { + total_len = 0; + op_ret = -ERANGE; + goto done_err; + } + + op_ret = read_op.range_to_ofs(s->obj_size, ofs, end); + if (op_ret < 0) + goto done_err; + total_len = (ofs <= end ? end + 1 - ofs : 0); + attr_iter = attrs.find(RGW_ATTR_USER_MANIFEST); if (attr_iter != attrs.end() && !skip_manifest) { op_ret = handle_user_manifest(attr_iter->second.c_str()); @@ -1488,37 +1451,25 @@ void RGWGetObj::execute() goto done_err; } - ofs = new_ofs; - end = new_end; - start = ofs; - if (need_decompress) { - - if (cs_info.blocks.size() == 0) { - lderr(s->cct) << "ERROR: no info about compression blocks, cannot decompress" << dendl; - op_ret = -EIO; - goto done_err; - } - - decompress = boost::in_place(s->cct, &cs_info, partial_content, filter); - filter = &*decompress; - } - /* STAT ops don't need data, and do no i/o */ if (get_type() == RGW_OP_STAT_OBJ) { return; } - if (!get_data || new_ofs > new_end) { + if (!get_data || ofs > end) { send_response_data(bl, 0, 0); return; } - perfcounter->inc(l_rgw_get_b, new_end - new_ofs); + perfcounter->inc(l_rgw_get_b, end - ofs); + + ofs_x = ofs; + end_x = end; + filter->fixup_range(ofs_x, end_x); + op_ret = read_op.iterate(ofs_x, end_x, filter); - filter->fixup_range(new_ofs, new_end); - op_ret = read_op.iterate(new_ofs, new_end, filter); if (op_ret >= 0) op_ret = filter->flush(); diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 6d556920779..ad8cb914b4b 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -140,7 +140,6 @@ protected: // compression attrs RGWCompressionInfo cs_info; - bool need_decompress; off_t first_block, last_block; off_t q_ofs, q_len; bool first_data; @@ -168,8 +167,6 @@ public: range_parsed = false; skip_manifest = false; is_slo = false; - rgwx_stat = false; - need_decompress = false; first_block = 0; last_block = 0; q_ofs = 0; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 13db1cfaa75..5e910778f05 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -12860,6 +12860,9 @@ int rgw_compression_info_from_attrset(map& attrs, bool& need } catch (buffer::error& err) { return -EIO; } + if (cs_info.blocks.size() == 0) { + return -EIO; + } if (cs_info.compression_type != "none") need_decompress = true; else -- 2.39.5