From: Kefu Chai Date: Thu, 18 Aug 2022 16:07:16 +0000 (+0800) Subject: crimson/os: define *::from_key() with IsFullKey X-Git-Tag: v18.0.0~233^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=72f91fad9e2d9871e88a7c0a433a23fe2c41ed78;p=ceph-ci.git crimson/os: define *::from_key() with IsFullKey more compact this way. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h index 13c52c9c1ab..45b46905a17 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h @@ -678,8 +678,14 @@ struct shard_pool_t { pool_t pool() const { return _pool; } - template - static shard_pool_t from_key(const full_key_t& key); + template + static shard_pool_t from_key(const Key& key) { + if constexpr (std::same_as) { + return key.shard_pool_packed(); + } else { + return {key.shard(), key.pool()}; + } + } shard_t shard; pool_t _pool; @@ -692,8 +698,14 @@ inline std::ostream& operator<<(std::ostream& os, const shard_pool_t& sp) { struct crush_t { auto operator<=>(const crush_t&) const = default; - template - static crush_t from_key(const full_key_t& key); + template + static crush_t from_key(const Key& key) { + if constexpr (std::same_as) { + return key.crush_packed(); + } else { + return {key.crush()}; + } + } crush_hash_t crush; } __attribute__((packed)); @@ -704,8 +716,10 @@ inline std::ostream& operator<<(std::ostream& os, const crush_t& c) { struct shard_pool_crush_t { auto operator<=>(const shard_pool_crush_t&) const = default; - template - static shard_pool_crush_t from_key(const full_key_t& key); + template + static shard_pool_crush_t from_key(const Key& key) { + return {shard_pool_t::from_key(key), crush_t::from_key(key)}; + } shard_pool_t shard_pool; crush_t crush; @@ -717,8 +731,14 @@ inline std::ostream& operator<<(std::ostream& os, const shard_pool_crush_t& spc) struct snap_gen_t { auto operator<=>(const snap_gen_t&) const = default; - template - static snap_gen_t from_key(const full_key_t& key); + template + static snap_gen_t from_key(const Key& key) { + if constexpr (std::same_as) { + return key.snap_gen_packed(); + } else { + return {key.snap(), key.gen()}; + } + } snap_t snap; gen_t gen; @@ -843,38 +863,6 @@ bool operator==(LHS lhs, RHS rhs) { return lhs <=> rhs == 0; } -template -shard_pool_t shard_pool_t::from_key(const full_key_t& key) { - if constexpr (KT == KeyT::VIEW) { - return key.shard_pool_packed(); - } else { - return {key.shard(), key.pool()}; - } -} - -template -crush_t crush_t::from_key(const full_key_t& key) { - if constexpr (KT == KeyT::VIEW) { - return key.crush_packed(); - } else { - return {key.crush()}; - } -} - -template -shard_pool_crush_t shard_pool_crush_t::from_key(const full_key_t& key) { - return {shard_pool_t::from_key(key), crush_t::from_key(key)}; -} - -template -snap_gen_t snap_gen_t::from_key(const full_key_t& key) { - if constexpr (KT == KeyT::VIEW) { - return key.snap_gen_packed(); - } else { - return {key.snap(), key.gen()}; - } -} - template node_offset_t ns_oid_view_t::estimate_size(const full_key_t& key) { if constexpr (KT == KeyT::VIEW) { 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 373f5d4fb6c..561da24a33b 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 @@ -96,7 +96,7 @@ void F013_T::insert_at( node.get_key_start_offset(node.num_keys, node_size); mut.shift_absolute(p_insert, p_shift_end - p_insert, estimate_insert_one()); mut.copy_in_absolute((void*)&node.num_keys, num_keys_t(node.num_keys + 1)); - append_key(mut, key_t::template from_key(key), p_insert); + append_key(mut, key_t::from_key(key), p_insert); int new_offset = node.get_item_end_offset(index, node_size) - size_right; assert(new_offset > 0); assert(new_offset < (int)node_size); 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 611b7dc1828..2ea7f215c98 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 @@ -194,7 +194,7 @@ struct _node_fields_013_t { template static void append_key( NodeExtentMutable& mut, const full_key_t& key, char*& p_append) { - append_key(mut, key_t::template from_key(key), p_append); + append_key(mut, key_t::from_key(key), p_append); } static void append_offset( NodeExtentMutable& mut, node_offset_t offset_to_right, char*& p_append); 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 ac3045e6fee..a9c50f8b287 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 @@ -22,7 +22,7 @@ const laddr_packed_t* internal_sub_items_t::insert_at( auto p_insert = const_cast(p_shift_end) - size; auto item = internal_sub_item_t{ - snap_gen_t::from_key(key), laddr_packed_t{value}}; + snap_gen_t::from_key(key), laddr_packed_t{value}}; mut.copy_in_absolute(p_insert, item); return &reinterpret_cast(p_insert)->value; } @@ -79,7 +79,7 @@ void internal_sub_items_t::Appender::append( { p_append -= sizeof(internal_sub_item_t); auto item = internal_sub_item_t{ - snap_gen_t::from_key(key), laddr_packed_t{value}}; + snap_gen_t::from_key(key), laddr_packed_t{value}}; p_mut->copy_in_absolute(p_append, item); p_value = &reinterpret_cast(p_append)->value; } @@ -102,7 +102,7 @@ const value_header_t* leaf_sub_items_t::insert_at( auto p_value = reinterpret_cast(p_insert); p_value->initiate(mut, value); p_insert += value.allocation_size(); - mut.copy_in_absolute(p_insert, snap_gen_t::template from_key(key)); + mut.copy_in_absolute(p_insert, snap_gen_t::from_key(key)); assert(p_insert + sizeof(snap_gen_t) + sizeof(node_offset_t) == p_shift_end); // c. compensate affected offsets @@ -312,7 +312,7 @@ char* leaf_sub_items_t::Appender::wrap() [&] (const kv_item_t& arg) { assert(pp_value); p_cur -= sizeof(snap_gen_t); - p_mut->copy_in_absolute(p_cur, snap_gen_t::template from_key(*arg.p_key)); + p_mut->copy_in_absolute(p_cur, snap_gen_t::from_key(*arg.p_key)); p_cur -= arg.value_config.allocation_size(); auto p_value = reinterpret_cast(p_cur); p_value->initiate(*p_mut, arg.value_config);