From: Matan Breizman Date: Mon, 3 Oct 2022 10:21:50 +0000 (+0000) Subject: crimson/osd: introduce get_or_load_obc() X-Git-Tag: v18.1.0~965^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F48345%2Fhead;p=ceph.git crimson/osd: introduce get_or_load_obc() Both with_head/clone_obc make use of this logic. Signed-off-by: Matan Breizman --- diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index 4301394b64b7..f232375403fe 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -1023,16 +1023,8 @@ PG::with_head_obc(ObjectContextRef obc, bool existed, with_obc_func_t&& func) obc->append_to(obc_set_accessing); return obc->with_lock( [existed=existed, obc=obc, func=std::move(func), this] { - auto loaded = load_obc_iertr::make_ready_future(obc); - if (existed) { - logger().debug("with_head_obc: found {} in cache", obc->get_oid()); - } else { - logger().debug("with_head_obc: cache miss on {}", obc->get_oid()); - loaded = obc->with_promoted_lock([this, obc] { - return load_obc(obc); - }); - } - return loaded.safe_then_interruptible([func = std::move(func)](auto obc) { + return get_or_load_obc(obc, existed).safe_then_interruptible( + [func = std::move(func)](auto obc) { return std::move(func)(std::move(obc)); }); }).finally([this, pgref=boost::intrusive_ptr{this}, obc=std::move(obc)] { @@ -1080,16 +1072,7 @@ PG::with_clone_obc(hobject_t oid, with_obc_func_t&& func) return clone->template with_lock( [existed=existed, head=std::move(head), clone=std::move(clone), func=std::move(func), this]() -> load_obc_iertr::future<> { - auto loaded = load_obc_iertr::make_ready_future(clone); - if (existed) { - logger().debug("with_clone_obc: found {} in cache", clone->get_oid()); - } else { - logger().debug("with_clone_obc: cache miss on {}", clone->get_oid()); - loaded = clone->template with_promoted_lock( - [clone, this] { - return load_obc(clone); - }); - } + auto loaded = get_or_load_obc(clone, existed); clone->head = head; return loaded.safe_then_interruptible([func = std::move(func)](auto clone) { return std::move(func)(std::move(clone)); @@ -1146,6 +1129,25 @@ PG::load_obc(ObjectContextRef obc) }); } +template +PG::load_obc_iertr::future +PG::get_or_load_obc( + crimson::osd::ObjectContextRef obc, + bool existed) +{ + auto loaded = load_obc_iertr::make_ready_future(obc); + if (existed) { + logger().debug("{}: found {} in cache", __func__, obc->get_oid()); + } else { + logger().debug("{}: cache miss on {}", __func__, obc->get_oid()); + loaded = obc->template with_promoted_lock( + [obc, this] { + return load_obc(obc); + }); + } + return loaded; +} + PG::load_obc_iertr::future<> PG::reload_obc(crimson::osd::ObjectContext& obc) const { diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 4f4f9cb21b19..5660aa5183b4 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -517,14 +517,11 @@ public: load_obc_ertr>; using interruptor = ::crimson::interruptible::interruptor< ::crimson::osd::IOInterruptCondition>; - load_obc_iertr::future< - std::pair> - get_or_load_clone_obc( - hobject_t oid, crimson::osd::ObjectContextRef head_obc); - - load_obc_iertr::future< - std::pair> - get_or_load_head_obc(hobject_t oid); + + template + load_obc_iertr::future + get_or_load_obc( + crimson::osd::ObjectContextRef head_obc, bool existed); load_obc_iertr::future load_obc(ObjectContextRef obc);