]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/onode-staged-tree: implement full_key_t.compare_to(full_key_t)
authorYingxin Cheng <yingxin.cheng@intel.com>
Thu, 4 Feb 2021 05:01:44 +0000 (13:01 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Thu, 4 Feb 2021 05:01:44 +0000 (13:01 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/onode_manager/staged-fltree/node.cc
src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h

index 771a8d588d34a0e2ac5c0c1cb5d96749dda02096..aae741182a74680286b8dcab6faf470008306651 100644 (file)
@@ -145,7 +145,7 @@ void tree_cursor_t::Cache::validate_is_latest(const LeafNode& node,
   assert(is_latest());
 #ifndef NDEBUG
   auto [_key_view, _p_value_header] = node.get_kv(pos);
-  assert(*key_view == _key_view);
+  assert(key_view->compare_to(_key_view) == MatchKindCMP::EQ);
   assert(p_value_header == _p_value_header);
 #endif
 }
@@ -634,7 +634,8 @@ void InternalNode::validate_child(const Node& child) const
     assert(child.impl->is_level_tail());
   } else {
     assert(!child.impl->is_level_tail());
-    assert(impl->get_key_view(child_pos) == child.impl->get_largest_key_view());
+    assert(impl->get_key_view(child_pos).compare_to(
+           child.impl->get_largest_key_view()) == MatchKindCMP::EQ);
   }
   // XXX(multi-type)
   assert(impl->field_type() <= child.impl->field_type());
@@ -874,7 +875,7 @@ void LeafNode::validate_cursor(const tree_cursor_t& cursor) const
   assert(!cursor.is_end());
   auto [key, p_value_header] = get_kv(cursor.get_position());
   auto magic = p_value_header->magic;
-  assert(key == cursor.get_key_view(magic));
+  assert(key.compare_to(cursor.get_key_view(magic)) == MatchKindCMP::EQ);
   assert(p_value_header == cursor.read_value_header(magic));
 #endif
 }
index 1088d1223e1ba406f1a9a546c257346ac813ff31..4407e495a9111925a317e9ffedefe15f7398b03f 100644 (file)
@@ -237,7 +237,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
       if (!result_raw.is_end()) {
         full_key_t<KeyT::VIEW> index;
         STAGE_T::get_key_view(node_stage, result_raw.position, index);
-        assert(index == *index_key);
+        assert(index.compare_to(*index_key) == MatchKindCMP::EQ);
       }
 #endif
     } else {
@@ -304,7 +304,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
       logger().trace("OTree::Layout::Insert: -- dump\n{}", sos.str());
     }
     validate_layout();
-    assert(get_key_view(insert_pos) == key);
+    assert(get_key_view(insert_pos).compare_to(key) == MatchKindCMP::EQ);
     return ret;
   }
 
@@ -474,10 +474,10 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
                      insert_pos, insert_stage);
       p_value = extent.template split_insert_replayable<KEY_TYPE>(
           split_at, key, value, insert_pos, insert_stage, insert_size);
