From: Casey Bodley Date: Thu, 10 Nov 2016 17:59:46 +0000 (-0500) Subject: rgw: fix for multipart uploads with rgw_compression_type=random X-Git-Tag: v11.1.0~220^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7200d77cc0420d4a967c03773dbc7cd7ad700d34;p=ceph.git rgw: fix for multipart uploads with rgw_compression_type=random use a hash of the multipart upload id so all parts use the same plugin Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 4f35e9cddce..dca4ce775e7 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2808,6 +2808,29 @@ int RGWPutObj::get_data(const off_t fst, const off_t lst, bufferlist& bl) return ret; } +// special handling for rgw_compression_type = "random" with multipart uploads +static CompressorRef get_compressor_plugin(const req_state *s) +{ + const auto& compression_type = s->cct->_conf->rgw_compression_type; + if (compression_type != "random") { + return Compressor::create(s->cct, compression_type); + } + + bool is_multipart{false}; + const auto& upload_id = s->info.args.get("uploadId", &is_multipart); + + if (!is_multipart) { + return Compressor::create(s->cct, compression_type); + } + + // use a hash of the multipart upload id so all parts use the same plugin + const auto alg = std::hash{}(upload_id) % Compressor::COMP_ALG_LAST; + if (alg == Compressor::COMP_ALG_NONE) { + return nullptr; + } + return Compressor::create(s->cct, alg); +} + void RGWPutObj::execute() { RGWPutObjProcessor *processor = NULL; @@ -2824,7 +2847,6 @@ void RGWPutObj::execute() off_t fst; off_t lst; - const auto& compression_type = s->cct->_conf->rgw_compression_type; CompressorRef plugin; boost::optional compressor; @@ -2911,11 +2933,11 @@ void RGWPutObj::execute() fst = copy_source_range_fst; lst = copy_source_range_lst; - if (compression_type != "none") { - plugin = Compressor::create(s->cct, compression_type); + if (s->cct->_conf->rgw_compression_type != "none") { + plugin = get_compressor_plugin(s); if (!plugin) { ldout(s->cct, 1) << "Cannot load plugin for rgw_compression_type " - << compression_type << dendl; + << s->cct->_conf->rgw_compression_type << dendl; } else { compressor = boost::in_place(s->cct, plugin, filter); filter = &*compressor;