]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/onode-staged-tree: make sure oids in tree are always valid
authorYingxin Cheng <yingxin.cheng@intel.com>
Thu, 29 Apr 2021 02:17:53 +0000 (10:17 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Sat, 8 May 2021 02:04:46 +0000 (10:04 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h
src/crimson/os/seastore/onode_manager/staged-fltree/tree.h
src/crimson/os/seastore/onode_manager/staged-fltree/tree_utils.h
src/test/crimson/seastore/test_seastore.cc

index 83afad7e6177100a033736d1134ab4a4c768a5ad..f8a9cc6b8eff706000cd22b9c013e40a245d97df 100644 (file)
@@ -480,6 +480,10 @@ inline const ghobject_t _MAX_OID() {
                     "MAX", "MAX", MAX_SNAP, MAX_GEN);
 }
 
+// the valid key stored in tree should be in the range of (_MIN_OID, _MAX_OID)
+template <KeyT KT>
+bool is_valid_key(const full_key_t<KT>& key);
+
 /**
  * key_hobj_t
  *
@@ -549,6 +553,10 @@ class key_hobj_t {
     return os;
   }
 
+  bool is_valid() const {
+    return is_valid_key<KeyT::HOBJ>(*this);
+  }
+
   static key_hobj_t decode(ceph::bufferlist::const_iterator& delta) {
     shard_t shard;
     ceph::decode(shard, delta);
@@ -675,6 +683,7 @@ class key_view_t {
   }
 
   ghobject_t to_ghobj() const {
+    assert(is_valid_key<KeyT::VIEW>(*this));
     return ghobject_t(
         shard_id_t(shard()), pool(), crush(),
         std::string(nspace()), std::string(oid()), snap(), gen());
@@ -801,6 +810,12 @@ inline MatchKindCMP key_view_t::compare_to(
   return compare_full_key<KeyT::VIEW, KeyT::HOBJ>(*this, o);
 }
 
+template <KeyT KT>
+bool is_valid_key(const full_key_t<KT>& key) {
+  return key.compare_to(key_hobj_t(ghobject_t())) == MatchKindCMP::GT &&
+         key.compare_to(key_hobj_t(ghobject_t::get_max())) == MatchKindCMP::LT;
+}
+
 inline std::ostream& operator<<(std::ostream& os, const key_view_t& key) {
   return key.dump(os);
 }
index 62db82fc7fed1dbe755827d7644ea8bd9b8eef37..567df2d5ba6eecdc708c29774a7cdb3920e67dcf 100644 (file)
@@ -243,6 +243,7 @@ class Btree {
     return seastar::do_with(
       full_key_t<KeyT::HOBJ>(obj),
       [this, &t, vconf](auto& key) -> btree_future<std::pair<Cursor, bool>> {
+        ceph_assert(key.is_valid());
         return get_root(t).safe_then([this, &t, &key, vconf](auto root) {
           return root->insert(get_context(t), key, vconf);
         }).safe_then([this](auto ret) {
index 016244ac383577dc744b7f5755cd4e390123f9be..83445f55be265da6e5624935c9929a90612cf4ec 100644 (file)
@@ -246,6 +246,7 @@ class KVPool {
     auto ret = ghobject_t(
       hobject_t(
         sobject_t(ss.str(), CEPH_NOSNAP)));
+    ret.set_shard(shard_id_t(0));
     ret.hobj.nspace = "asdf";
     return ret;
   }
index 1100306209e0d822b07158204b1dc1ffa21d7081..efc4d81561f7d79afa4d2d1b76d0dca324df5545 100644 (file)
@@ -275,6 +275,7 @@ ghobject_t make_oid(int i) {
   auto ret = ghobject_t(
     hobject_t(
       sobject_t(ss.str(), CEPH_NOSNAP)));
+  ret.set_shard(shard_id_t(0));
   ret.hobj.nspace = "asdf";
   return ret;
 }