Merge pull request #47782 from tchaikov/wip-crimson-os-cleanups

crimson/os: use IsFullKey when appropriate 

Reviewed-by: Yingxin Cheng <yingxin.cheng@intel.com>
This commit is contained in:
Yingxin 2022-08-24 16:07:07 +08:00 committed by GitHub
commit 2c916e1923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 65 deletions

View File

@ -310,7 +310,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
eagain_ifuture<NodeExtentMutable>
rebuild_extent(context_t c) override {
assert(!is_keys_empty());
full_key_t<KeyT::VIEW> first_index;
key_view_t first_index;
stage_t::template get_slot<true, false>(
extent.read(), position_t::begin(), &first_index, nullptr);
auto hint = first_index.get_hint();
@ -520,7 +520,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
node_stage, key, history, index_key);
#ifndef NDEBUG
if (!result_raw.is_end()) {
full_key_t<KeyT::VIEW> index;
key_view_t index;
stage_t::template get_slot<true, false>(
node_stage, result_raw.position, &index, nullptr);
assert(index == *index_key);
@ -533,7 +533,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
if (result_raw.is_end()) {
assert(result_raw.mstat == MSTAT_END);
} else {
full_key_t<KeyT::VIEW> index;
key_view_t index;
stage_t::template get_slot<true, false>(
node_stage, result_raw.position, &index, nullptr);
assert_mstat(key, index, result_raw.mstat);
@ -593,7 +593,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
}
validate_layout();
#ifndef NDEBUG
full_key_t<KeyT::VIEW> index;
key_view_t index;
get_slot(insert_pos, &index, nullptr);
assert(index == key);
#endif
@ -773,14 +773,14 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
p_value = extent.template split_insert_replayable<KEY_TYPE>(
split_at, key, value, insert_pos, insert_stage, insert_size);
#ifndef NDEBUG
full_key_t<KeyT::VIEW> index;
key_view_t index;
get_slot(_insert_pos, &index, nullptr);
assert(index == key);
#endif
} else {
SUBDEBUG(seastore_onode, "-- left trim ...");
#ifndef NDEBUG
full_key_t<KeyT::VIEW> index;
key_view_t index;
right_impl.get_slot(_insert_pos, &index, nullptr);
assert(index == key);
#endif
@ -871,7 +871,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
if (unlikely(is_keys_empty())) {
assert(insert_pos.is_end());
insert_stage = STAGE;
insert_size = stage_t::template insert_size<KeyT::VIEW>(key, value);
insert_size = stage_t::insert_size(key, value);
} else {
std::tie(insert_stage, insert_size) = stage_t::evaluate_insert(
node_stage, key, value, cast_down<STAGE>(insert_pos), false);
@ -893,7 +893,7 @@ class NodeLayoutT final : public InternalNodeImpl, public LeafNodeImpl {
if (unlikely(is_keys_empty())) {
assert(insert_pos.is_end());
assert(is_level_tail());
return {STAGE, stage_t::template insert_size<KeyT::HOBJ>(key, value)};
return {STAGE, stage_t::insert_size(key, value)};
} else {
return stage_t::evaluate_insert(
key, value, history, mstat, cast_down<STAGE>(insert_pos));

View File

@ -23,7 +23,7 @@ struct search_result_bs_t {
};
template <typename FGetKey>
search_result_bs_t binary_search(
const full_key_t<KeyT::HOBJ>& key,
const key_hobj_t& key,
index_t begin, index_t end, FGetKey&& f_get_key) {
assert(begin <= end);
while (begin < end) {
@ -85,8 +85,8 @@ inline bool matchable(field_type_t type, match_stat_t mstat) {
}
inline void assert_mstat(
const full_key_t<KeyT::HOBJ>& key,
const full_key_t<KeyT::VIEW>& index,
const key_hobj_t& key,
const key_view_t& index,
match_stat_t mstat) {
assert(mstat >= MSTAT_MIN && mstat <= MSTAT_LT2);
// key < index ...
@ -301,7 +301,7 @@ struct staged {
++_index;
}
// Note: possible to return an end iterator
MatchKindBS seek(const full_key_t<KeyT::HOBJ>& key, bool exclude_last) {
MatchKindBS seek(const key_hobj_t& key, bool exclude_last) {
assert(!is_end());
assert(index() == 0);
index_t end_index = container.keys();
@ -316,10 +316,10 @@ struct staged {
return ret.match;
}
template <KeyT KT, typename T = value_t>
template <IsFullKey Key, typename T = value_t>
std::enable_if_t<IS_BOTTOM, const T*> insert(
NodeExtentMutable& mut,
const full_key_t<KT>& key,
const Key& key,
const value_input_t& value,
node_offset_t insert_size,
const char* p_left_bound) {
@ -620,7 +620,7 @@ struct staged {
_is_end = true;
}
// Note: possible to return an end iterator
MatchKindBS seek(const full_key_t<KeyT::HOBJ>& key, bool exclude_last) {
MatchKindBS seek(const key_hobj_t& key, bool exclude_last) {
assert(!is_end());
assert(index() == 0);
do {
@ -932,7 +932,7 @@ struct staged {
template <bool GET_KEY>
static result_t smallest_result(
const iterator_t& iter, full_key_t<KeyT::VIEW>* p_index_key) {
const iterator_t& iter, key_view_t* p_index_key) {
static_assert(!IS_BOTTOM);
assert(!iter.is_end());
auto nxt_container = iter.get_nxt_container();
@ -951,8 +951,8 @@ struct staged {
template <bool GET_KEY>
static result_t nxt_lower_bound(
const full_key_t<KeyT::HOBJ>& key, iterator_t& iter,
MatchHistory& history, full_key_t<KeyT::VIEW>* index_key) {
const key_hobj_t& key, iterator_t& iter,
MatchHistory& history, key_view_t* index_key) {
static_assert(!IS_BOTTOM);
assert(!iter.is_end());
auto nxt_container = iter.get_nxt_container();
@ -976,7 +976,7 @@ struct staged {
static void get_largest_slot(
const container_t& container, // IN
position_t* p_position, // OUT
full_key_t<KeyT::VIEW>* p_index_key, // OUT
key_view_t* p_index_key, // OUT
const value_t** pp_value) { // OUT
auto iter = iterator_t(container);
iter.seek_last();
@ -1015,7 +1015,7 @@ struct staged {
static void get_slot(
const container_t& container, // IN
const position_t& pos, // IN
full_key_t<KeyT::VIEW>* p_index_key, // OUT
key_view_t* p_index_key, // OUT
const value_t** pp_value) { // OUT
auto iter = iterator_t(container);
iter.seek_at(pos.index);
@ -1044,9 +1044,9 @@ struct staged {
template <bool GET_KEY = false>
static result_t lower_bound(
const container_t& container,
const full_key_t<KeyT::HOBJ>& key,
const key_hobj_t& key,
MatchHistory& history,
full_key_t<KeyT::VIEW>* index_key = nullptr) {
key_view_t* index_key = nullptr) {
bool exclude_last = false;
if (history.get<STAGE>().has_value()) {
if (*history.get<STAGE>() == MatchKindCMP::EQ) {
@ -1133,33 +1133,33 @@ struct staged {
}
}
template <KeyT KT>
static node_offset_t insert_size(const full_key_t<KT>& key,
template <IsFullKey Key>
static node_offset_t insert_size(const Key& key,
const value_input_t& value) {
if constexpr (IS_BOTTOM) {
return iterator_t::estimate_insert(key, value);
} else {
return iterator_t::estimate_insert(key, value) +
NXT_STAGE_T::iterator_t::header_size() +
NXT_STAGE_T::template insert_size<KT>(key, value);
NXT_STAGE_T::insert_size(key, value);
}
}
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t insert_size_at(match_stage_t stage,
const full_key_t<KeyT::HOBJ>& key,
const Key& key,
const value_input_t& value) {
if (stage == STAGE) {
return insert_size<KT>(key, value);
return insert_size(key, value);
} else {
assert(stage < STAGE);
return NXT_STAGE_T::template insert_size_at<KT>(stage, key, value);
return NXT_STAGE_T::template insert_size_at(stage, key, value);
}
}
template <typename T = std::tuple<match_stage_t, node_offset_t>>
static std::enable_if_t<NODE_TYPE == node_type_t::INTERNAL, T> evaluate_insert(
const container_t& container, const full_key_t<KeyT::VIEW>& key,
const container_t& container, const key_view_t& key,
const value_input_t& value, position_t& position, bool evaluate_last) {
auto iter = iterator_t(container);
auto& index = position.index;
@ -1185,7 +1185,7 @@ struct staged {
assert(match == std::strong_ordering::less);
if (index == 0) {
// already the first index, so insert at the current index
return {STAGE, insert_size<KeyT::VIEW>(key, value)};
return {STAGE, insert_size(key, value)};
}
--index;
iter = iterator_t(container);
@ -1199,7 +1199,7 @@ struct staged {
if (match == std::strong_ordering::greater) {
// key doesn't match both indexes, so insert at the current index
++index;
return {STAGE, insert_size<KeyT::VIEW>(key, value)};
return {STAGE, insert_size(key, value)};
} else {
assert(match == std::strong_ordering::equal);
if constexpr (IS_BOTTOM) {
@ -1259,7 +1259,7 @@ struct staged {
template <typename T = std::tuple<match_stage_t, node_offset_t>>
static std::enable_if_t<NODE_TYPE == node_type_t::LEAF, T> evaluate_insert(
const full_key_t<KeyT::HOBJ>& key, const value_config_t& value,
const key_hobj_t& key, const value_config_t& value,
const MatchHistory& history, match_stat_t mstat, position_t& position) {
match_stage_t insert_stage = STAGE_TOP;
while (*history.get_by_stage(insert_stage) == MatchKindCMP::EQ) {
@ -1296,7 +1296,7 @@ struct staged {
patch_insert_end(position, insert_stage);
}
node_offset_t insert_size = insert_size_at<KeyT::HOBJ>(insert_stage, key, value);
node_offset_t insert_size = insert_size_at(insert_stage, key, value);
return {insert_stage, insert_size};
}
@ -1349,7 +1349,7 @@ struct staged {
if (iter.is_end()) {
// insert at the higher stage due to split
do_insert = true;
_insert_size = insert_size<KT>(key, value);
_insert_size = insert_size(key, value);
stage = STAGE;
}
} else {
@ -1361,9 +1361,9 @@ struct staged {
if constexpr (!IS_BOTTOM) {
position.nxt = position_t::nxt_t::begin();
}
assert(_insert_size == insert_size<KT>(key, value));
assert(_insert_size == insert_size(key, value));
if constexpr (IS_BOTTOM) {
return iter.template insert<KT>(
return iter.insert(
mut, key, value, _insert_size, p_left_bound);
} else {
auto range = iter.insert_prefix(
@ -1394,11 +1394,11 @@ struct staged {
if (position.is_end()) {
position = position_t::begin();
assert(stage == STAGE);
assert(_insert_size == insert_size<KT>(key, value));
assert(_insert_size == insert_size(key, value));
} else if (position == position_t::begin()) {
// when insert into a trimmed and empty left node
stage = STAGE;
_insert_size = insert_size<KT>(key, value);
_insert_size = insert_size(key, value);
} else {
ceph_abort("impossible path");
}
@ -1478,7 +1478,7 @@ struct staged {
}
static void get_stats(const container_t& container, node_stats_t& stats,
full_key_t<KeyT::VIEW>& index_key) {
key_view_t& index_key) {
auto iter = iterator_t(container);
assert(!iter.is_end());
stats.size_overhead += iterator_t::header_size();
@ -1513,7 +1513,7 @@ struct staged {
static bool get_next_slot(
const container_t& container, // IN
position_t& pos, // IN&OUT
full_key_t<KeyT::VIEW>* p_index_key, // OUT
key_view_t* p_index_key, // OUT
const value_t** pp_value) { // OUT
auto iter = iterator_t(container);
assert(!iter.is_end());
@ -1554,7 +1554,7 @@ struct staged {
static void get_prev_slot(
const container_t& container, // IN
position_t& pos, // IN&OUT
full_key_t<KeyT::VIEW>* p_index_key, // OUT
key_view_t* p_index_key, // OUT
const value_t** pp_value) { // OUT
assert(pos != position_t::begin());
assert(!pos.is_end());
@ -2344,7 +2344,7 @@ struct staged {
}
static std::tuple<match_stage_t, node_offset_t> evaluate_merge(
const full_key_t<KeyT::VIEW>& left_pivot_index,
const key_view_t& left_pivot_index,
const container_t& right_container) {
auto r_iter = iterator_t(right_container);
r_iter.seek_at(0);

View File

@ -140,9 +140,9 @@ void validate_tree_config(const tree_conf_t& conf)
laddr_t i_value{0};
auto insert_size_2 =
_STAGE_T(InternalNode0)::template insert_size<KeyT::HOBJ>(key, i_value);
_STAGE_T(InternalNode0)::insert_size(key, i_value);
auto insert_size_0 =
NXT_T(NXT_T(_STAGE_T(InternalNode0)))::template insert_size<KeyT::HOBJ>(key, i_value);
NXT_T(NXT_T(_STAGE_T(InternalNode0)))::insert_size(key, i_value);
unsigned internal_size_bound = sizeof(node_header_t) +
(insert_size_2 + max_str_size) * 2 +
(insert_size_2 - insert_size_0 + max_str_size);
@ -151,9 +151,9 @@ void validate_tree_config(const tree_conf_t& conf)
value_config_t l_value;
l_value.payload_size = conf.max_value_payload_size;
insert_size_2 =
_STAGE_T(LeafNode0)::template insert_size<KeyT::HOBJ>(key, l_value);
_STAGE_T(LeafNode0)::insert_size(key, l_value);
insert_size_0 =
NXT_T(NXT_T(_STAGE_T(LeafNode0)))::template insert_size<KeyT::HOBJ>(key, l_value);
NXT_T(NXT_T(_STAGE_T(LeafNode0)))::insert_size(key, l_value);
unsigned leaf_size_bound = sizeof(node_header_t) +
(insert_size_2 + max_str_size) * 2 +
(insert_size_2 - insert_size_0 + max_str_size);

View File

@ -139,24 +139,24 @@ TEST_F(a_basic_test_t, 1_basic_sizes)
" LeafNode1: {} {} {}\n"
" LeafNode2: {} {}\n"
" LeafNode3: {}",
_STAGE_T(InternalNode0)::template insert_size<KeyT::VIEW>(key_view, i_value),
NXT_T(_STAGE_T(InternalNode0))::template insert_size<KeyT::VIEW>(key_view, i_value),
NXT_T(NXT_T(_STAGE_T(InternalNode0)))::template insert_size<KeyT::VIEW>(key_view, i_value),
_STAGE_T(InternalNode1)::template insert_size<KeyT::VIEW>(key_view, i_value),
NXT_T(_STAGE_T(InternalNode1))::template insert_size<KeyT::VIEW>(key_view, i_value),
NXT_T(NXT_T(_STAGE_T(InternalNode1)))::template insert_size<KeyT::VIEW>(key_view, i_value),
_STAGE_T(InternalNode2)::template insert_size<KeyT::VIEW>(key_view, i_value),
NXT_T(_STAGE_T(InternalNode2))::template insert_size<KeyT::VIEW>(key_view, i_value),
_STAGE_T(InternalNode3)::template insert_size<KeyT::VIEW>(key_view, i_value),
_STAGE_T(LeafNode0)::template insert_size<KeyT::HOBJ>(key, value),
NXT_T(_STAGE_T(LeafNode0))::template insert_size<KeyT::HOBJ>(key, value),
NXT_T(NXT_T(_STAGE_T(LeafNode0)))::template insert_size<KeyT::HOBJ>(key, value),
_STAGE_T(LeafNode1)::template insert_size<KeyT::HOBJ>(key, value),
NXT_T(_STAGE_T(LeafNode1))::template insert_size<KeyT::HOBJ>(key, value),
NXT_T(NXT_T(_STAGE_T(LeafNode1)))::template insert_size<KeyT::HOBJ>(key, value),
_STAGE_T(LeafNode2)::template insert_size<KeyT::HOBJ>(key, value),
NXT_T(_STAGE_T(LeafNode2))::template insert_size<KeyT::HOBJ>(key, value),
_STAGE_T(LeafNode3)::template insert_size<KeyT::HOBJ>(key, value)
_STAGE_T(InternalNode0)::insert_size(key_view, i_value),
NXT_T(_STAGE_T(InternalNode0))::insert_size(key_view, i_value),
NXT_T(NXT_T(_STAGE_T(InternalNode0)))::insert_size(key_view, i_value),
_STAGE_T(InternalNode1)::insert_size(key_view, i_value),
NXT_T(_STAGE_T(InternalNode1))::insert_size(key_view, i_value),
NXT_T(NXT_T(_STAGE_T(InternalNode1)))::insert_size(key_view, i_value),
_STAGE_T(InternalNode2)::insert_size(key_view, i_value),
NXT_T(_STAGE_T(InternalNode2))::insert_size(key_view, i_value),
_STAGE_T(InternalNode3)::insert_size(key_view, i_value),
_STAGE_T(LeafNode0)::insert_size(key, value),
NXT_T(_STAGE_T(LeafNode0))::insert_size(key, value),
NXT_T(NXT_T(_STAGE_T(LeafNode0)))::insert_size(key, value),
_STAGE_T(LeafNode1)::insert_size(key, value),
NXT_T(_STAGE_T(LeafNode1))::insert_size(key, value),
NXT_T(NXT_T(_STAGE_T(LeafNode1)))::insert_size(key, value),
_STAGE_T(LeafNode2)::insert_size(key, value),
NXT_T(_STAGE_T(LeafNode2))::insert_size(key, value),
_STAGE_T(LeafNode3)::insert_size(key, value)
);
std::free(p_mem);
}