]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/onode_manager/staged-fltree/node_impl.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / os / seastore / onode_manager / staged-fltree / node_impl.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <ostream>
7
8 #include "node_extent_mutable.h"
9 #include "node_types.h"
10 #include "stages/stage_types.h"
11
12 namespace crimson::os::seastore::onode {
13
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;
19 bool is_insert_left;
20 InsertType insert_type;
21 };
22 struct last_split_info_t {
23 search_position_t split_pos;
24 match_stage_t insert_stage;
25 bool is_insert_left;
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) {
31 split_stage = 2;
32 } else {
33 split_stage = 1;
34 }
35 } else {
36 split_stage = 0;
37 }
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;
42 }
43 bool match_split_pos(const search_position_t& pos) const {
44 return split_pos == pos;
45 }
46 };
47 extern last_split_info_t last_split;
48 #endif
49
50 struct key_hobj_t;
51 struct key_view_t;
52 class NodeExtentMutable;
53
54 /**
55 * NodeImpl
56 *
57 * Hides type specific node layout implementations for Node.
58 */
59 class NodeImpl {
60 public:
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;
67
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;
78
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;
83
84 virtual void test_copy_to(NodeExtentMutable&) const = 0;
85 virtual void test_set_tail(NodeExtentMutable&) = 0;
86
87 protected:
88 NodeImpl() = default;
89 };
90
91 /**
92 * InternalNodeImpl
93 *
94 * Hides type specific node layout implementations for InternalNode.
95 */
96 class InternalNodeImpl : public NodeImpl {
97 public:
98 struct internal_marker_t {};
99 virtual ~InternalNodeImpl() = default;
100
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");
106 }
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");
112 }
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");
117 }
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");
123 }
124
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;
128
129 struct fresh_impl_t {
130 InternalNodeImplURef impl;
131 NodeExtentMutable mut;
132 std::pair<NodeImplURef, NodeExtentMutable> make_pair() {
133 return {std::move(impl), mut};
134 }
135 };
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);
138
139 protected:
140 InternalNodeImpl() = default;
141 };
142
143 /**
144 * LeafNodeImpl
145 *
146 * Hides type specific node layout implementations for LeafNode.
147 */
148 class LeafNodeImpl : public NodeImpl {
149 public:
150 struct leaf_marker_t {};
151 virtual ~LeafNodeImpl() = default;
152
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");
158 }
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");
164 }
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");
169 }
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");
175 }
176
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;
182
183 struct fresh_impl_t {
184 LeafNodeImplURef impl;
185 NodeExtentMutable mut;
186 std::pair<NodeImplURef, NodeExtentMutable> make_pair() {
187 return {std::move(impl), mut};
188 }
189 };
190 static alloc_ertr::future<fresh_impl_t> allocate(context_t, field_type_t, bool);
191 static LeafNodeImplURef load(NodeExtentRef, field_type_t, bool);
192
193 protected:
194 LeafNodeImpl() = default;
195 };
196
197 }