]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/btree: add interfaces to check whether the mappings'
authorXuehan Xu <xuxuehan@qianxin.com>
Tue, 11 Jun 2024 05:00:49 +0000 (13:00 +0800)
committerMatan Breizman <mbreizma@redhat.com>
Thu, 25 Jul 2024 07:39:22 +0000 (10:39 +0300)
parents have been modified

Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
(cherry picked from commit 10c0f2ab0af4aff8ef182b95830e25d036fe2e3f)

src/crimson/os/seastore/btree/btree_range_pin.cc
src/crimson/os/seastore/btree/fixed_kv_node.h
src/crimson/os/seastore/cached_extent.h
src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h
src/crimson/os/seastore/lba_manager/btree/lba_btree_node.cc
src/crimson/os/seastore/lba_manager/btree/lba_btree_node.h
src/crimson/os/seastore/transaction_manager.h

index ac04705aaf0672398f95fd9ba7ac904fd677a9ab..ad6abdf4ee80f6f8b10f33ea8fa8fe62f21e4d92 100644 (file)
@@ -28,7 +28,7 @@ BtreeNodeMapping<key_t, val_t>::get_logical_extent(
 template <typename key_t, typename val_t>
 bool BtreeNodeMapping<key_t, val_t>::is_stable() const
 {
-  assert(is_parent_valid());
+  assert(!this->parent_modified());
   assert(pos != std::numeric_limits<uint16_t>::max());
   auto &p = (FixedKVNode<key_t>&)*parent;
   return p.is_child_stable(ctx, pos);
@@ -37,7 +37,7 @@ bool BtreeNodeMapping<key_t, val_t>::is_stable() const
 template <typename key_t, typename val_t>
 bool BtreeNodeMapping<key_t, val_t>::is_data_stable() const
 {
-  assert(is_parent_valid());
+  assert(!this->parent_modified());
   assert(pos != std::numeric_limits<uint16_t>::max());
   auto &p = (FixedKVNode<key_t>&)*parent;
   return p.is_child_data_stable(ctx, pos);
index 79495cb35d129607e6719f27cbb4cff897ccd592..ea61d6b9933d227d8a821cedf9d85f21a6244438 100644 (file)
@@ -1004,14 +1004,29 @@ struct FixedKVLeafNode
       node_layout_t(this->get_bptr().c_str()) {}
   FixedKVLeafNode(const FixedKVLeafNode &rhs)
     : FixedKVNode<NODE_KEY>(rhs),
-      node_layout_t(this->get_bptr().c_str()) {}
+      node_layout_t(this->get_bptr().c_str()),
+      modifications(rhs.modifications) {}
 
   static constexpr bool do_has_children = has_children;
+  // for the stable extent, modifications is always 0;
+  // it will increase for each transaction-local change, so that
+  // modifications can be detected (see BtreeLBAMapping.parent_modifications)
+  uint64_t modifications = 0;
+
 
   bool have_children() const final {
     return do_has_children;
   }
 
+  void on_modify() {
+    modifications++;
+  }
+
+  bool modified_since(uint64_t v) const {
+    ceph_assert(v <= modifications);
+    return v != modifications;
+  }
+
   bool is_leaf_and_has_children() const final {
     return has_children;
   }
@@ -1108,6 +1123,7 @@ struct FixedKVLeafNode
        this->copy_sources.clear();
       }
     }
+    modifications = 0;
     assert(this->is_initial_pending()
       ? this->copy_sources.empty():
       true);
@@ -1129,6 +1145,7 @@ struct FixedKVLeafNode
     } else {
       this->set_parent_tracker_from_prior_instance();
     }
+    modifications = 0;
   }
 
   uint16_t lower_bound_offset(NODE_KEY key) const final {
index 5c68207e80ca69e9565b80bb39a828b923e88e9b..d26d61f25a2298385572e12f564339441e4dc1cf 100644 (file)
@@ -1152,6 +1152,10 @@ public:
     return !get_val().is_real();
   }
   virtual bool is_parent_valid() const = 0;
+  virtual bool parent_modified() const {
+    ceph_abort("impossible");
+    return false;
+  };
 
   virtual ~PhysicalNodeMapping() {}
 protected:
