1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
8 #include "node_extent_mutable.h"
9 #include "node_types.h"
10 #include "stages/stage_types.h"
12 namespace crimson::os::seastore::onode
{
14 #ifdef UNIT_TESTS_BUILT
15 enum class InsertType
{ BEGIN
, LAST
, MID
};
16 struct split_expectation_t
{
17 match_stage_t split_stage
;
18 match_stage_t insert_stage
;
20 InsertType insert_type
;
22 struct last_split_info_t
{
23 search_position_t split_pos
;
24 match_stage_t insert_stage
;
26 InsertType insert_type
;
27 bool match(const split_expectation_t
& e
) const {
28 match_stage_t split_stage
;
29 if (split_pos
.nxt
.nxt
.index
== 0) {
30 if (split_pos
.nxt
.index
== 0) {
38 return split_stage
== e
.split_stage
&&
39 insert_stage
== e
.insert_stage
&&
40 is_insert_left
== e
.is_insert_left
&&
41 insert_type
== e
.insert_type
;
43 bool match_split_pos(const search_position_t
& pos
) const {
44 return split_pos
== pos
;
47 extern last_split_info_t last_split
;
52 class NodeExtentMutable
;
57 * Hides type specific node layout implementations for Node.
61 using alloc_ertr
= crimson::errorator
<
62 crimson::ct_error::input_output_error
,
63 crimson::ct_error::invarg
,
64 crimson::ct_error::enoent
,
65 crimson::ct_error::erange
>;
66 virtual ~NodeImpl() = default;
68 virtual field_type_t
field_type() const = 0;
69 virtual laddr_t
laddr() const = 0;
70 virtual void prepare_mutate(context_t
) = 0;
71 virtual bool is_level_tail() const = 0;
72 virtual bool is_empty() const = 0;
73 virtual level_t
level() const = 0;
74 virtual node_offset_t
free_size() const = 0;
75 virtual key_view_t
get_key_view(const search_position_t
&) const = 0;
76 virtual key_view_t
get_largest_key_view() const = 0;
77 virtual void next_position(search_position_t
&) const = 0;
79 virtual node_stats_t
get_stats() const = 0;
80 virtual std::ostream
& dump(std::ostream
&) const = 0;
81 virtual std::ostream
& dump_brief(std::ostream
&) const = 0;
82 virtual void validate_layout() const = 0;
84 virtual void test_copy_to(NodeExtentMutable
&) const = 0;
85 virtual void test_set_tail(NodeExtentMutable
&) = 0;
94 * Hides type specific node layout implementations for InternalNode.
96 class InternalNodeImpl
: public NodeImpl
{
98 struct internal_marker_t
{};
99 virtual ~InternalNodeImpl() = default;
101 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
102 virtual const laddr_packed_t
* get_p_value(
103 const search_position_t
&,
104 key_view_t
* = nullptr, internal_marker_t
= {}) const {
105 ceph_abort("impossible path");
107 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
108 virtual lookup_result_t
<node_type_t::INTERNAL
> lower_bound(
109 const key_hobj_t
&, MatchHistory
&,
110 key_view_t
* = nullptr, internal_marker_t
= {}) const {
111 ceph_abort("impossible path");
113 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
114 virtual const laddr_packed_t
* insert(
115 const key_view_t
&, const laddr_packed_t
&, search_position_t
&, match_stage_t
&, node_offset_t
&) {
116 ceph_abort("impossible path");
118 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
119 virtual std::tuple
<search_position_t
, bool, const laddr_packed_t
*> split_insert(
120 NodeExtentMutable
&, NodeImpl
&, const key_view_t
&, const laddr_packed_t
&,
121 search_position_t
&, match_stage_t
&, node_offset_t
&) {
122 ceph_abort("impossible path");
125 virtual void replace_child_addr(const search_position_t
&, laddr_t dst
, laddr_t src
) = 0;
126 virtual std::tuple
<match_stage_t
, node_offset_t
> evaluate_insert(
127 const key_view_t
&, const laddr_t
&, search_position_t
&) const = 0;
129 struct fresh_impl_t
{
130 InternalNodeImplURef impl
;
131 NodeExtentMutable mut
;
132 std::pair
<NodeImplURef
, NodeExtentMutable
> make_pair() {
133 return {std::move(impl
), mut
};
136 static alloc_ertr::future
<fresh_impl_t
> allocate(context_t
, field_type_t
, bool, level_t
);
137 static InternalNodeImplURef
load(NodeExtentRef
, field_type_t
, bool);
140 InternalNodeImpl() = default;
146 * Hides type specific node layout implementations for LeafNode.
148 class LeafNodeImpl
: public NodeImpl
{
150 struct leaf_marker_t
{};
151 virtual ~LeafNodeImpl() = default;
153 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
154 virtual const onode_t
* get_p_value(
155 const search_position_t
&,
156 key_view_t
* = nullptr, leaf_marker_t
={}) const {
157 ceph_abort("impossible path");
159 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
160 virtual lookup_result_t
<node_type_t::LEAF
> lower_bound(
161 const key_hobj_t
&, MatchHistory
&,
162 key_view_t
* = nullptr, leaf_marker_t
= {}) const {
163 ceph_abort("impossible path");
165 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
166 virtual const onode_t
* insert(
167 const key_hobj_t
&, const onode_t
&, search_position_t
&, match_stage_t
&, node_offset_t
&) {
168 ceph_abort("impossible path");
170 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
171 virtual std::tuple
<search_position_t
, bool, const onode_t
*> split_insert(
172 NodeExtentMutable
&, NodeImpl
&, const key_hobj_t
&, const onode_t
&,
173 search_position_t
&, match_stage_t
&, node_offset_t
&) {
174 ceph_abort("impossible path");
177 virtual void get_largest_slot(
178 search_position_t
&, key_view_t
&, const onode_t
**) const = 0;
179 virtual std::tuple
<match_stage_t
, node_offset_t
> evaluate_insert(
180 const key_hobj_t
&, const onode_t
&,
181 const MatchHistory
&, match_stat_t
, search_position_t
&) const = 0;
183 struct fresh_impl_t
{
184 LeafNodeImplURef impl
;
185 NodeExtentMutable mut
;
186 std::pair
<NodeImplURef
, NodeExtentMutable
> make_pair() {
187 return {std::move(impl
), mut
};
190 static alloc_ertr::future
<fresh_impl_t
> allocate(context_t
, field_type_t
, bool);
191 static LeafNodeImplURef
load(NodeExtentRef
, field_type_t
, bool);
194 LeafNodeImpl() = default;