-      assert(get_key_view(_insert_pos) == key);
+      assert(get_key_view(_insert_pos).compare_to(key) == MatchKindCMP::EQ);
     } else {
       logger().debug("OTree::Layout::Split: -- left trim ...");
-      assert(right_impl.get_key_view(_insert_pos) == key);
+      assert(right_impl.get_key_view(_insert_pos).compare_to(key) == MatchKindCMP::EQ);
       extent.split_replayable(split_at);
     }
     if (unlikely(logger().is_enabled(seastar::log_level::debug))) {
index cc1f546c1a96626621251ed2af108644e0666fa5..3455c7629f1854f043e05409a3f80e8d1a7dc8b0 100644 (file)
@@ -487,14 +487,8 @@ class key_hobj_t {
     return ghobj.generation;
   }
 
-  bool operator==(const full_key_t<KeyT::VIEW>& o) const;
-  bool operator==(const full_key_t<KeyT::HOBJ>& o) const;
-  bool operator!=(const full_key_t<KeyT::VIEW>& o) const {
-    return !operator==(o);
-  }
-  bool operator!=(const full_key_t<KeyT::HOBJ>& o) const {
-    return !operator==(o);
-  }
+  MatchKindCMP compare_to(const full_key_t<KeyT::VIEW>&) const;
+  MatchKindCMP compare_to(const full_key_t<KeyT::HOBJ>&) const;
 
   std::ostream& dump(std::ostream& os) const {
     os << "key_hobj(" << (unsigned)shard() << ","
@@ -582,14 +576,8 @@ class key_view_t {
     return snap_gen_packed().gen;
   }
 
-  bool operator==(const full_key_t<KeyT::VIEW>& o) const;
-  bool operator==(const full_key_t<KeyT::HOBJ>& o) const;
-  bool operator!=(const full_key_t<KeyT::VIEW>& o) const {
-    return !operator==(o);
-  }
-  bool operator!=(const full_key_t<KeyT::HOBJ>& o) const {
-    return !operator==(o);
-  }
+  MatchKindCMP compare_to(const full_key_t<KeyT::VIEW>&) const;
+  MatchKindCMP compare_to(const full_key_t<KeyT::HOBJ>&) const;
 
   /**
    * key_view_t specific interfaces
@@ -700,38 +688,44 @@ void encode_key(const full_key_t<KT>& key, ceph::bufferlist& bl) {
   ceph::encode(key.gen(), bl);
 }
 
-inline MatchKindCMP compare_to(std::string_view l, std::string_view r) {
-  return toMatchKindCMP(l, r);
-}
 template <KeyT TypeL, KeyT TypeR>
-bool compare_full_key(const full_key_t<TypeL>& l, const full_key_t<TypeR>& r) {
-  if (l.shard() != r.shard())
-    return false;
-  if (l.pool() != r.pool())
-    return false;
-  if (l.crush() != r.crush())
-    return false;
-  if (compare_to(l.nspace(), r.nspace()) != MatchKindCMP::EQ)
-    return false;
-  if (compare_to(l.oid(), r.oid()) != MatchKindCMP::EQ)
-    return false;
-  if (l.snap() != r.snap())
-    return false;
-  if (l.gen() != r.gen())
-    return false;
-  return true;
-}
-
-inline bool key_hobj_t::operator==(const full_key_t<KeyT::VIEW>& o) const {
+MatchKindCMP compare_full_key(
+    const full_key_t<TypeL>& l, const full_key_t<TypeR>& r) {
+  auto ret = toMatchKindCMP(l.shard(), r.shard());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  ret = toMatchKindCMP(l.pool(), r.pool());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  ret = toMatchKindCMP(l.crush() != r.crush());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  ret = toMatchKindCMP(l.nspace(), r.nspace());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  ret = toMatchKindCMP(l.oid(), r.oid());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  ret = toMatchKindCMP(l.snap(), r.snap());
+  if (ret != MatchKindCMP::EQ)
+    return ret;
+  return toMatchKindCMP(l.gen(), r.gen());
+}
+
+inline MatchKindCMP key_hobj_t::compare_to(
+    const full_key_t<KeyT::VIEW>& o) const {
   return compare_full_key<KeyT::HOBJ, KeyT::VIEW>(*this, o);
 }
-inline bool key_hobj_t::operator==(const full_key_t<KeyT::HOBJ>& o) const {
+inline MatchKindCMP key_hobj_t::compare_to(
+    const full_key_t<KeyT::HOBJ>& o) const {
   return compare_full_key<KeyT::HOBJ, KeyT::HOBJ>(*this, o);
 }
-inline bool key_view_t::operator==(const full_key_t<KeyT::VIEW>& o) const {
+inline MatchKindCMP key_view_t::compare_to(
+    const full_key_t<KeyT::VIEW>& o) const {
   return compare_full_key<KeyT::VIEW, KeyT::VIEW>(*this, o);
 }
-inline bool key_view_t::operator==(const full_key_t<KeyT::HOBJ>& o) const {
+inline MatchKindCMP key_view_t::compare_to(
+    const full_key_t<KeyT::HOBJ>& o) const {
   return compare_full_key<KeyT::VIEW, KeyT::HOBJ>(*this, o);
 }