]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/cache: introduce maybe_add_to_read_set() 58983/head
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 5 Aug 2024 08:04:26 +0000 (16:04 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Mon, 5 Aug 2024 08:08:08 +0000 (16:08 +0800)
And only touch extent if it is absent in transaction.

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

index 779df4f6f524bdf0fe9adc5e367aa13f6ac31deb..4441df86d4e9596c75099a04853e964a1cc6df9f 100644 (file)
@@ -494,8 +494,9 @@ public:
       } else {
         // stable from trans-view
         assert(!p_extent->is_pending_in_trans(t.get_trans_id()));
-        t.add_to_read_set(p_extent);
-        touch_extent(*p_extent);
+        if (t.maybe_add_to_read_set(p_extent)) {
+          touch_extent(*p_extent);
+        }
       }
     } else {
       assert(!extent->is_stable_writting());
index d7cdb30098a0fe34693fd93233d5b64f6564f032..2fa468fb48e07c38c2407cb05f32152fd370c09f 100644 (file)
@@ -137,14 +137,37 @@ public:
     }
   }
 
+  // Returns true if added, false if already added or weak
+  bool maybe_add_to_read_set(CachedExtentRef ref) {
+    if (is_weak()) {
+      return false;
+    }
+
+    assert(ref->is_valid());
+
+    auto it = ref->transactions.lower_bound(
+      this, read_set_item_t<Transaction>::trans_cmp_t());
+    if (it != ref->transactions.end() && it->t == this) {
+      return false;
+    }
+
+    auto [iter, inserted] = read_set.emplace(this, ref);
+    ceph_assert(inserted);
+    ref->transactions.insert_before(
+      it, const_cast<read_set_item_t<Transaction>&>(*iter));
+    return true;
+  }
+
   void add_to_read_set(CachedExtentRef ref) {
-    if (is_weak()) return;
+    if (is_weak()) {
+      return;
+    }
 
     assert(ref->is_valid());
 
     auto it = ref->transactions.lower_bound(
       this, read_set_item_t<Transaction>::trans_cmp_t());
-    if (it != ref->transactions.end() && it->t == this) return;
+    assert(it == ref->transactions.end() || it->t != this);
 
     auto [iter, inserted] = read_set.emplace(this, ref);
     ceph_assert(inserted);