]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: introduce get_or_load_obc() 48345/head
authorMatan Breizman <mbreizma@redhat.com>
Mon, 3 Oct 2022 10:21:50 +0000 (10:21 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Tue, 18 Oct 2022 13:44:39 +0000 (13:44 +0000)
Both with_head/clone_obc make use of this logic.

Signed-off-by: Matan Breizman <mbreizma@redhat.com>
src/crimson/osd/pg.cc
src/crimson/osd/pg.h

index 4301394b64b719c10122bb7b0c163c57d58b5e72..f232375403fe3d7e17d4baf4955e6291a10a9915 100644 (file)
@@ -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<State, IOInterruptCondition>(
     [existed=existed, obc=obc, func=std::move(func), this] {
-    auto loaded = load_obc_iertr::make_ready_future<ObjectContextRef>(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<State, IOInterruptCondition>([this, obc] {
-        return load_obc(obc);
-      });
-    }
-    return loaded.safe_then_interruptible([func = std::move(func)](auto obc) {
+    return get_or_load_obc<State>(obc, existed).safe_then_interruptible(
+      [func = std::move(func)](auto obc) {
       return std::move(func)(std::move(obc));
     });
   }).finally([this, pgref=boost::intrusive_ptr<PG>{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<State, IOInterruptCondition>(
       [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<ObjectContextRef>(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<State, IOInterruptCondition>(
-          [clone, this] {
-          return load_obc(clone);
-        });
-      }
+      auto loaded = get_or_load_obc<State>(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<RWState::State State>
+PG::load_obc_iertr::future<crimson::osd::ObjectContextRef>
+PG::get_or_load_obc(
+    crimson::osd::ObjectContextRef obc,
+    bool existed)
+{
+  auto loaded = load_obc_iertr::make_ready_future<ObjectContextRef>(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<State, IOInterruptCondition>(
+      [obc, this] {
+      return load_obc(obc);
+    });
+  }
+  return loaded;
+}
+
 PG::load_obc_iertr::future<>
 PG::reload_obc(crimson::osd::ObjectContext& obc) const
 {
index 4f4f9cb21b1952cbf81cbf2cd457e7ff21d5ce77..5660aa5183b46caf69d9b0e2e9c51de9008fb630 100644 (file)
@@ -517,14 +517,11 @@ public:
       load_obc_ertr>;
   using interruptor = ::crimson::interruptible::interruptor<
     ::crimson::osd::IOInterruptCondition>;
-  load_obc_iertr::future<
-    std::pair<crimson::osd::ObjectContextRef, bool>>
-  get_or_load_clone_obc(
-    hobject_t oid, crimson::osd::ObjectContextRef head_obc);
-
-  load_obc_iertr::future<
-    std::pair<crimson::osd::ObjectContextRef, bool>>
-  get_or_load_head_obc(hobject_t oid);
+
+  template<RWState::State State>
+  load_obc_iertr::future<crimson::osd::ObjectContextRef>
+  get_or_load_obc(
+    crimson::osd::ObjectContextRef head_obc, bool existed);
 
   load_obc_iertr::future<crimson::osd::ObjectContextRef>
   load_obc(ObjectContextRef obc);