1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once
#include "include/buffer.h"
#include "crimson/common/fixed_kv_node_layout.h"
#include "crimson/common/errorator.h"
#include "crimson/os/seastore/extentmap_manager.h"
#include "crimson/os/seastore/seastore_types.h"
#include "crimson/os/seastore/extentmap_manager/btree/extentmap_btree_node.h"
namespace crimson::os::seastore::extentmap_manager {
struct extmap_node_meta_le_t {
depth_le_t depth = init_les32(0);
extmap_node_meta_le_t() = default;
extmap_node_meta_le_t(const extmap_node_meta_le_t &) = default;
explicit extmap_node_meta_le_t(const extmap_node_meta_t &val)
: depth(init_les32(val.depth)) {}
operator extmap_node_meta_t() const {
return extmap_node_meta_t{ depth };
}
};
/**
* ExtMapInnerNode
*
* Abstracts operations on and layout of internal nodes for the
* Extentmap Tree.
*
* Layout (4k):
* num_entries: uint32_t 4b
* meta : depth 4b
* (padding) : 8b
* keys : objaddr_t[340] (340*4)b
* values : laddr_t[340] (340*8)b
* = 4096
*/
constexpr size_t INNER_NODE_CAPACITY =
(EXTMAP_BLOCK_SIZE - sizeof(uint32_t) - sizeof(extmap_node_meta_t))
/ (sizeof (objaddr_t) + sizeof(laddr_t));
struct ExtMapInnerNode
: ExtMapNode,
common::FixedKVNodeLayout<
INNER_NODE_CAPACITY,
extmap_node_meta_t, extmap_node_meta_le_t,
objaddr_t, ceph_le32,
laddr_t, laddr_le_t> {
using internal_iterator_t = const_iterator;
template <typename... T>
ExtMapInnerNode(T&&... t) :
ExtMapNode(std::forward<T>(t)...),
FixedKVNodeLayout(get_bptr().c_str()) {}
static constexpr extent_types_t type = extent_types_t::EXTMAP_INNER;
extmap_node_meta_t get_node_meta() const final {return get_meta();}
CachedExtentRef duplicate_for_write() final {
assert(delta_buffer.empty());
return CachedExtentRef(new ExtMapInnerNode(*this));
};
delta_buffer_t delta_buffer;
delta_buffer_t *maybe_get_delta_buffer() {
return is_mutation_pending() ? &delta_buffer : nullptr;
}
find_lextent_ret find_lextent(ext_context_t ec, objaddr_t lo, extent_len_t len) final;
insert_ret insert(ext_context_t ec, objaddr_t lo, lext_map_val_t val) final;
rm_lextent_ret rm_lextent(ext_context_t ec, objaddr_t lo, lext_map_val_t val) final;
split_children_ret make_split_children(ext_context_t ec) final;
full_merge_ret make_full_merge(ext_context_t ec, ExtMapNodeRef right) final;
make_balanced_ret make_balanced(ext_context_t ec, ExtMapNodeRef _right, bool prefer_left) final;
std::ostream &print_detail_l(std::ostream &out) const final;
extent_types_t get_type() const final {
return type;
}
ceph::bufferlist get_delta() final {
assert(!delta_buffer.empty());
ceph::buffer::ptr bptr(delta_buffer.get_bytes());
delta_buffer.copy_out(bptr.c_str(), bptr.length());
ceph::bufferlist bl;
bl.push_back(bptr);
return bl;
}
void apply_delta(const ceph::bufferlist &_bl) final {
assert(_bl.length());
ceph::bufferlist bl = _bl;
bl.rebuild();
delta_buffer_t buffer;
buffer.copy_in(bl.front().c_str(), bl.front().length());
buffer.replay(*this);
}
bool at_max_capacity() const final {
return get_size() == get_capacity();
}
bool at_min_capacity() const {
return get_size() == get_capacity() / 2;
}
unsigned get_node_size() const {
return get_size();
}
/* get the iterator containing [l, r]
*/
std::pair<internal_iterator_t, internal_iterator_t> bound(
objaddr_t l, objaddr_t r) {
auto retl = begin();
for (; retl != end(); ++retl) {
if (retl->get_next_key_or_max() > l)
break;
}
auto retr = retl;
for (; retr != end(); ++retr) {
if (retr->get_key() >= r)
break;
}
return {retl, retr};
}
using split_entry_ertr = TransactionManager::read_extent_ertr;
using split_entry_ret = split_entry_ertr::future<ExtMapNodeRef>;
split_entry_ret split_entry(ext_context_t ec, objaddr_t lo,
internal_iterator_t, ExtMapNodeRef entry);
using merge_entry_ertr = TransactionManager::read_extent_ertr;
using merge_entry_ret = merge_entry_ertr::future<ExtMapNodeRef>;
merge_entry_ret merge_entry(ext_context_t ec, objaddr_t lo,
internal_iterator_t iter, ExtMapNodeRef entry);
internal_iterator_t get_containing_child(objaddr_t lo);
};
/**
* ExtMapLeafNode
*
* Abstracts operations on and layout of leaf nodes for the
* ExtentMap Tree.
*
* Layout (4k):
* num_entries: uint32_t 4b
* meta : depth 4b
* (padding) : 8b
* keys : objaddr_t[204] (204*4)b
* values : lext_map_val_t[204] (204*16)b
* = 4096
*/
constexpr size_t LEAF_NODE_CAPACITY =
(EXTMAP_BLOCK_SIZE - sizeof(uint32_t) - sizeof(extmap_node_meta_t))
/ (sizeof(objaddr_t) + sizeof(lext_map_val_t));
struct lext_map_val_le_t {
laddr_le_t laddr;
extent_len_le_t length = init_extent_len_le_t(0);
lext_map_val_le_t() = default;
lext_map_val_le_t(const lext_map_val_le_t &) = default;
explicit lext_map_val_le_t(const lext_map_val_t &val)
: laddr(laddr_le_t(val.laddr)),
length(init_extent_len_le_t(val.length)) {}
operator lext_map_val_t() const {
return lext_map_val_t{laddr, length};
}
};
struct ExtMapLeafNode
: ExtMapNode,
common::FixedKVNodeLayout<
LEAF_NODE_CAPACITY,
extmap_node_meta_t, extmap_node_meta_le_t,
objaddr_t, ceph_le32,
lext_map_val_t, lext_map_val_le_t> {
using internal_iterator_t = const_iterator;
template <typename... T>
ExtMapLeafNode(T&&... t) :
ExtMapNode(std::forward<T>(t)...),
FixedKVNodeLayout(get_bptr().c_str()) {}
static constexpr extent_types_t type = extent_types_t::EXTMAP_LEAF;
extmap_node_meta_t get_node_meta() const final { return get_meta(); }
CachedExtentRef duplicate_for_write() final {
assert(delta_buffer.empty());
return CachedExtentRef(new ExtMapLeafNode(*this));
};
delta_buffer_t delta_buffer;
delta_buffer_t *maybe_get_delta_buffer() {
return is_mutation_pending() ? &delta_buffer : nullptr;
}
find_lextent_ret find_lextent(ext_context_t ec, objaddr_t lo, extent_len_t len) final;
insert_ret insert(ext_context_t ec, objaddr_t lo, lext_map_val_t val) final;
rm_lextent_ret rm_lextent(ext_context_t ec, objaddr_t lo, lext_map_val_t val) final;
split_children_ret make_split_children(ext_context_t ec) final;
full_merge_ret make_full_merge(ext_context_t ec, ExtMapNodeRef right) final;
make_balanced_ret make_balanced(ext_context_t ec, ExtMapNodeRef _right, bool prefer_left) final;
extent_types_t get_type() const final {
return type;
}
ceph::bufferlist get_delta() final {
assert(!delta_buffer.empty());
ceph::buffer::ptr bptr(delta_buffer.get_bytes());
delta_buffer.copy_out(bptr.c_str(), bptr.length());
ceph::bufferlist bl;
bl.push_back(bptr);
return bl;
}
void apply_delta(const ceph::bufferlist &_bl) final {
assert(_bl.length());
ceph::bufferlist bl = _bl;
bl.rebuild();
delta_buffer_t buffer;
buffer.copy_in(bl.front().c_str(), bl.front().length());
buffer.replay(*this);
}
std::ostream &print_detail_l(std::ostream &out) const final;
bool at_max_capacity() const final {
return get_size() == get_capacity();
}
bool at_min_capacity() const final {
return get_size() == get_capacity() / 2;
}
unsigned get_node_size() const {
return get_size();
}
/* get the iterator containing [l, r]
*/
std::pair<internal_iterator_t, internal_iterator_t> bound(
objaddr_t l, objaddr_t r) {
auto retl = begin();
for (; retl != end(); ++retl) {
if (retl->get_key() >= l || (retl->get_key() + retl->get_val().length) > l)
break;
}
auto retr = retl;
for (; retr != end(); ++retr) {
if (retr->get_key() >= r)
break;
}
return {retl, retr};
}
std::pair<internal_iterator_t, internal_iterator_t>
get_leaf_entries(objaddr_t lo, extent_len_t len);
};
using ExtentMapLeafNodeRef = TCachedExtentRef<ExtMapLeafNode>;
}
|