]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/onode-staged-tree: cleanup stage.h
authorYingxin Cheng <yingxin.cheng@intel.com>
Thu, 17 Sep 2020 02:15:12 +0000 (10:15 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Tue, 1 Dec 2020 04:50:53 +0000 (12:50 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h

index 35e0c32c320ab88ca75747bc101b52cd06c27b5e..7ad1366bac03d9307e8df154d93c624aed775eca 100644 (file)
@@ -178,7 +178,34 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
         return lookup_result_t<NODE_TYPE>::end();
       }
     }
-    auto result = STAGE_T::lower_bound_normalized(node_stage, key, history);
+
+    auto result_raw = STAGE_T::lower_bound(node_stage, key, history);
+#ifndef NDEBUG
+    if (result_raw.is_end()) {
+      assert(result_raw.mstat == MSTAT_END);
+    } else {
+      full_key_t<KeyT::VIEW> index;
+      STAGE_T::get_key_view(node_stage, result_raw.position, index);
+      assert_mstat(key, index, result_raw.mstat);
+    }
+#endif
+
+    // calculate MSTAT_NE3
+    if constexpr (FIELD_TYPE == field_type_t::N0) {
+      // currently only internal node checks mstat
+      if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
+        if (result_raw.mstat == MSTAT_NE2) {
+          auto cmp = compare_to<KeyT::HOBJ>(
+              key, node_stage[result_raw.position.index].shard_pool);
+          assert(cmp != MatchKindCMP::PO);
+          if (cmp != MatchKindCMP::EQ) {
+            result_raw.mstat = MSTAT_NE3;
+          }
+        }
+      }
+    }
+
+    auto result = normalize(std::move(result_raw));
     if (result.is_end()) {
       assert(node_stage.is_level_tail());
       assert(result.p_value == nullptr);
@@ -308,7 +335,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
    */
   void get_largest_value(search_position_t& pos, const onode_t*& p_value) const override {
     if constexpr (NODE_TYPE == node_type_t::LEAF) {
-      STAGE_T::lookup_largest_normalized(extent.read(), pos, p_value);
+      STAGE_T::lookup_largest(extent.read(), cast_down_fill_0<STAGE>(pos), p_value);
     } else {
       assert(false && "impossible path");
     }
index 7d5b51978133f1ed213e8a3274caf65d1fba9791..c3378c1c655967e5f5ef19317622d8414168927e 100644 (file)
@@ -1186,63 +1186,6 @@ struct staged {
     }
   }
 
-  /*
-   * Lookup interfaces
-   */
-
-  static void lookup_largest_normalized(
-      const container_t& container,
-      search_position_t& position,
-      const value_t*& p_value) {
-    if constexpr (STAGE == STAGE_LEFT) {
-      lookup_largest(container, position, p_value);
-      return;
-    }
-    position.index = 0;
-    auto& pos_nxt = position.nxt;
-    if constexpr (STAGE == STAGE_STRING) {
-      lookup_largest(container, pos_nxt, p_value);
-      return;
-    }
-    pos_nxt.index = 0;
-    auto& pos_nxt_nxt = pos_nxt.nxt;
-    if constexpr (STAGE == STAGE_RIGHT) {
-      lookup_largest(container, pos_nxt_nxt, p_value);
-      return;
-    }
-    assert(false);
-  }
-
-  static lookup_result_t<NODE_TYPE> lower_bound_normalized(
-      const container_t& container,
-      const full_key_t<KeyT::HOBJ>& key,
-      MatchHistory& history) {
-    auto&& result = lower_bound(container, key, history);
-#ifndef NDEBUG
-    if (result.is_end()) {
-      assert(result.mstat == MSTAT_END);
-    } else {
-      full_key_t<KeyT::VIEW> index;
-      get_key_view(container, result.position, index);
-      assert_mstat(key, index, result.mstat);
-    }
-#endif
-    if constexpr (container_t::FIELD_TYPE == field_type_t::N0) {
-      // currently only internal node checks mstat
-      if constexpr (NODE_TYPE == node_type_t::INTERNAL) {
-        if (result.mstat == MSTAT_NE2) {
-          auto cmp = compare_to<KeyT::HOBJ>(
-              key, container[result.position.index].shard_pool);
-          assert(cmp != MatchKindCMP::PO);
-          if (cmp != MatchKindCMP::EQ) {
-            result.mstat = MSTAT_NE3;
-          }
-        }
-      }
-    }
-    return normalize(std::move(result));
-  }
-
   static std::ostream& dump(const container_t& container,
                             std::ostream& os,
                             const std::string& prefix,
index aad4aa643ead59cf711ffecfd3c5aa644d6b2ad5..6f30a15485730ec395d59e70366bc68316ffe9c6 100644 (file)
@@ -210,12 +210,11 @@ inline std::ostream& operator<<(std::ostream& os, const staged_position_t<STAGE_
 
 using search_position_t = staged_position_t<STAGE_TOP>;
 
-template <match_stage_t STAGE, typename = std::enable_if_t<STAGE == STAGE_TOP>>
-const search_position_t& cast_down(const search_position_t& pos) { return pos; }
-
-template <match_stage_t STAGE, typename = std::enable_if_t<STAGE != STAGE_TOP>>
+template <match_stage_t STAGE>
 const staged_position_t<STAGE>& cast_down(const search_position_t& pos) {
-  if constexpr (STAGE == STAGE_STRING) {
+  if constexpr (STAGE == STAGE_LEFT) {
+    return pos;
+  } else if constexpr (STAGE == STAGE_STRING) {
 #ifndef NDEBUG
     if (pos.is_end()) {
       assert(pos.nxt.is_end());
@@ -224,7 +223,7 @@ const staged_position_t<STAGE>& cast_down(const search_position_t& pos) {
     }
 #endif
     return pos.nxt;
-  } else if (STAGE == STAGE_RIGHT) {
+  } else if constexpr (STAGE == STAGE_RIGHT) {
 #ifndef NDEBUG
     if (pos.is_end()) {
       assert(pos.nxt.nxt.is_end());
@@ -235,7 +234,7 @@ const staged_position_t<STAGE>& cast_down(const search_position_t& pos) {
 #endif
     return pos.nxt.nxt;
   } else {
-    assert(false);
+    assert(false && "impossible path");
   }
 }
 
@@ -245,6 +244,22 @@ staged_position_t<STAGE>& cast_down(search_position_t& pos) {
   return const_cast<staged_position_t<STAGE>&>(cast_down<STAGE>(_pos));
 }
 
+template <match_stage_t STAGE>
+staged_position_t<STAGE>& cast_down_fill_0(search_position_t& pos) {
+  if constexpr (STAGE == STAGE_LEFT) {
+    return pos;
+  } if constexpr (STAGE == STAGE_STRING) {
+    pos.index = 0;
+    return pos.nxt;
+  } else if constexpr (STAGE == STAGE_RIGHT) {
+    pos.index = 0;
+    pos.nxt.index = 0;
+    return pos.nxt.nxt;
+  } else {
+    assert(false && "impossible path");
+  }
+}
+
 inline search_position_t&& normalize(search_position_t&& pos) { return std::move(pos); }
 
 template <match_stage_t STAGE, typename = std::enable_if_t<STAGE != STAGE_TOP>>