From: Yingxin Cheng Date: Thu, 17 Sep 2020 02:15:12 +0000 (+0800) Subject: crimson/onode-staged-tree: cleanup stage.h X-Git-Tag: v16.1.0~359^2~41 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9deef491df04c0b2c846f4bfb630d2d12f0b33c4;p=ceph.git crimson/onode-staged-tree: cleanup stage.h Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h b/src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h index 35e0c32c320a..7ad1366bac03 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node_layout.h @@ -178,7 +178,34 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl { return lookup_result_t::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 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( + 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(pos), p_value); } else { assert(false && "impossible path"); } diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h index 7d5b51978133..c3378c1c6559 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h @@ -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 lower_bound_normalized( - const container_t& container, - const full_key_t& 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 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( - 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, diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h index aad4aa643ead..6f30a1548573 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h @@ -210,12 +210,11 @@ inline std::ostream& operator<<(std::ostream& os, const staged_position_t; -template > -const search_position_t& cast_down(const search_position_t& pos) { return pos; } - -template > +template const staged_position_t& 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& 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& 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& cast_down(search_position_t& pos) { return const_cast&>(cast_down(_pos)); } +template +staged_position_t& 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 >