From: Yingxin Cheng Date: Tue, 9 Feb 2021 04:48:59 +0000 (+0800) Subject: crimson/onode-staged-tree: be explicit about string_key markers X-Git-Tag: v17.1.0~3016^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=54f87106649aafa1c6a0cf77e72eb04df3a5a41c;p=ceph.git crimson/onode-staged-tree: be explicit about string_key markers To be explicit that string_kew_view_t::MIN and MAX are not valid string lengths. They are reserved as markers. Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.cc index dab2c0d1b8f7..4bf717dc224e 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/key_layout.cc @@ -23,9 +23,9 @@ void string_key_view_t::append_dedup( { p_append -= sizeof(string_size_t); if (dedup_type == Type::MIN) { - mut.copy_in_absolute(p_append, MIN); + mut.copy_in_absolute(p_append, MARKER_MIN); } else if (dedup_type == Type::MAX) { - mut.copy_in_absolute(p_append, MAX); + mut.copy_in_absolute(p_append, MARKER_MAX); } else { ceph_abort("impossible path"); } 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 b32090bb8a27..ccf67c0d735a 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 @@ -128,9 +128,9 @@ inline MatchKindCMP compare_to(const snap_gen_t& l, const snap_gen_t& r) { * The layout to store char array as an oid or an ns string which may be * compressed. * - * (TODO) If compressed, the physical block only stores an unsigned - * int of string_size_t, with value MIN denoting Type::MIN, and value MAX - * denoting Type::MAX. + * (TODO) If compressed, the physical block only stores an unsigned int of + * string_size_t, with value MARKER_MIN denoting Type::MIN, and value + * MARKER_MAX denoting Type::MAX. * * If not compressed (Type::STR), the physical block stores the char array and * a valid string_size_t value. @@ -139,10 +139,11 @@ struct string_key_view_t { enum class Type {MIN, STR, MAX}; // presumably the maximum string length is 2KiB using string_size_t = uint16_t; - static constexpr auto MAX = std::numeric_limits::max(); - static constexpr auto MIN = MAX - 1; + static constexpr auto MARKER_MAX = std::numeric_limits::max(); + static constexpr auto MARKER_MIN = std::numeric_limits::max() - 1; + static constexpr auto VALID_UPPER_BOUND = std::numeric_limits::max() - 2; static bool is_valid_size(size_t size) { - return size < MIN; + return size <= VALID_UPPER_BOUND; } string_key_view_t(const char* p_end) { @@ -152,14 +153,14 @@ struct string_key_view_t { auto _p_key = p_length - length; p_key = static_cast(_p_key); } else { - assert(length == MAX || length == MIN); + assert(length == MARKER_MAX || length == MARKER_MIN); p_key = nullptr; } } Type type() const { - if (length == MIN) { + if (length == MARKER_MIN) { return Type::MIN; - } else if (length == MAX) { + } else if (length == MARKER_MAX) { return Type::MAX; } else { assert(is_valid_size(length)); @@ -230,9 +231,9 @@ struct string_key_view_t { p_append -= sizeof(string_size_t); string_size_t len; if (dedup_type == Type::MIN) { - len = MIN; + len = MARKER_MIN; } else if (dedup_type == Type::MAX) { - len = MAX; + len = MARKER_MAX; } else { ceph_abort("impossible path"); } @@ -290,9 +291,9 @@ class string_view_masked_t { bool operator!=(const string_view_masked_t& x) const { return !(*this == x); } void encode(ceph::bufferlist& bl) const { if (get_type() == Type::MIN) { - ceph::encode(string_key_view_t::MIN, bl); + ceph::encode(string_key_view_t::MARKER_MIN, bl); } else if (get_type() == Type::MAX) { - ceph::encode(string_key_view_t::MAX, bl); + ceph::encode(string_key_view_t::MARKER_MAX, bl); } else { ceph::encode(size(), bl); ceph::encode_nohead(view, bl); @@ -304,9 +305,9 @@ class string_view_masked_t { std::string& str_storage, ceph::bufferlist::const_iterator& delta) { string_size_t size; ceph::decode(size, delta); - if (size == string_key_view_t::MIN) { + if (size == string_key_view_t::MARKER_MIN) { return min(); - } else if (size == string_key_view_t::MAX) { + } else if (size == string_key_view_t::MARKER_MAX) { return max(); } else { ceph::decode_nohead(size, str_storage, delta);