From: Yingxin Cheng Date: Wed, 16 Dec 2020 05:51:41 +0000 (+0800) Subject: crimson/onode-staged-tree: use index_t for node internal indexes X-Git-Tag: v16.1.0~63^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=84ee63e2ad31db94a928bc3f708f79a0d8bbb329;p=ceph.git crimson/onode-staged-tree: use index_t for node internal indexes Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/fwd.h b/src/crimson/os/seastore/onode_manager/staged-fltree/fwd.h index c45d60505dbe..212d5cec9f88 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/fwd.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/fwd.h @@ -45,10 +45,12 @@ using InternalNodeImplURef = std::unique_ptr; using NodeImplURef = std::unique_ptr; using level_t = uint8_t; -constexpr auto INDEX_END = std::numeric_limits::max(); -constexpr auto INDEX_LAST = INDEX_END - 0xf; -constexpr auto INDEX_UPPER_BOUND = INDEX_END - 0xff; -inline bool is_valid_index(size_t index) { return index < INDEX_UPPER_BOUND; } +// a type only to index within a node, 32 bits should be enough +using index_t = uint32_t; +constexpr auto INDEX_END = std::numeric_limits::max(); +constexpr auto INDEX_LAST = INDEX_END - 0x4; +constexpr auto INDEX_UPPER_BOUND = INDEX_END - 0x8; +inline bool is_valid_index(index_t index) { return index < INDEX_UPPER_BOUND; } // TODO: decide by NODE_BLOCK_SIZE using node_offset_t = uint16_t; diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.cc index 5a2b45577541..7532c4521632 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.cc @@ -86,7 +86,7 @@ ITER_TEMPLATE(node_type_t::INTERNAL); template template -bool APPEND_T::append(const ITER_T& src, size_t& items) { +bool APPEND_T::append(const ITER_T& src, index_t& items) { auto p_end = src.p_end(); bool append_till_end = false; if (is_valid_index(items)) { diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.h index bdf6bb95614c..b0ff95c57fe8 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/item_iterator_stage.h @@ -48,7 +48,7 @@ class item_iterator_t { // container type system using key_get_type = const ns_oid_view_t&; static constexpr auto CONTAINER_TYPE = ContainerType::ITERATIVE; - size_t index() const { return _index; } + index_t index() const { return _index; } key_get_type get_key() const { if (!key.has_value()) { key = ns_oid_view_t(item_range.p_end); @@ -123,7 +123,7 @@ class item_iterator_t { mutable memory_range_t item_range; mutable node_offset_t back_offset; mutable std::optional key; - mutable size_t _index = 0u; + mutable index_t _index = 0u; }; template @@ -132,7 +132,7 @@ class item_iterator_t::Appender { public: Appender(NodeExtentMutable* p_mut, char* p_append) : p_mut{p_mut}, p_append{p_append} {} - bool append(const item_iterator_t& src, size_t& items); + bool append(const item_iterator_t& src, index_t& items); char* wrap() { return p_append; } std::tuple open_nxt(const key_get_type&); std::tuple open_nxt(const full_key_t&); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.cc index d3b96048025c..92280135dcf8 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.cc @@ -28,7 +28,7 @@ const char* NODE_T::p_left_bound() const { } template -node_offset_t NODE_T::size_to_nxt_at(size_t index) const { +node_offset_t NODE_T::size_to_nxt_at(index_t index) const { assert(index < keys()); if constexpr (FIELD_TYPE == field_type_t::N0 || FIELD_TYPE == field_type_t::N1) { @@ -42,7 +42,7 @@ node_offset_t NODE_T::size_to_nxt_at(size_t index) const { } template -memory_range_t NODE_T::get_nxt_container(size_t index) const { +memory_range_t NODE_T::get_nxt_container(index_t index) const { if constexpr (std::is_same_v) { ceph_abort("N3 internal node doesn't have the right part"); } else { @@ -83,7 +83,7 @@ template template memory_range_t NODE_T::insert_prefix_at( NodeExtentMutable& mut, const node_extent_t& node, const full_key_t& key, - size_t index, node_offset_t size, const char* p_left_bound) { + index_t index, node_offset_t size, const char* p_left_bound) { if constexpr (FIELD_TYPE == field_type_t::N0 || FIELD_TYPE == field_type_t::N1) { assert(index <= node.keys()); @@ -106,7 +106,7 @@ memory_range_t NODE_T::insert_prefix_at( #define IPA_TEMPLATE(FT, NT, KT) \ template memory_range_t NODE_INST(FT, NT)::insert_prefix_at( \ NodeExtentMutable&, const node_extent_t&, const full_key_t&, \ - size_t, node_offset_t, const char*) + index_t, node_offset_t, const char*) IPA_TEMPLATE(node_fields_0_t, node_type_t::INTERNAL, KeyT::VIEW); IPA_TEMPLATE(node_fields_1_t, node_type_t::INTERNAL, KeyT::VIEW); IPA_TEMPLATE(node_fields_2_t, node_type_t::INTERNAL, KeyT::VIEW); @@ -122,14 +122,14 @@ IPA_TEMPLATE(node_fields_2_t, node_type_t::LEAF, KeyT::HOBJ); template void NODE_T::update_size_at( - NodeExtentMutable& mut, const node_extent_t& node, size_t index, int change) { + NodeExtentMutable& mut, const node_extent_t& node, index_t index, int change) { assert(index < node.keys()); FieldType::update_size_at(mut, node.fields(), index, change); } template node_offset_t NODE_T::trim_until( - NodeExtentMutable& mut, const node_extent_t& node, size_t index) { + NodeExtentMutable& mut, const node_extent_t& node, index_t index) { assert(!node.is_level_tail()); auto keys = node.keys(); assert(index <= keys); @@ -149,7 +149,7 @@ node_offset_t NODE_T::trim_until( template node_offset_t NODE_T::trim_at( NodeExtentMutable& mut, const node_extent_t& node, - size_t index, node_offset_t trimmed) { + index_t index, node_offset_t trimmed) { assert(!node.is_level_tail()); assert(index < node.keys()); if constexpr (std::is_same_v) { @@ -181,7 +181,7 @@ NODE_TEMPLATE(leaf_fields_3_t, node_type_t::LEAF); template template -void APPEND_T::append(const node_extent_t& src, size_t from, size_t items) { +void APPEND_T::append(const node_extent_t& src, index_t from, index_t items) { assert(from <= src.keys()); if (p_src == nullptr) { p_src = &src; diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.h index d1a704d4a0a3..1aabea15efca 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage.h @@ -79,21 +79,21 @@ class node_extent_t { // container type system using key_get_type = typename FieldType::key_get_type; static constexpr auto CONTAINER_TYPE = ContainerType::INDEXABLE; - size_t keys() const { return p_fields->num_keys; } - key_get_type operator[] (size_t index) const { return p_fields->get_key(index); } - node_offset_t size_before(size_t index) const { + index_t keys() const { return p_fields->num_keys; } + key_get_type operator[] (index_t index) const { return p_fields->get_key(index); } + node_offset_t size_before(index_t index) const { auto free_size = p_fields->template free_size_before(index); assert(total_size() >= free_size); return total_size() - free_size; } - node_offset_t size_to_nxt_at(size_t index) const; - node_offset_t size_overhead_at(size_t index) const { + node_offset_t size_to_nxt_at(index_t index) const; + node_offset_t size_overhead_at(index_t index) const { return FieldType::ITEM_OVERHEAD; } - memory_range_t get_nxt_container(size_t index) const; + memory_range_t get_nxt_container(index_t index) const; template std::enable_if_t - get_p_value(size_t index) const { + get_p_value(index_t index) const { assert(index < keys()); if constexpr (NODE_TYPE == node_type_t::INTERNAL) { return &p_fields->child_addrs[index]; @@ -141,7 +141,7 @@ class node_extent_t { static const value_t* insert_at( NodeExtentMutable& mut, const node_extent_t&, const full_key_t& key, const value_t& value, - size_t index, node_offset_t size, const char* p_left_bound) { + index_t index, node_offset_t size, const char* p_left_bound) { if constexpr (FIELD_TYPE == field_type_t::N3) { ceph_abort("not implemented"); } else { @@ -153,15 +153,15 @@ class node_extent_t { static memory_range_t insert_prefix_at( NodeExtentMutable&, const node_extent_t&, const full_key_t& key, - size_t index, node_offset_t size, const char* p_left_bound); + index_t index, node_offset_t size, const char* p_left_bound); static void update_size_at( - NodeExtentMutable&, const node_extent_t&, size_t index, int change); + NodeExtentMutable&, const node_extent_t&, index_t index, int change); static node_offset_t trim_until( - NodeExtentMutable&, const node_extent_t&, size_t index); + NodeExtentMutable&, const node_extent_t&, index_t index); static node_offset_t trim_at(NodeExtentMutable&, const node_extent_t&, - size_t index, node_offset_t trimmed); + index_t index, node_offset_t trimmed); template class Appender; @@ -186,7 +186,7 @@ class node_extent_t::Appender { p_append_left = p_start + FieldType::HEADER_SIZE; p_append_right = p_start + FieldType::SIZE; } - void append(const node_extent_t& src, size_t from, size_t items); + void append(const node_extent_t& src, index_t from, index_t items); void append(const full_key_t&, const value_t&, const value_t*&); char* wrap(); std::tuple open_nxt(const key_get_type&); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.cc index 8f6b73a6a9c8..c3f27567e98c 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.cc @@ -31,7 +31,7 @@ void node_header_t::update_is_level_tail( template void F013_T::update_size_at( - NodeExtentMutable& mut, const me_t& node, size_t index, int change) { + NodeExtentMutable& mut, const me_t& node, index_t index, int change) { assert(index <= node.num_keys); for (const auto* p_slot = &node.slots[index]; p_slot < &node.slots[node.num_keys]; @@ -61,7 +61,7 @@ template template void F013_T::insert_at( NodeExtentMutable& mut, const full_key_t& key, - const me_t& node, size_t index, node_offset_t size_right) { + const me_t& node, index_t index, node_offset_t size_right) { assert(index <= node.num_keys); update_size_at(mut, node, index, size_right); auto p_insert = const_cast(fields_start(node)) + @@ -74,7 +74,7 @@ void F013_T::insert_at( } #define IA_TEMPLATE(ST, KT) template void F013_INST(ST):: \ insert_at(NodeExtentMutable&, const full_key_t&, \ - const F013_INST(ST)&, size_t, node_offset_t) + const F013_INST(ST)&, index_t, node_offset_t) IA_TEMPLATE(slot_0_t, KeyT::VIEW); IA_TEMPLATE(slot_1_t, KeyT::VIEW); IA_TEMPLATE(slot_3_t, KeyT::VIEW); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.h index 6305f1904da5..26ba537d2ce5 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.h @@ -82,7 +82,7 @@ const char* fields_start(const FieldType& node) { template node_range_t fields_free_range_before( - const FieldType& node, size_t index) { + const FieldType& node, index_t index) { assert(index <= node.num_keys); node_offset_t offset_start = node.get_key_start_offset(index); node_offset_t offset_end = @@ -137,31 +137,31 @@ struct _node_fields_013_t { bool is_level_tail() const { return header.get_is_level_tail(); } node_offset_t total_size() const { return SIZE; } - key_get_type get_key(size_t index) const { + key_get_type get_key(index_t index) const { assert(index < num_keys); return slots[index].key; } - node_offset_t get_key_start_offset(size_t index) const { + node_offset_t get_key_start_offset(index_t index) const { assert(index <= num_keys); auto offset = HEADER_SIZE + sizeof(SlotType) * index; assert(offset < SIZE); return offset; } - node_offset_t get_item_start_offset(size_t index) const { + node_offset_t get_item_start_offset(index_t index) const { assert(index < num_keys); auto offset = slots[index].right_offset; assert(offset <= SIZE); return offset; } - const void* p_offset(size_t index) const { + const void* p_offset(index_t index) const { assert(index < num_keys); return &slots[index].right_offset; } - node_offset_t get_item_end_offset(size_t index) const { + node_offset_t get_item_end_offset(index_t index) const { return index == 0 ? SIZE : get_item_start_offset(index - 1); } template - node_offset_t free_size_before(size_t index) const { + node_offset_t free_size_before(index_t index) const { auto range = fields_free_range_before(*this, index); return range.end - range.start; } @@ -170,9 +170,9 @@ struct _node_fields_013_t { template static void insert_at( NodeExtentMutable&, const full_key_t& key, - const me_t& node, size_t index, node_offset_t size_right); + const me_t& node, index_t index, node_offset_t size_right); static void update_size_at( - NodeExtentMutable&, const me_t& node, size_t index, int change); + NodeExtentMutable&, const me_t& node, index_t index, int change); static void append_key( NodeExtentMutable&, const key_t& key, char*& p_append); template @@ -224,7 +224,7 @@ struct node_fields_2_t { bool is_level_tail() const { return header.get_is_level_tail(); } node_offset_t total_size() const { return SIZE; } - key_get_type get_key(size_t index) const { + key_get_type get_key(index_t index) const { assert(index < num_keys); node_offset_t item_end_offset = (index == 0 ? SIZE : offsets[index - 1]); @@ -232,27 +232,27 @@ struct node_fields_2_t { const char* p_start = fields_start(*this); return key_t(p_start + item_end_offset); } - node_offset_t get_key_start_offset(size_t index) const { + node_offset_t get_key_start_offset(index_t index) const { assert(index <= num_keys); auto offset = HEADER_SIZE + sizeof(node_offset_t) * num_keys; assert(offset <= SIZE); return offset; } - node_offset_t get_item_start_offset(size_t index) const { + node_offset_t get_item_start_offset(index_t index) const { assert(index < num_keys); auto offset = offsets[index]; assert(offset <= SIZE); return offset; } - const void* p_offset(size_t index) const { + const void* p_offset(index_t index) const { assert(index < num_keys); return &offsets[index]; } - node_offset_t get_item_end_offset(size_t index) const { + node_offset_t get_item_end_offset(index_t index) const { return index == 0 ? SIZE : get_item_start_offset(index - 1); } template - node_offset_t free_size_before(size_t index) const { + node_offset_t free_size_before(index_t index) const { auto range = fields_free_range_before(*this, index); return range.end - range.start; } @@ -261,11 +261,11 @@ struct node_fields_2_t { template static void insert_at( NodeExtentMutable& mut, const full_key_t& key, - const node_fields_2_t& node, size_t index, node_offset_t size_right) { + const node_fields_2_t& node, index_t index, node_offset_t size_right) { ceph_abort("not implemented"); } static void update_size_at( - NodeExtentMutable& mut, const node_fields_2_t& node, size_t index, int change) { + NodeExtentMutable& mut, const node_fields_2_t& node, index_t index, int change) { ceph_abort("not implemented"); } static void append_key( @@ -321,13 +321,13 @@ struct _internal_fields_3_t { return SIZE; } } - key_get_type get_key(size_t index) const { + key_get_type get_key(index_t index) const { assert(index < num_keys); return keys[index]; } template std::enable_if_t - free_size_before(size_t index) const { + free_size_before(index_t index) const { assert(index <= num_keys); assert(num_keys <= (is_level_tail() ? MAX_NUM_KEYS - 1 : MAX_NUM_KEYS)); auto free = (MAX_NUM_KEYS - index) * (sizeof(snap_gen_t) + sizeof(laddr_t)); @@ -344,11 +344,11 @@ struct _internal_fields_3_t { template static void insert_at( NodeExtentMutable& mut, const full_key_t& key, - const me_t& node, size_t index, node_offset_t size_right) { + const me_t& node, index_t index, node_offset_t size_right) { ceph_abort("not implemented"); } static void update_size_at( - NodeExtentMutable& mut, const me_t& node, size_t index, int change) { + NodeExtentMutable& mut, const me_t& node, index_t index, int change) { ceph_abort("not implemented"); } 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 9d8a5e1abd4f..8dec00c8addd 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 @@ -17,13 +17,13 @@ namespace crimson::os::seastore::onode { struct search_result_bs_t { - size_t index; + index_t index; MatchKindBS match; }; template search_result_bs_t binary_search( const full_key_t& key, - size_t begin, size_t end, FGetKey&& f_get_key) { + index_t begin, index_t end, FGetKey&& f_get_key) { assert(begin <= end); while (begin < end) { auto total = begin + end; @@ -44,7 +44,7 @@ search_result_bs_t binary_search( template search_result_bs_t binary_search_r( - size_t rend, size_t rbegin, FGet&& f_get, const PivotType& key) { + index_t rend, index_t rbegin, FGet&& f_get, const PivotType& key) { assert(rend <= rbegin); while (rend < rbegin) { auto total = rend + rbegin + 1; @@ -169,7 +169,7 @@ struct staged { static constexpr auto STAGE = Params::STAGE; template - static void _left_or_right(size_t& split_index, size_t insert_index, + static void _left_or_right(index_t& split_index, index_t insert_index, std::optional& is_insert_left) { assert(!is_insert_left.has_value()); assert(is_valid_index(split_index)); @@ -205,13 +205,13 @@ struct staged { /* * indexable container type system: * CONTAINER_TYPE = ContainerType::INDEXABLE - * keys() const -> size_t - * operator[](size_t) const -> key_get_type - * size_before(size_t) const -> node_offset_t - * size_overhead_at(size_t) const -> node_offset_t - * (IS_BOTTOM) get_p_value(size_t) const -> const value_t* - * (!IS_BOTTOM) size_to_nxt_at(size_t) const -> node_offset_t - * (!IS_BOTTOM) get_nxt_container(size_t) const + * keys() const -> index_t + * operator[](index_t) const -> key_get_type + * size_before(index_t) const -> node_offset_t + * size_overhead_at(index_t) const -> node_offset_t + * (IS_BOTTOM) get_p_value(index_t) const -> const value_t* + * (!IS_BOTTOM) size_to_nxt_at(index_t) const -> node_offset_t + * (!IS_BOTTOM) get_nxt_container(index_t) const * static: * header_size() -> node_offset_t * estimate_insert(key, value) -> node_offset_t @@ -232,7 +232,7 @@ struct staged { assert(container.keys()); } - size_t index() const { + index_t index() const { return _index; } key_get_type get_key() const { @@ -275,11 +275,11 @@ struct staged { ++_index; return *this; } - void seek_at(size_t index) { + void seek_at(index_t index) { assert(index < container.keys()); seek_till_end(index); } - void seek_till_end(size_t index) { + void seek_till_end(index_t index) { assert(!is_end()); assert(this->index() == 0); assert(index <= container.keys()); @@ -299,14 +299,14 @@ struct staged { MatchKindBS seek(const full_key_t& key, bool exclude_last) { assert(!is_end()); assert(index() == 0); - size_t end_index = container.keys(); + index_t end_index = container.keys(); if (exclude_last) { assert(end_index); --end_index; assert(compare_to(key, container[end_index]) == MatchKindCMP::LT); } auto ret = binary_search(key, _index, end_index, - [this] (size_t index) { return container[index]; }); + [this] (index_t index) { return container[index]; }); _index = ret.index; return ret.match; } @@ -338,7 +338,7 @@ struct staged { template size_t seek_split_inserted( size_t start_size, size_t extra_size, size_t target_size, - size_t& insert_index, size_t insert_size, + index_t& insert_index, size_t insert_size, std::optional& is_insert_left) { assert(!is_end()); assert(index() == 0); @@ -356,7 +356,7 @@ struct staged { auto start_size_1 = start_size + extra_size; auto f_get_used_size = [this, start_size, start_size_1, - insert_index, insert_size] (size_t index) { + insert_index, insert_size] (index_t index) { size_t current_size; if (unlikely(index == 0)) { current_size = start_size; @@ -373,7 +373,7 @@ struct staged { } return current_size; }; - size_t s_end; + index_t s_end; if constexpr (is_exclusive) { s_end = container.keys(); } else { @@ -391,7 +391,7 @@ struct staged { assert(!is_end()); assert(index() == 0); auto start_size_1 = start_size + extra_size; - auto f_get_used_size = [this, start_size, start_size_1] (size_t index) { + auto f_get_used_size = [this, start_size, start_size_1] (index_t index) { size_t current_size; if (unlikely(index == 0)) { current_size = start_size; @@ -411,9 +411,9 @@ struct staged { // Note: possible to return an end iterater if to_index == INDEX_END template void copy_out_until( - typename container_t::template Appender& appender, size_t& to_index) { + typename container_t::template Appender& appender, index_t& to_index) { auto num_keys = container.keys(); - size_t items; + index_t items; if (to_index == INDEX_END) { items = num_keys - _index; appender.append(container, _index, items); @@ -456,7 +456,7 @@ struct staged { private: container_t container; - size_t _index = 0; + index_t _index = 0; }; template @@ -464,7 +464,7 @@ struct staged { /* * iterative container type system (!IS_BOTTOM): * CONTAINER_TYPE = ContainerType::ITERATIVE - * index() const -> size_t + * index() const -> index_t * get_key() const -> key_get_type * size() const -> node_offset_t * size_to_nxt() const -> node_offset_t @@ -490,7 +490,7 @@ struct staged { assert(index() == 0); } - size_t index() const { + index_t index() const { if (is_end()) { return end_index; } else { @@ -529,7 +529,7 @@ struct staged { ++container; return *this; } - void seek_at(size_t index) { + void seek_at(index_t index) { assert(!is_end()); assert(this->index() == 0); while (index > 0) { @@ -538,7 +538,7 @@ struct staged { --index; } } - void seek_till_end(size_t index) { + void seek_till_end(index_t index) { assert(!is_end()); assert(this->index() == 0); while (index > 0) { @@ -610,12 +610,12 @@ struct staged { template size_t seek_split_inserted( size_t start_size, size_t extra_size, size_t target_size, - size_t& insert_index, size_t insert_size, + index_t& insert_index, size_t insert_size, std::optional& is_insert_left) { assert(!is_end()); assert(index() == 0); size_t current_size = start_size; - size_t split_index = 0; + index_t split_index = 0; extra_size += header_size(); do { if constexpr (!is_exclusive) { @@ -702,7 +702,7 @@ struct staged { // Note: possible to return an end iterater if to_index == INDEX_END template void copy_out_until( - typename container_t::template Appender& appender, size_t& to_index) { + typename container_t::template Appender& appender, index_t& to_index) { if (is_end()) { assert(!container.has_next()); if (to_index == INDEX_END) { @@ -711,7 +711,7 @@ struct staged { assert(to_index == index()); return; } - size_t items; + index_t items; if (to_index == INDEX_END || to_index == INDEX_LAST) { items = to_index; } else { @@ -749,7 +749,7 @@ struct staged { private: container_t container; bool _is_end = false; - size_t end_index; + index_t end_index; }; /* @@ -757,7 +757,7 @@ struct staged { * from a *non-empty* container. * cstr(const container_t&) * access: - * index() -> size_t + * index() -> index_t * get_key() -> key_get_type (const reference or value type) * is_last() -> bool * is_end() -> bool @@ -1410,7 +1410,7 @@ struct staged { public: StagedIterator() = default; bool valid() const { return iter.has_value(); } - size_t index() const { + index_t index() const { return iter->index(); } bool is_end() const { return iter->is_end(); } @@ -1722,7 +1722,7 @@ struct staged { /* * container appender type system * container_t::Appender(NodeExtentMutable& mut, char* p_append) - * append(const container_t& src, size_t from, size_t items) + * append(const container_t& src, index_t from, index_t items) * wrap() -> char* * IF !IS_BOTTOM: * open_nxt(const key_get_type&) @@ -1746,7 +1746,7 @@ struct staged { assert(!valid()); } bool valid() const { return appender.has_value(); } - size_t index() const { + index_t index() const { assert(valid()); return _index; } @@ -1758,7 +1758,7 @@ struct staged { _index = 0; } // possible to make src_iter end if to_index == INDEX_END - void append_until(StagedIterator& src_iter, size_t& to_index) { + void append_until(StagedIterator& src_iter, index_t& to_index) { assert(!require_wrap_nxt); auto s_index = src_iter.index(); src_iter.get().template copy_out_until(*appender, to_index); @@ -1841,13 +1841,13 @@ struct staged { } private: std::optional> appender; - size_t _index; + index_t _index; bool require_wrap_nxt = false; }; template static void _append_range( - StagedIterator& src_iter, StagedAppender& appender, size_t& to_index) { + StagedIterator& src_iter, StagedAppender& appender, index_t& to_index) { if (src_iter.is_end()) { // append done assert(to_index == INDEX_END); @@ -1856,7 +1856,7 @@ struct staged { if (appender.in_progress()) { // appender has appended something at the current item, // cannot append the current item as-a-whole - size_t to_index_nxt = INDEX_END; + index_t to_index_nxt = INDEX_END; NXT_STAGE_T::template _append_range( src_iter.nxt(), appender.get_nxt(), to_index_nxt); ++src_iter; @@ -1864,7 +1864,7 @@ struct staged { } else if (src_iter.in_progress()) { // src_iter is not at the beginning of the current item, // cannot append the current item as-a-whole - size_t to_index_nxt = INDEX_END; + index_t to_index_nxt = INDEX_END; NXT_STAGE_T::template _append_range( src_iter.nxt(), appender.open_nxt(src_iter.get_key()), to_index_nxt); ++src_iter; @@ -1898,8 +1898,8 @@ struct staged { template static void append_until(StagedIterator& src_iter, StagedAppender& appender, position_t& position, match_stage_t stage) { - size_t from_index = src_iter.index(); - size_t& to_index = position.index; + index_t from_index = src_iter.index(); + index_t& to_index = position.index; assert(from_index <= to_index); if constexpr (IS_BOTTOM) { assert(stage == STAGE); 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 715b59de9eed..eec2788abc95 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 @@ -140,7 +140,7 @@ struct staged_position_t { return false; } } - size_t& index_by_stage(match_stage_t stage) { + index_t& index_by_stage(match_stage_t stage) { assert(stage <= STAGE); if (STAGE == stage) { return index; @@ -183,7 +183,7 @@ struct staged_position_t { return {INDEX_END, nxt_t::end()}; } - size_t index; + index_t index; nxt_t nxt; }; template @@ -210,7 +210,7 @@ struct staged_position_t { return false; } } - size_t& index_by_stage(match_stage_t stage) { + index_t& index_by_stage(match_stage_t stage) { assert(stage == STAGE_BOTTOM); return index; } @@ -244,7 +244,7 @@ struct staged_position_t { static me_t begin() { return {0u}; } static me_t end() { return {INDEX_END}; } - size_t index; + index_t index; }; template <> inline std::ostream& operator<<(std::ostream& os, const staged_position_t& pos) { @@ -350,7 +350,7 @@ struct staged_result_t { } template static std::enable_if_t from_nxt( - size_t index, const staged_result_t& nxt_stage_result) { + index_t index, const staged_result_t& nxt_stage_result) { return {{index, nxt_stage_result.position}, nxt_stage_result.p_value, nxt_stage_result.mstat}; diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.cc index 577b8b7bfc99..447a35c97d27 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.cc @@ -11,7 +11,7 @@ template const laddr_packed_t* internal_sub_items_t::insert_at( NodeExtentMutable& mut, const internal_sub_items_t& sub_items, const full_key_t& key, const laddr_packed_t& value, - size_t index, node_offset_t size, const char* p_left_bound) { + index_t index, node_offset_t size, const char* p_left_bound) { assert(index <= sub_items.keys()); assert(size == estimate_insert(key, value)); const char* p_shift_start = p_left_bound; @@ -26,10 +26,10 @@ const laddr_packed_t* internal_sub_items_t::insert_at( } template const laddr_packed_t* internal_sub_items_t::insert_at( NodeExtentMutable&, const internal_sub_items_t&, const full_key_t&, - const laddr_packed_t&, size_t, node_offset_t, const char*); + const laddr_packed_t&, index_t, node_offset_t, const char*); node_offset_t internal_sub_items_t::trim_until( - NodeExtentMutable&, internal_sub_items_t& items, size_t index) { + NodeExtentMutable&, internal_sub_items_t& items, index_t index) { assert(index != 0); auto keys = items.keys(); assert(index <= keys); @@ -40,7 +40,7 @@ node_offset_t internal_sub_items_t::trim_until( template void internal_sub_items_t::Appender::append( - const internal_sub_items_t& src, size_t from, size_t items) { + const internal_sub_items_t& src, index_t from, index_t items) { assert(from <= src.keys()); if (items == 0) { return; @@ -66,7 +66,7 @@ template const onode_t* leaf_sub_items_t::insert_at( NodeExtentMutable& mut, const leaf_sub_items_t& sub_items, const full_key_t& key, const onode_t& value, - size_t index, node_offset_t size, const char* p_left_bound) { + index_t index, node_offset_t size, const char* p_left_bound) { assert(index <= sub_items.keys()); assert(size == estimate_insert(key, value)); // a. [... item(index)] << size @@ -109,17 +109,17 @@ const onode_t* leaf_sub_items_t::insert_at( } template const onode_t* leaf_sub_items_t::insert_at( NodeExtentMutable&, const leaf_sub_items_t&, const full_key_t&, - const onode_t&, size_t, node_offset_t, const char*); + const onode_t&, index_t, node_offset_t, const char*); node_offset_t leaf_sub_items_t::trim_until( - NodeExtentMutable& mut, leaf_sub_items_t& items, size_t index) { + NodeExtentMutable& mut, leaf_sub_items_t& items, index_t index) { assert(index != 0); auto keys = items.keys(); assert(index <= keys); if (index == keys) { return 0; } - size_t trim_items = keys - index; + index_t trim_items = keys - index; const char* p_items_start = items.p_start(); const char* p_shift_start = items.get_item_end(index); const char* p_shift_end = items.get_item_end(0); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.h index 37262afacea0..d9c1eceaa5a8 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.h @@ -40,7 +40,7 @@ struct internal_sub_item_t { */ class internal_sub_items_t { public: - using num_keys_t = size_t; + using num_keys_t = index_t; internal_sub_items_t(const memory_range_t& range) { assert(range.p_start < range.p_end); @@ -55,20 +55,20 @@ class internal_sub_items_t { using key_get_type = const snap_gen_t&; static constexpr auto CONTAINER_TYPE = ContainerType::INDEXABLE; num_keys_t keys() const { return num_items; } - key_get_type operator[](size_t index) const { + key_get_type operator[](index_t index) const { assert(index < num_items); return (p_first_item - index)->get_key(); } - node_offset_t size_before(size_t index) const { + node_offset_t size_before(index_t index) const { size_t ret = index * sizeof(internal_sub_item_t); assert(ret < NODE_BLOCK_SIZE); return ret; } - const laddr_packed_t* get_p_value(size_t index) const { + const laddr_packed_t* get_p_value(index_t index) const { assert(index < num_items); return (p_first_item - index)->get_p_value(); } - node_offset_t size_overhead_at(size_t index) const { return 0u; } + node_offset_t size_overhead_at(index_t index) const { return 0u; } static node_offset_t header_size() { return 0u; } @@ -82,15 +82,15 @@ class internal_sub_items_t { static const laddr_packed_t* insert_at( NodeExtentMutable&, const internal_sub_items_t&, const full_key_t&, const laddr_packed_t&, - size_t index, node_offset_t size, const char* p_left_bound); + index_t index, node_offset_t size, const char* p_left_bound); - static node_offset_t trim_until(NodeExtentMutable&, internal_sub_items_t&, size_t); + static node_offset_t trim_until(NodeExtentMutable&, internal_sub_items_t&, index_t); template class Appender; private: - size_t num_items; + index_t num_items; const internal_sub_item_t* p_first_item; }; @@ -99,7 +99,7 @@ class internal_sub_items_t::Appender { public: Appender(NodeExtentMutable* p_mut, char* p_append) : p_mut{p_mut}, p_append{p_append} {} - void append(const internal_sub_items_t& src, size_t from, size_t items); + void append(const internal_sub_items_t& src, index_t from, index_t items); void append(const full_key_t&, const laddr_packed_t&, const laddr_packed_t*&); char* wrap() { return p_append; } private: @@ -153,21 +153,21 @@ class leaf_sub_items_t { const char* p_start() const { return get_item_end(keys()); } - const node_offset_packed_t& get_offset(size_t index) const { + const node_offset_packed_t& get_offset(index_t index) const { assert(index < keys()); return *(p_offsets - index); } - const node_offset_t get_offset_to_end(size_t index) const { + const node_offset_t get_offset_to_end(index_t index) const { assert(index <= keys()); return index == 0 ? 0 : get_offset(index - 1).value; } - const char* get_item_start(size_t index) const { + const char* get_item_start(index_t index) const { return p_items_end - get_offset(index).value; } - const char* get_item_end(size_t index) const { + const char* get_item_end(index_t index) const { return p_items_end - get_offset_to_end(index); } @@ -175,7 +175,7 @@ class leaf_sub_items_t { using key_get_type = const snap_gen_t&; static constexpr auto CONTAINER_TYPE = ContainerType::INDEXABLE; num_keys_t keys() const { return *p_num_keys; } - key_get_type operator[](size_t index) const { + key_get_type operator[](index_t index) const { assert(index < keys()); auto pointer = get_item_end(index); assert(get_item_start(index) < pointer); @@ -183,7 +183,7 @@ class leaf_sub_items_t { assert(get_item_start(index) < pointer); return *reinterpret_cast(pointer); } - node_offset_t size_before(size_t index) const { + node_offset_t size_before(index_t index) const { assert(index <= keys()); size_t ret; if (index == 0) { @@ -197,8 +197,8 @@ class leaf_sub_items_t { assert(ret < NODE_BLOCK_SIZE); return ret; } - node_offset_t size_overhead_at(size_t index) const { return sizeof(node_offset_t); } - const onode_t* get_p_value(size_t index) const { + node_offset_t size_overhead_at(index_t index) const { return sizeof(node_offset_t); } + const onode_t* get_p_value(index_t index) const { assert(index < keys()); auto pointer = get_item_start(index); auto value = reinterpret_cast(pointer); @@ -217,9 +217,9 @@ class leaf_sub_items_t { static const onode_t* insert_at( NodeExtentMutable&, const leaf_sub_items_t&, const full_key_t&, const onode_t&, - size_t index, node_offset_t size, const char* p_left_bound); + index_t index, node_offset_t size, const char* p_left_bound); - static node_offset_t trim_until(NodeExtentMutable&, leaf_sub_items_t&, size_t index); + static node_offset_t trim_until(NodeExtentMutable&, leaf_sub_items_t&, index_t index); template class Appender; @@ -231,13 +231,13 @@ class leaf_sub_items_t { const char* p_items_end; }; -auto constexpr APPENDER_LIMIT = 3u; +constexpr index_t APPENDER_LIMIT = 3u; template class leaf_sub_items_t::Appender { struct range_items_t { - size_t from; - size_t items; + index_t from; + index_t items; }; struct kv_item_t { const full_key_t* p_key; @@ -250,7 +250,7 @@ class leaf_sub_items_t::Appender { : p_mut{p_mut}, p_append{p_append} { } - void append(const leaf_sub_items_t& src, size_t from, size_t items) { + void append(const leaf_sub_items_t& src, index_t from, index_t items) { assert(cnt <= APPENDER_LIMIT); assert(from <= src.keys()); if (items == 0) { @@ -282,7 +282,7 @@ class leaf_sub_items_t::Appender { NodeExtentMutable* p_mut; char* p_append; var_t appends[APPENDER_LIMIT]; - size_t cnt = 0; + index_t cnt = 0; }; template struct _sub_items_t;