]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os: define *::from_key() with IsFullKey
authorKefu Chai <tchaikov@gmail.com>
Thu, 18 Aug 2022 16:07:16 +0000 (00:07 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 18 Aug 2022 16:28:45 +0000 (00:28 +0800)
more compact this way.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.cc
src/crimson/os/seastore/onode_manager/staged-fltree/stages/node_stage_layout.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/sub_items_stage.cc

index 13c52c9c1ab19f77bf97158644e43bc2078adc92..45b46905a178d908c4fadd80d83a97f5a896d2f2 100644 (file)
@@ -678,8 +678,14 @@ struct shard_pool_t {
 
   pool_t pool() const { return _pool; }
 
-  template <KeyT KT>
-  static shard_pool_t from_key(const full_key_t<KT>& key);
+  template <IsFullKey Key>
+  static shard_pool_t from_key(const Key& key) {
+    if constexpr (std::same_as<Key, key_view_t>) {
+      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 <KeyT KT>
-  static crush_t from_key(const full_key_t<KT>& key);
+  template <IsFullKey Key>
+  static crush_t from_key(const Key& key) {
+    if constexpr (std::same_as<Key, key_view_t>) {
+      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 <KeyT KT>
-  static shard_pool_crush_t from_key(const full_key_t<KT>& key);
+  template <IsFullKey Key>
+  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 <KeyT KT>
-  static snap_gen_t from_key(const full_key_t<KT>& key);
+  template <IsFullKey Key>
+  static snap_gen_t from_key(const Key& key) {
+    if constexpr (std::same_as<Key, key_view_t>) {
+      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 <KeyT KT>
-shard_pool_t shard_pool_t::from_key(const full_key_t<KT>& key) {
-  if constexpr (KT == KeyT::VIEW) {
-    return key.shard_pool_packed();
-  } else {
-    return {key.shard(), key.pool()};
-  }
-}
-
-template <KeyT KT>
-crush_t crush_t::from_key(const full_key_t<KT>& key) {
-  if constexpr (KT == KeyT::VIEW) {
-    return key.crush_packed();
-  } else {
-    return {key.crush()};
-  }
-}
-
-template <KeyT KT>
-shard_pool_crush_t shard_pool_crush_t::from_key(const full_key_t<KT>& key) {
-  return {shard_pool_t::from_key<KT>(key), crush_t::from_key<KT>(key)};
-}
-
-template <KeyT KT>
-snap_gen_t snap_gen_t::from_key(const full_key_t<KT>& key) {
-  if constexpr (KT == KeyT::VIEW) {
-    return key.snap_gen_packed();
-  } else {
-    return {key.snap(), key.gen()};
-  }
-}
-
 template <KeyT KT>
 node_offset_t ns_oid_view_t::estimate_size(const full_key_t<KT>& key) {
   if constexpr (KT == KeyT::VIEW) {
index 373f5d4fb6ceb2ae2dee9653205a74cd93f6bee6..561da24a33b60acc676a8eb284c56fc12f76b701 100644 (file)
@@ -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<KT>(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);
index 611b7dc1828ba9ddce9a934ac3e0b0157bf45cb6..2ea7f215c98fe969c119f115fc98e0590348cbda 100644 (file)
@@ -194,7 +194,7 @@ struct _node_fields_013_t {
   template <KeyT KT>
   static void append_key(
       NodeExtentMutable& mut, const full_key_t<KT>& key, char*& p_append) {
-    append_key(mut, key_t::template from_key<KT>(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);
index ac3045e6feef54bf2a5c53bd7d1ee76a66afe527..a9c50f8b2878834a31e28d2e37b207efabebe02f 100644 (file)
@@ -22,7 +22,7 @@ const laddr_packed_t* internal_sub_items_t::insert_at(
 
   auto p_insert = const_cast<char*>(p_shift_end) - size;
   auto item = internal_sub_item_t{
-    snap_gen_t::from_key<KT>(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<internal_sub_item_t*>(p_insert)->value;
 }
@@ -79,7 +79,7 @@ void internal_sub_items_t::Appender<KT>::append(
 {
   p_append -= sizeof(internal_sub_item_t);
   auto item = internal_sub_item_t{
-    snap_gen_t::from_key<KT>(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<internal_sub_item_t*>(p_append)->value;
 }
@@ -102,7 +102,7 @@ const value_header_t* leaf_sub_items_t::insert_at(
   auto p_value = reinterpret_cast<value_header_t*>(p_insert);
   p_value->initiate(mut, value);
   p_insert += value.allocation_size();
-  mut.copy_in_absolute(p_insert, snap_gen_t::template from_key<KT>(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<KT>::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<KT>(*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<value_header_t*>(p_cur);
         p_value->initiate(*p_mut, arg.value_config);