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

crimson/os: cleanups

Reviewed-by: Yingxin Cheng <yingxin.cheng@intel.com>
This commit is contained in:
Kefu Chai 2022-08-22 13:29:19 +08:00 committed by GitHub
commit 5fd0f9cd48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 54 deletions

View File

@ -37,7 +37,7 @@ memory_range_t ITER_T::insert_prefix(
p_insert -= sizeof(node_offset_t);
node_offset_t back_offset = (p_insert - p_insert_front);
mut.copy_in_absolute(p_insert, back_offset);
ns_oid_view_t::append<KT>(mut, key, p_insert);
ns_oid_view_t::append(mut, key, p_insert);
return {p_insert_front, p_insert};
}
@ -179,7 +179,7 @@ APPEND_T::open_nxt(const full_key_t<KT>& key)
{
p_append -= sizeof(node_offset_t);
p_offset_while_open = p_append;
ns_oid_view_t::append<KT>(*p_mut, key, p_append);
ns_oid_view_t::append(*p_mut, key, p_append);
return {p_mut, p_append};
}

View File

@ -126,10 +126,10 @@ class item_iterator_t {
static node_offset_t header_size() { return 0u; }
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t estimate_insert(
const full_key_t<KT>& key, const value_input_t&) {
return ns_oid_view_t::estimate_size<KT>(key) + sizeof(node_offset_t);
const Key& key, const value_input_t&) {
return ns_oid_view_t::estimate_size(key) + sizeof(node_offset_t);
}
template <KeyT KT>

View File

@ -349,12 +349,12 @@ struct ns_oid_view_t {
oid.reset_to(origin_base, new_base, node_size);
}
template <KeyT KT>
static node_offset_t estimate_size(const full_key_t<KT>& key);
template <typename Key>
static node_offset_t estimate_size(const Key& key);
template <KeyT KT>
template <typename Key>
static void append(NodeExtentMutable&,
const full_key_t<KT>& key,
const Key& key,
char*& p_append);
static void append(NodeExtentMutable& mut,
@ -368,8 +368,8 @@ struct ns_oid_view_t {
}
}
template <KeyT KT>
static void test_append(const full_key_t<KT>& key, char*& p_append);
template <typename Key>
static void test_append(const Key& key, char*& p_append);
string_key_view_t nspace;
string_key_view_t oid;
@ -404,8 +404,8 @@ inline const ghobject_t _MAX_OID() {
}
// the valid key stored in tree should be in the range of (_MIN_OID, _MAX_OID)
template <KeyT KT>
bool is_valid_key(const full_key_t<KT>& key);
template <typename Key>
bool is_valid_key(const Key& key);
/**
* key_hobj_t
@ -478,7 +478,7 @@ class key_hobj_t {
}
bool is_valid() const {
return is_valid_key<KeyT::HOBJ>(*this);
return is_valid_key(*this);
}
static key_hobj_t decode(ceph::bufferlist::const_iterator& delta) {
@ -596,7 +596,7 @@ class key_view_t {
}
ghobject_t to_ghobj() const {
assert(is_valid_key<KeyT::VIEW>(*this));
assert(is_valid_key(*this));
return ghobject_t(
shard_id_t(shard()), pool(), crush(),
std::string(nspace()), std::string(oid()), snap(), gen());
@ -811,8 +811,9 @@ std::strong_ordering operator<=>(const LHS& lhs, const RHS& rhs) noexcept {
return lhs.gen() <=> rhs.gen();
}
template <KeyT KT>
bool is_valid_key(const full_key_t<KT>& key) {
template <typename Key>
bool is_valid_key(const Key& key) {
static_assert(IsFullKey<Key>);
return (key > key_hobj_t(ghobject_t()) &&
key < key_hobj_t(ghobject_t::get_max()));
}
@ -863,9 +864,10 @@ bool operator==(LHS lhs, RHS rhs) {
return lhs <=> rhs == 0;
}
template <KeyT KT>
node_offset_t ns_oid_view_t::estimate_size(const full_key_t<KT>& key) {
if constexpr (KT == KeyT::VIEW) {
template <typename Key>
node_offset_t ns_oid_view_t::estimate_size(const Key& key) {
static_assert(IsFullKey<Key>);
if constexpr (std::same_as<Key, key_view_t>) {
return key.ns_oid_view().size();
} else {
if (key.dedup_type() != Type::STR) {
@ -877,9 +879,10 @@ node_offset_t ns_oid_view_t::estimate_size(const full_key_t<KT>& key) {
}
}
template <KeyT KT>
template <typename Key>
void ns_oid_view_t::append(
NodeExtentMutable& mut, const full_key_t<KT>& key, char*& p_append) {
NodeExtentMutable& mut, const Key& key, char*& p_append) {
static_assert(IsFullKey<Key>);
if (key.dedup_type() == Type::STR) {
string_key_view_t::append_str(mut, key.nspace(), p_append);
string_key_view_t::append_str(mut, key.oid(), p_append);
@ -888,8 +891,9 @@ void ns_oid_view_t::append(
}
}
template <KeyT KT>
void ns_oid_view_t::test_append(const full_key_t<KT>& key, char*& p_append) {
template <typename Key>
void ns_oid_view_t::test_append(const Key& key, char*& p_append) {
static_assert(IsFullKey<Key>);
if (key.dedup_type() == Type::STR) {
string_key_view_t::test_append_str(key.nspace(), p_append);
string_key_view_t::test_append_str(key.oid(), p_append);

View File

@ -372,9 +372,9 @@ APPEND_T::open_nxt(const full_key_t<KT>& key)
{
if constexpr (FIELD_TYPE == field_type_t::N0 ||
FIELD_TYPE == field_type_t::N1) {
FieldType::template append_key<KT>(*p_mut, key, p_append_left);
FieldType::append_key(*p_mut, key, p_append_left);
} else if constexpr (FIELD_TYPE == field_type_t::N2) {
FieldType::template append_key<KT>(*p_mut, key, p_append_right);
FieldType::append_key(*p_mut, key, p_append_right);
} else {
ceph_abort("impossible path");
}

View File

@ -133,12 +133,12 @@ class node_extent_t {
static node_offset_t header_size() { return FieldType::HEADER_SIZE; }
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t estimate_insert(
const full_key_t<KT>& key, const value_input_t& value) {
const Key& key, const value_input_t& value) {
auto size = FieldType::estimate_insert_one();
if constexpr (FIELD_TYPE == field_type_t::N2) {
size += ns_oid_view_t::estimate_size<KT>(key);
size += ns_oid_view_t::estimate_size(key);
} else if constexpr (FIELD_TYPE == field_type_t::N3 &&
NODE_TYPE == node_type_t::LEAF) {
size += value.allocation_size();

View File

@ -191,9 +191,9 @@ struct _node_fields_013_t {
NodeExtentMutable&, const me_t& node, index_t index, int change);
static void append_key(
NodeExtentMutable&, const key_t& key, char*& p_append);
template <KeyT KT>
template <IsFullKey Key>
static void append_key(
NodeExtentMutable& mut, const full_key_t<KT>& key, char*& p_append) {
NodeExtentMutable& mut, const Key& key, char*& p_append) {
append_key(mut, key_t::from_key(key), p_append);
}
static void append_offset(
@ -278,9 +278,9 @@ struct node_fields_2_t {
}
static node_offset_t estimate_insert_one() { return sizeof(node_offset_t); }
template <KeyT KT>
template <IsFullKey Key>
static void insert_at(
NodeExtentMutable& mut, const full_key_t<KT>& key,
NodeExtentMutable& mut, const Key& key,
const node_fields_2_t& node, index_t index, node_offset_t size_right) {
ceph_abort("not implemented");
}
@ -292,10 +292,10 @@ struct node_fields_2_t {
NodeExtentMutable& mut, const key_t& key, char*& p_append) {
ns_oid_view_t::append(mut, key, p_append);
}
template <KeyT KT>
template <IsFullKey Key>
static void append_key(
NodeExtentMutable& mut, const full_key_t<KT>& key, char*& p_append) {
ns_oid_view_t::append<KT>(mut, key, p_append);
NodeExtentMutable& mut, const Key& key, char*& p_append) {
ns_oid_view_t::append(mut, key, p_append);
}
static void append_offset(
NodeExtentMutable& mut, node_offset_t offset_to_right, char*& p_append);
@ -374,9 +374,9 @@ struct internal_fields_3_t {
static node_offset_t estimate_insert_one() { return ITEM_SIZE; }
template <KeyT KT>
template <IsFullKey Key>
static void insert_at(
NodeExtentMutable& mut, const full_key_t<KT>& key,
NodeExtentMutable& mut, const Key& key,
const internal_fields_3_t& node,
index_t index, node_offset_t size_right) {
ceph_abort("not implemented");

View File

@ -496,10 +496,10 @@ struct staged {
return container_t::header_size();
}
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t estimate_insert(
const full_key_t<KT>& key, const value_input_t& value) {
return container_t::template estimate_insert<KT>(key, value);
const Key& key, const value_input_t& value) {
return container_t::estimate_insert(key, value);
}
private:
@ -837,10 +837,10 @@ struct staged {
return container_t::header_size();
}
template <KeyT KT>
static node_offset_t estimate_insert(const full_key_t<KT>& key,
template <IsFullKey Key>
static node_offset_t estimate_insert(const Key& key,
const value_input_t& value) {
return container_t::template estimate_insert<KT>(key, value);
return container_t::estimate_insert(key, value);
}
private:
@ -1137,9 +1137,9 @@ struct staged {
static node_offset_t insert_size(const full_key_t<KT>& key,
const value_input_t& value) {
if constexpr (IS_BOTTOM) {
return iterator_t::template estimate_insert<KT>(key, value);
return iterator_t::estimate_insert(key, value);
} else {
return iterator_t::template estimate_insert<KT>(key, value) +
return iterator_t::estimate_insert(key, value) +
NXT_STAGE_T::iterator_t::header_size() +
NXT_STAGE_T::template insert_size<KT>(key, value);
}

View File

@ -14,7 +14,7 @@ const laddr_packed_t* internal_sub_items_t::insert_at(
index_t index, node_offset_t size, const char* p_left_bound)
{
assert(index <= sub_items.keys());
assert(size == estimate_insert<KT>(key, value));
assert(size == estimate_insert(key, value));
const char* p_shift_start = p_left_bound;
const char* p_shift_end = reinterpret_cast<const char*>(
sub_items.p_first_item + 1 - index);
@ -91,7 +91,7 @@ const value_header_t* leaf_sub_items_t::insert_at(
index_t index, node_offset_t size, const char* p_left_bound)
{
assert(index <= sub_items.keys());
assert(size == estimate_insert<KT>(key, value));
assert(size == estimate_insert(key, value));
// a. [... item(index)] << size
const char* p_shift_start = p_left_bound;
const char* p_shift_end = sub_items.get_item_end(index);

View File

@ -103,9 +103,9 @@ class internal_sub_items_t {
static node_offset_t header_size() { return 0u; }
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t estimate_insert(
const full_key_t<KT>&, const laddr_t&) {
const Key&, const laddr_t&) {
return sizeof(internal_sub_item_t);
}
@ -283,9 +283,9 @@ class leaf_sub_items_t {
static node_offset_t header_size() { return sizeof(num_keys_t); }
template <KeyT KT>
template <IsFullKey Key>
static node_offset_t estimate_insert(
const full_key_t<KT>&, const value_config_t& value) {
const Key&, const value_config_t& value) {
return value.allocation_size() + sizeof(snap_gen_t) + sizeof(node_offset_t);
}

View File

@ -67,7 +67,7 @@ namespace {
std::pair<key_view_t, void*> build_key_view(const ghobject_t& hobj) {
key_hobj_t key_hobj(hobj);
size_t key_size = sizeof(shard_pool_crush_t) + sizeof(snap_gen_t) +
ns_oid_view_t::estimate_size<KeyT::HOBJ>(key_hobj);
ns_oid_view_t::estimate_size(key_hobj);
void* p_mem = std::malloc(key_size);
key_view_t key_view;
@ -79,7 +79,7 @@ namespace {
key_view.set(*reinterpret_cast<const shard_pool_crush_t*>(p_fill));
auto p_ns_oid = p_fill;
ns_oid_view_t::test_append<KeyT::HOBJ>(key_hobj, p_fill);
ns_oid_view_t::test_append(key_hobj, p_fill);
ns_oid_view_t ns_oid_view(p_ns_oid);
key_view.set(ns_oid_view);