]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/cache: count invalidated transactions
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 7 Jul 2021 01:46:32 +0000 (09:46 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Wed, 14 Jul 2021 02:52:29 +0000 (10:52 +0800)
Labeled by source and extent-type.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/cache.h
src/crimson/os/seastore/seastore_types.h

index a9482f195fd40585d627723e70d6928c72123a74..fdf88d9f27bf9758c10ad58f74f239ed7394ef08 100644 (file)
@@ -96,6 +96,22 @@ void Cache::register_metrics()
     {src_t::CLEANER, src_label("CLEANER")},
   };
 
+  auto ext_label = sm::label("ext");
+  std::map<extent_types_t, sm::label_instance> labels_by_ext {
+    {extent_types_t::ROOT,                ext_label("ROOT")},
+    {extent_types_t::LADDR_INTERNAL,      ext_label("LADDR_INTERNAL")},
+    {extent_types_t::LADDR_LEAF,          ext_label("LADDR_LEAF")},
+    {extent_types_t::OMAP_INNER,          ext_label("OMAP_INNER")},
+    {extent_types_t::OMAP_LEAF,           ext_label("OMAP_LEAF")},
+    {extent_types_t::ONODE_BLOCK_STAGED,  ext_label("ONODE_BLOCK_STAGED")},
+    {extent_types_t::COLL_BLOCK,          ext_label("COLL_BLOCK")},
+    {extent_types_t::OBJECT_DATA_BLOCK,   ext_label("OBJECT_DATA_BLOCK")},
+    {extent_types_t::RETIRED_PLACEHOLDER, ext_label("RETIRED_PLACEHOLDER")},
+    {extent_types_t::RBM_ALLOC_INFO,      ext_label("RBM_ALLOC_INFO")},
+    {extent_types_t::TEST_BLOCK,          ext_label("TEST_BLOCK")},
+    {extent_types_t::TEST_BLOCK_PHYSICAL, ext_label("TEST_BLOCK_PHYSICAL")}
+  };
+
   /*
    * trans_created
    */
@@ -181,6 +197,54 @@ void Cache::register_metrics()
       ),
     }
   );
+
+  /*
+   * trans_invalidated
+   */
+  auto register_trans_invalidated =
+    [this, &labels_by_src, &labels_by_ext](src_t src, extent_types_t ext) {
+      auto m_key = std::make_pair(src, ext);
+      stats.trans_invalidated[m_key] = 0;
+      std::ostringstream oss_desc;
+      oss_desc << "total number of transaction invalidated (src="
+               << src << ", ext="
+               << ext << ")";
+      metrics.add_group(
+        "cache",
+        {
+          sm::make_counter(
+            "trans_invalidated",
+            stats.trans_invalidated.find(m_key)->second,
+            sm::description(oss_desc.str()),
+            {labels_by_src.find(src)->second,
+             labels_by_ext.find(ext)->second}
+          ),
+        }
+      );
+    };
+  for (auto& [src, label] : labels_by_src) {
+    for (auto& [ext, _label] : labels_by_ext) {
+      register_trans_invalidated(src, ext);
+    }
+  }
+
+  metrics.add_group(
+    "cache",
+    {
+      sm::make_counter(
+        "trans_invalidated",
+        [this] {
+          uint64_t total = 0;
+          for (auto& [k, v] : stats.trans_invalidated) {
+            total += v;
+          }
+          return total;
+        },
+        sm::description("total number of transaction invalidated"),
+        {src_label("ALL")}
+      ),
+    }
+  );
 }
 
 void Cache::add_extent(CachedExtentRef ref)
@@ -283,9 +347,19 @@ void Cache::replace_extent(CachedExtentRef next, CachedExtentRef prev)
 }
 
 void Cache::invalidate(CachedExtent &extent) {
+  LOG_PREFIX(Cache::invalidate);
+  DEBUG("invalidate begin -- extent {}", extent);
   for (auto &&i: extent.transactions) {
-    i.t->conflicted = true;
+    if (!i.t->conflicted) {
+      DEBUGT("", i.t);
+      i.t->conflicted = true;
+      assert(!i.t->is_weak());
+      auto m_key = std::make_pair(i.t->get_src(), extent.get_type());
+      assert(stats.trans_invalidated.count(m_key));
+      ++(stats.trans_invalidated[m_key]);
+    }
   }
+  DEBUG("invalidate end");
   extent.state = CachedExtent::extent_state_t::INVALID;
 }
 
index 897dc3d7ff3828349736fe04e40be38e03fac77e..452fff7dccb12cdfaae104dbddb26cbed6ff5416 100644 (file)
@@ -296,9 +296,14 @@ public:
       return trans_intr::make_interruptible(
        get_extent<T>(offset, length)
       ).si_then(
-       [&t](auto ref) mutable {
+       [&t, this](auto ref) {
          if (!ref->is_valid()) {
+           LOG_PREFIX(Cache::get_extent);
+           DEBUGT("got invalid extent: {}", t, ref);
            t.conflicted = true;
+           auto m_key = std::make_pair(t.get_src(), T::TYPE);
+           assert(stats.trans_invalidated.count(m_key));
+           ++(stats.trans_invalidated[m_key]);
            return get_extent_iertr::make_ready_future<TCachedExtentRef<T>>();
          } else {
            t.add_to_read_set(ref);
@@ -343,7 +348,12 @@ public:
        get_extent_by_type(type, offset, laddr, length)
       ).si_then([=, &t](CachedExtentRef ret) {
         if (!ret->is_valid()) {
+          LOG_PREFIX(Cache::get_extent_by_type);
+          DEBUGT("got invalid extent: {}", t, ret);
           t.conflicted = true;
+          auto m_key = std::make_pair(t.get_src(), type);
+          assert(stats.trans_invalidated.count(m_key));
+          ++(stats.trans_invalidated[m_key]);
           return get_extent_ertr::make_ready_future<CachedExtentRef>();
         } else {
           t.add_to_read_set(ret);
@@ -572,9 +582,12 @@ private:
    */
   CachedExtent::list dirty;
 
+  using src_ext_t = std::pair<Transaction::src_t, extent_types_t>;
   struct {
     std::array<uint64_t, Transaction::SRC_MAX> trans_created_by_src;
     std::array<uint64_t, Transaction::SRC_MAX> trans_committed_by_src;
+    std::unordered_map<src_ext_t, uint64_t,
+                       boost::hash<src_ext_t>> trans_invalidated;
   } stats;
   uint64_t& get_counter(
       std::array<uint64_t, Transaction::SRC_MAX>& counters_by_src,
index 5a7a11a5f252f42d2346de6b09ddb5faff969e65..53316be75c8b409062bb41d1491170337a9328b7 100644 (file)
@@ -713,6 +713,18 @@ struct rbm_alloc_delta_t {
 
 }
 
+namespace std {
+
+template<>
+struct hash<::crimson::os::seastore::extent_types_t> {
+  std::size_t operator()(
+      const ::crimson::os::seastore::extent_types_t& type) const noexcept {
+    return std::hash<uint8_t>{}((uint8_t)type);
+  }
+};
+
+}
+
 WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::seastore_meta_t)
 WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::paddr_t)
 WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::journal_seq_t)