diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index bf2b67fe8bb..0efd2a598dd 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -6168,7 +6168,10 @@ int RGWRados::Object::Read::prepare() state.obj = astate->obj; store->obj_to_raw(bucket_info.placement_rule, state.obj, &state.head_obj); - r = store->get_obj_head_ioctx(bucket_info, state.obj, &state.io_ctx); + state.cur_pool = state.head_obj.pool; + state.cur_ioctx = &state.io_ctxs[state.cur_pool]; + + r = store->get_obj_head_ioctx(bucket_info, state.obj, state.cur_ioctx); if (r < 0) { return r; } @@ -6492,8 +6495,6 @@ int RGWRados::Object::Read::read(int64_t ofs, int64_t end, bufferlist& bl) len = max_chunk_size; - state.io_ctx.locator_set_key(read_obj.loc); - read_len = len; if (reading_from_head) { @@ -6525,7 +6526,24 @@ int RGWRados::Object::Read::read(int64_t ofs, int64_t end, bufferlist& bl) ldout(cct, 20) << "rados->read obj-ofs=" << ofs << " read_ofs=" << read_ofs << " read_len=" << read_len << dendl; op.read(read_ofs, read_len, pbl, NULL); - r = state.io_ctx.operate(read_obj.oid, &op, NULL); + if (state.cur_pool != read_obj.pool) { + auto iter = state.io_ctxs.find(read_obj.pool); + if (iter == state.io_ctxs.end()) { + state.cur_ioctx = &state.io_ctxs[read_obj.pool]; + r = store->open_pool_ctx(read_obj.pool, *state.cur_ioctx); + if (r < 0) { + ldout(cct, 20) << "ERROR: failed to open pool context for pool=" << read_obj.pool << " r=" << r << dendl; + return r; + } + } else { + state.cur_ioctx = &iter->second; + } + state.cur_pool = read_obj.pool; + } + + state.cur_ioctx->locator_set_key(read_obj.loc); + + r = state.cur_ioctx->operate(read_obj.oid, &op, NULL); ldout(cct, 20) << "rados->read r=" << r << " bl.length=" << bl.length() << dendl; if (r < 0) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 172bd68747f..06ca96ea68c 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1548,7 +1548,9 @@ public: RGWRados::Object *source; struct GetObjState { - librados::IoCtx io_ctx; + map io_ctxs; + rgw_pool cur_pool; + librados::IoCtx *cur_ioctx{nullptr}; rgw_obj obj; rgw_raw_obj head_obj; } state; diff --git a/src/rgw/rgw_torrent.cc b/src/rgw/rgw_torrent.cc index 7a4753e16c9..c8786ee9a7e 100644 --- a/src/rgw/rgw_torrent.cc +++ b/src/rgw/rgw_torrent.cc @@ -68,7 +68,7 @@ int seed::get_torrent_file(RGWRados::Object::Read &read_op, const set obj_key{RGW_OBJ_TORRENT}; map m; - const int r = read_op.state.io_ctx.omap_get_vals_by_keys(oid, obj_key, &m); + const int r = read_op.state.cur_ioctx->omap_get_vals_by_keys(oid, obj_key, &m); if (r < 0) { ldout(s->cct, 0) << "ERROR: omap_get_vals_by_keys failed: " << r << dendl; return r;