index 43807efb5fcf94dc00356f692c41224111c8beb0..ac2274676db59e73c9f79b3e7fefd258bb03d2c7 100644 (file)
@@ -62,7 +62,7 @@ public:
     : BtreeNodeMapping(ctx) {}
   BtreeLBAMapping(
     op_context_t<laddr_t> c,
-    CachedExtentRef parent,
+    LBALeafNodeRef parent,
     uint16_t pos,
     lba_map_val_t &val,
     lba_node_meta_t meta)
@@ -78,7 +78,8 @@ public:
       intermediate_key(indirect ? val.pladdr.get_laddr() : L_ADDR_NULL),
       intermediate_length(indirect ? val.len : 0),
       raw_val(val.pladdr),
-      map_val(val)
+      map_val(val),
+      parent_modifications(parent->modifications)
   {}
 
   lba_map_val_t get_map_val() const {
@@ -154,6 +155,17 @@ public:
     len = length;
   }
 
+  uint64_t get_parent_modifications() const {
+    return parent_modifications;
+  }
+
+  bool parent_modified() const final {
+    ceph_assert(parent);
+    ceph_assert(is_parent_valid());
+    auto &p = static_cast<LBALeafNode&>(*parent);
+    return p.modified_since(parent_modifications);
+  }
+
 protected:
   std::unique_ptr<BtreeNodeMapping<laddr_t, paddr_t>> _duplicate(
     op_context_t<laddr_t> ctx) const final {
@@ -165,6 +177,7 @@ protected:
     pin->indirect = indirect;
     pin->raw_val = raw_val;
     pin->map_val = map_val;
+    pin->parent_modifications = parent_modifications;
     return pin;
   }
 private:
@@ -175,6 +188,7 @@ private:
   extent_len_t intermediate_length = 0;
   pladdr_t raw_val;
   lba_map_val_t map_val;
+  uint64_t parent_modifications = 0;
 };
 
 using BtreeLBAMappingRef = std::unique_ptr<BtreeLBAMapping>;
index 66dc94394a99e16ccdacff22ebe3808d53cff470..730da546cb0e23602d6404cbf0f0f7c7628d7ad5 100644 (file)
@@ -31,6 +31,7 @@ std::ostream &LBALeafNode::_print_detail(std::ostream &out) const
 {
   out << ", size=" << this->get_size()
       << ", meta=" << this->get_meta()
+      << ", modifications=" << this->modifications
       << ", my_tracker=" << (void*)this->my_tracker;
   if (this->my_tracker) {
     out << ", my_tracker->parent=" << (void*)this->my_tracker->get_parent().get();
index c5da860e24ff8c5493474eaaa6417ff5eac17cb6..ff06bf81039d4a218abab5eebb36671b5aa980fb 100644 (file)
@@ -202,6 +202,7 @@ struct LBALeafNode
       assert(nextent->has_parent_tracker()
        && nextent->get_parent_node<LBALeafNode>().get() == this);
     }
+    this->on_modify();
     if (val.pladdr.is_paddr()) {
       val.pladdr = maybe_generate_relative(val.pladdr.get_paddr());
     }
@@ -222,6 +223,7 @@ struct LBALeafNode
       iter.get_offset(),
       addr,
       (void*)nextent);
+    this->on_modify();
     this->insert_child_ptr(iter, nextent);
     if (val.pladdr.is_paddr()) {
       val.pladdr = maybe_generate_relative(val.pladdr.get_paddr());
@@ -241,6 +243,7 @@ struct LBALeafNode
       iter.get_offset(),
       iter.get_key());
     assert(iter != this->end());
+    this->on_modify();
     this->remove_child_ptr(iter);
     return this->journal_remove(
       iter,
index f6bbc8aa4152b106258d4989af380db704b15beb..1fbdcd21fd065964c9785b4e16701c63ba5c6fdb 100644 (file)
@@ -221,7 +221,7 @@ public:
     LBAMappingRef pin,
     extent_types_t type)
   {
-    ceph_assert(pin->is_parent_valid());
+    ceph_assert(!pin->parent_modified());
     auto v = pin->get_logical_extent(t);
     // checking the lba child must be atomic with creating
     // and linking the absent child