Skip to content

Commit 308ec88

Browse files
authored
Merge pull request ceph#59864 from cbodley/wip-68134
rgw/rados: RGWRados::delete_objs_inline() uses AioThrottle Reviewed-by: Pritha Srivastava <[email protected]>
2 parents 5e9dcaf + f39c5f5 commit 308ec88

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

src/cls/rgw/cls_rgw_types.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <string>
77
#include <list>
8+
#include <vector>
89
#include <boost/container/flat_map.hpp>
910
#include "common/ceph_time.h"
1011
#include "common/Formatter.h"
@@ -1197,16 +1198,14 @@ struct cls_rgw_obj {
11971198
WRITE_CLASS_ENCODER(cls_rgw_obj)
11981199

11991200
struct cls_rgw_obj_chain {
1200-
std::list<cls_rgw_obj> objs;
1201-
1202-
cls_rgw_obj_chain() {}
1201+
std::vector<cls_rgw_obj> objs;
12031202

12041203
void push_obj(const std::string& pool, const cls_rgw_obj_key& key, const std::string& loc) {
12051204
cls_rgw_obj obj;
12061205
obj.pool = pool;
12071206
obj.key = key;
12081207
obj.loc = loc;
1209-
objs.push_back(obj);
1208+
objs.push_back(std::move(obj));
12101209
}
12111210

12121211
void encode(ceph::buffer::list& bl) const {
@@ -1223,9 +1222,9 @@ struct cls_rgw_obj_chain {
12231222

12241223
void dump(ceph::Formatter *f) const {
12251224
f->open_array_section("objs");
1226-
for (std::list<cls_rgw_obj>::const_iterator p = objs.begin(); p != objs.end(); ++p) {
1225+
for (const auto& o : objs) {
12271226
f->open_object_section("obj");
1228-
p->dump(f);
1227+
o.dump(f);
12291228
f->close_section();
12301229
}
12311230
f->close_section();

src/rgw/driver/rados/rgw_gc.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ int RGWGC::process(int index, int max_secs, bool expired_only,
653653
info.tag << "', time=" << info.time << ", chain.objs.size()=" <<
654654
info.chain.objs.size() << dendl;
655655

656-
std::list<cls_rgw_obj>::iterator liter;
657656
cls_rgw_obj_chain& chain = info.chain;
658657

659658
utime_t now = ceph_clock_now();
@@ -668,9 +667,7 @@ int RGWGC::process(int index, int max_secs, bool expired_only,
668667
}
669668
}
670669
if (! chain.objs.empty()) {
671-
for (liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) {
672-
cls_rgw_obj& obj = *liter;
673-
670+
for (const auto& obj : chain.objs) {
674671
if (obj.pool != last_pool) {
675672
delete ctx;
676673
ctx = new IoCtx;

src/rgw/driver/rados/rgw_rados.cc

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,33 +5369,41 @@ std::tuple<int, std::optional<cls_rgw_obj_chain>> RGWRados::send_chain_to_gc(cls
53695369
void RGWRados::delete_objs_inline(const DoutPrefixProvider *dpp, cls_rgw_obj_chain& chain,
53705370
const string& tag, optional_yield y)
53715371
{
5372-
string last_pool;
5373-
std::unique_ptr<IoCtx> ctx(new IoCtx);
5374-
int ret = 0;
5375-
for (auto liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) {
5376-
cls_rgw_obj& obj = *liter;
5377-
if (obj.pool != last_pool) {
5378-
ctx.reset(new IoCtx);
5379-
ret = rgw_init_ioctx(dpp, get_rados_handle(), obj.pool, *ctx);
5380-
if (ret < 0) {
5381-
last_pool = "";
5382-
ldpp_dout(dpp, 0) << "ERROR: failed to create ioctx pool=" <<
5383-
obj.pool << dendl;
5384-
continue;
5385-
}
5386-
last_pool = obj.pool;
5387-
}
5388-
ctx->locator_set_key(obj.loc);
5389-
const string& oid = obj.key.name; /* just stored raw oid there */
5390-
ldpp_dout(dpp, 5) << "delete_objs_inline: removing " << obj.pool <<
5391-
":" << obj.key.name << dendl;
5372+
if (chain.objs.empty()) {
5373+
return;
5374+
}
5375+
5376+
// initialize an IoCtx for the first object's pool. RGWObjManifest uses the
5377+
// same pool for all tail objects
5378+
auto obj = chain.objs.begin();
5379+
5380+
librados::IoCtx ioctx;
5381+
int ret = rgw_init_ioctx(dpp, get_rados_handle(), obj->pool, ioctx);
5382+
if (ret < 0) {
5383+
return;
5384+
}
5385+
5386+
// issue deletions in parallel, up to max_aio at a time
5387+
auto aio = rgw::make_throttle(cct->_conf->rgw_multi_obj_del_max_aio, y);
5388+
static constexpr uint64_t cost = 1; // 1 throttle unit per request
5389+
static constexpr uint64_t id = 0; // ids unused
5390+
5391+
for (; obj != chain.objs.end(); ++obj) {
53925392
ObjectWriteOperation op;
53935393
cls_refcount_put(op, tag, true);
5394-
ret = rgw_rados_operate(dpp, *ctx, oid, &op, y);
5395-
if (ret < 0) {
5396-
ldpp_dout(dpp, 5) << "delete_objs_inline: refcount put returned error " << ret << dendl;
5397-
}
5394+
5395+
rgw_raw_obj raw;
5396+
raw.pool = std::move(obj->pool);
5397+
raw.oid = std::move(obj->key.name);
5398+
raw.loc = std::move(obj->loc);
5399+
5400+
auto completed = aio->get(std::move(raw), rgw::Aio::librados_op(
5401+
ioctx, std::move(op), y), cost, id);
5402+
std::ignore = rgw::check_for_errors(completed);
53985403
}
5404+
5405+
auto completed = aio->drain();
5406+
std::ignore = rgw::check_for_errors(completed);
53995407
}
54005408

54015409
static void accumulate_raw_stats(const rgw_bucket_dir_header& header,

src/rgw/rgw_admin.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8806,10 +8806,7 @@ int main(int argc, const char **argv)
88068806
formatter->dump_string("tag", info.tag);
88078807
formatter->dump_stream("time") << info.time;
88088808
formatter->open_array_section("objs");
8809-
list<cls_rgw_obj>::iterator liter;
8810-
cls_rgw_obj_chain& chain = info.chain;
8811-
for (liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) {
8812-
cls_rgw_obj& obj = *liter;
8809+
for (const auto& obj : info.chain.objs) {
88138810
encode_json("obj", obj, formatter.get());
88148811
}
88158812
formatter->close_section(); // objs

src/test/cls_rgw/test_cls_rgw.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ TEST_F(cls_rgw, gc_set)
854854
/* verify expected num of objects in chain */
855855
ASSERT_EQ(2, (int)entry.chain.objs.size());
856856

857-
list<cls_rgw_obj>::iterator oiter = entry.chain.objs.begin();
857+
auto oiter = entry.chain.objs.begin();
858858
cls_rgw_obj obj1, obj2;
859859

860860
/* create expected objects */
@@ -932,7 +932,7 @@ TEST_F(cls_rgw, gc_list)
932932
/* verify expected num of objects in chain */
933933
ASSERT_EQ(2, (int)entry.chain.objs.size());
934934

935-
list<cls_rgw_obj>::iterator oiter = entry.chain.objs.begin();
935+
auto oiter = entry.chain.objs.begin();
936936
cls_rgw_obj obj1, obj2;
937937

938938
/* create expected objects */

0 commit comments

Comments
 (0)