From 740b7809af540b4f3fe0cd3c0f05d5a25633ee0c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Mar 2018 19:46:03 -0600 Subject: [PATCH] osd: use rctx transaction for PG removal In the normal case, queue up the removal work on the rctx transaction. For the final cleanup, since we need to block, dispatch it ourselves, and do not do so in OSD.cc. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 15 +++++++++++++++ src/osd/OSD.h | 1 + src/osd/PG.cc | 25 ++++++++++--------------- src/osd/PG.h | 2 +- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index bb000d4a9f0d8..1745f92a6af90 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -8187,6 +8187,15 @@ void OSD::dispatch_context(PG::RecoveryCtx &ctx, PG *pg, OSDMapRef curmap, } } +void OSD::discard_context(PG::RecoveryCtx& ctx) +{ + delete ctx.notify_list; + delete ctx.query_map; + delete ctx.info_map; + delete ctx.transaction; +} + + /** do_notifies * Send an MOSDPGNotify to a primary, with a list of PGs that I have * content for, and they are primary for. @@ -8839,6 +8848,12 @@ void OSD::dequeue_peering_evt( advance_pg(curmap->get_epoch(), pg, handle, &rctx); } pg->do_peering_event(evt, &rctx); + if (pg->is_deleted()) { + // do not dispatch rctx; the final _delete_some already did it. + discard_context(rctx); + pg->unlock(); + return; + } dispatch_context_transaction(rctx, pg, &handle); need_up_thru = pg->get_need_up_thru(); same_interval_since = pg->get_same_interval_since(); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 27422bb29c858..e9a52fd011173 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1977,6 +1977,7 @@ protected: ThreadPool::TPHandle *handle = NULL); void dispatch_context_transaction(PG::RecoveryCtx &ctx, PG *pg, ThreadPool::TPHandle *handle = NULL); + void discard_context(PG::RecoveryCtx &ctx); void do_notifies(map > >& notify_list, diff --git a/src/osd/PG.cc b/src/osd/PG.cc index c0d608dbda329..9a551656d471b 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -6483,12 +6483,11 @@ struct C_DeleteMore : public Context { } }; -void PG::_delete_some() +void PG::_delete_some(ObjectStore::Transaction *t) { dout(10) << __func__ << dendl; vector olist; - ObjectStore::Transaction t; int max = std::min(osd->store->get_ideal_list_max(), (int)cct->_conf->osd_target_transaction_size); ghobject_t next; @@ -6501,7 +6500,7 @@ void PG::_delete_some() &next); dout(20) << __func__ << " " << olist << dendl; - OSDriver::OSTransaction _t(osdriver.get_transaction(&t)); + OSDriver::OSTransaction _t(osdriver.get_transaction(t)); int64_t num = 0; for (auto& oid : olist) { if (oid.is_pgmeta()) { @@ -6511,17 +6510,14 @@ void PG::_delete_some() if (r != 0 && r != -ENOENT) { ceph_abort(); } - t.remove(coll, oid); + t->remove(coll, oid); ++num; } epoch_t e = get_osdmap()->get_epoch(); if (num) { dout(20) << __func__ << " deleting " << num << " objects" << dendl; Context *fin = new C_DeleteMore(this, e); - t.register_on_commit(fin); - osd->store->queue_transaction( - ch, - std::move(t)); + t->register_on_commit(fin); } else { dout(20) << __func__ << " finished" << dendl; if (cct->_conf->osd_inject_failure_on_pg_removal) { @@ -6531,13 +6527,12 @@ void PG::_delete_some() // final flush here to ensure completions drop refs. Of particular concern // are the SnapMapper ContainerContexts. { - ObjectStore::Transaction t; PGRef pgref(this); - PGLog::clear_info_log(info.pgid, &t); - t.remove_collection(coll); - t.register_on_commit(new ContainerContext(pgref)); - t.register_on_applied(new ContainerContext(pgref)); - osd->store->queue_transaction(ch, std::move(t)); + PGLog::clear_info_log(info.pgid, t); + t->remove_collection(coll); + t->register_on_commit(new ContainerContext(pgref)); + t->register_on_applied(new ContainerContext(pgref)); + osd->store->queue_transaction(ch, std::move(*t)); } ch->flush(); @@ -8512,7 +8507,7 @@ boost::statechart::result PG::RecoveryState::Deleting::react( const DeleteSome& evt) { PG *pg = context< RecoveryMachine >().pg; - pg->_delete_some(); + pg->_delete_some(context().get_cur_transaction()); return discard_event(); } diff --git a/src/osd/PG.h b/src/osd/PG.h index 947c3b14b77c3..186703f32e0f4 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -477,7 +477,7 @@ public: virtual void on_removal(ObjectStore::Transaction *t) = 0; - void _delete_some(); + void _delete_some(ObjectStore::Transaction *t); // reference counting #ifdef PG_DEBUG_REFS -- 2.39.5