Skip to content

Commit 295544f

Browse files
zhscnMatan-B
authored andcommitted
crimson/os/seastore: refactor LBAMapping and BackrefMapping
Signed-off-by: Zhang Song <[email protected]> (cherry picked from commit 23883c9)
1 parent a80c4d4 commit 295544f

File tree

8 files changed

+212
-370
lines changed

8 files changed

+212
-370
lines changed

src/crimson/os/seastore/backref/btree_backref_manager.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@
99

1010
namespace crimson::os::seastore::backref {
1111

12-
class BtreeBackrefMapping : public BackrefMapping {
13-
public:
14-
BtreeBackrefMapping(
15-
op_context_t ctx,
16-
BackrefLeafNodeRef parent,
17-
uint16_t pos,
18-
backref_map_val_t &val,
19-
backref_node_meta_t &&meta)
20-
: BackrefMapping(
21-
val.type,
22-
ctx,
23-
parent,
24-
pos,
25-
val.laddr,
26-
val.len,
27-
std::forward<backref_node_meta_t>(meta)) {}
28-
};
29-
3012
constexpr size_t BACKREF_BLOCK_SIZE = 4096;
3113

3214
using BackrefBtree = FixedKVBtree<

src/crimson/os/seastore/backref_mapping.h

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,52 @@
88
namespace crimson::os::seastore {
99

1010
class BackrefMapping {
11-
op_context_t ctx;
12-
CachedExtentRef parent;
13-
fixed_kv_node_meta_t<paddr_t> range;
14-
laddr_t value;
15-
extent_len_t len = 0;
16-
uint16_t pos = std::numeric_limits<uint16_t>::max();
17-
extent_types_t type;
11+
BackrefCursorRef cursor;
12+
13+
BackrefMapping(BackrefCursorRef cursor)
14+
: cursor(std::move(cursor)) {}
15+
1816
public:
19-
BackrefMapping(
20-
extent_types_t type,
21-
op_context_t ctx,
22-
CachedExtentRef parent,
23-
uint16_t pos,
24-
laddr_t value,
25-
extent_len_t len,
26-
fixed_kv_node_meta_t<paddr_t> meta)
27-
: ctx(ctx),
28-
parent(parent),
29-
range(meta),
30-
value(value),
31-
len(len),
32-
pos(pos),
33-
type(type)
34-
{}
17+
static BackrefMapping create(BackrefCursorRef cursor) {
18+
return BackrefMapping(std::move(cursor));
19+
}
20+
21+
BackrefMapping() = default;
22+
23+
BackrefMapping(const BackrefMapping &) = delete;
24+
BackrefMapping(BackrefMapping &&) = default;
25+
26+
BackrefMapping &operator=(const BackrefMapping &) = delete;
27+
BackrefMapping &operator=(BackrefMapping &&) = default;
28+
29+
~BackrefMapping() = default;
30+
31+
bool is_viewable() const {
32+
assert(cursor);
33+
return cursor->is_viewable();
34+
}
3535

3636
extent_len_t get_length() const {
37-
ceph_assert(range.end > range.begin);
38-
return len;
37+
assert(cursor);
38+
return cursor->get_length();
3939
}
4040

4141
laddr_t get_val() const {
42-
return value;
42+
assert(cursor);
43+
return cursor->get_laddr();
4344
}
4445

4546
paddr_t get_key() const {
46-
return range.begin;
47+
assert(cursor);
48+
return cursor->get_paddr();
4749
}
4850

4951
extent_types_t get_type() const {
50-
return type;
52+
assert(cursor);
53+
return cursor->get_type();
5154
}
5255
};
5356

54-
using BackrefMappingRef = std::unique_ptr<BackrefMapping>;
55-
using backref_pin_list_t = std::list<BackrefMappingRef>;
57+
using backref_mapping_list_t = std::list<BackrefMapping>;
5658

5759
} // namespace crimson::os::seastore

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.cc

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,37 +89,6 @@ template class TreeRootLinker<RootBlock, lba_manager::btree::LBALeafNode>;
8989

9090
namespace crimson::os::seastore::lba_manager::btree {
9191

92-
get_child_ret_t<lba_manager::btree::LBALeafNode, LogicalChildNode>
93-
BtreeLBAMapping::get_logical_extent(Transaction &t)
94-
{
95-
ceph_assert(is_parent_viewable());
96-
assert(pos != std::numeric_limits<uint16_t>::max());
97-
ceph_assert(t.get_trans_id() == ctx.trans.get_trans_id());
98-
auto &p = static_cast<LBALeafNode&>(*parent);
99-
auto k = this->is_indirect()
100-
? this->get_intermediate_base()
101-
: get_key();
102-
return p.template get_child<LogicalChildNode>(ctx.trans, ctx.cache, pos, k);
103-
}
104-
105-
bool BtreeLBAMapping::is_stable() const
106-
{
107-
assert(!parent_modified());
108-
assert(pos != std::numeric_limits<uint16_t>::max());
109-
auto &p = (LBALeafNode&)*parent;
110-
auto k = is_indirect() ? get_intermediate_base() : get_key();
111-
return p.is_child_stable(ctx, pos, k);
112-
}
113-
114-
bool BtreeLBAMapping::is_data_stable() const
115-
{
116-
assert(!parent_modified());
117-
assert(pos != std::numeric_limits<uint16_t>::max());
118-
auto &p = (LBALeafNode&)*parent;
119-
auto k = is_indirect() ? get_intermediate_base() : get_key();
120-
return p.is_child_data_stable(ctx, pos, k);
121-
}
122-
12392
BtreeLBAManager::mkfs_ret
12493
BtreeLBAManager::mkfs(
12594
Transaction &t)

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h

Lines changed: 0 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -29,206 +29,6 @@ class LogicalCachedExtent;
2929

3030
namespace crimson::os::seastore::lba_manager::btree {
3131

32-
class BtreeLBAMapping : public LBAMapping {
33-
// To support cloning, there are two kinds of lba mappings:
34-
// 1. physical lba mapping: the pladdr in the value of which is the paddr of
35-
// the corresponding extent;
36-
// 2. indirect lba mapping: the pladdr in the value of which is an laddr pointing
37-
// to the physical lba mapping that's pointing to the actual paddr of the
38-
// extent being searched;
39-
//
40-
// Accordingly, BtreeLBAMapping may also work under two modes: indirect or direct
41-
// 1. BtreeLBAMappings that come from quering an indirect lba mapping in the lba tree
42-
// are indirect;
43-
// 2. BtreeLBAMappings that come from quering a physical lba mapping in the lba tree
44-
// are direct.
45-
//
46-
// For direct BtreeLBAMappings, there are two important fields:
47-
// 1. key: the laddr of the lba mapping being queried;
48-
// 2. paddr: the paddr recorded in the value of the lba mapping being queried.
49-
// For indirect BtreeLBAMappings, BtreeLBAMapping has three important fields:
50-
// 1. key: the laddr key of the lba entry being queried;
51-
// 2. intermediate_key: the laddr within the scope of the physical lba mapping
52-
// that the current indirect lba mapping points to; although an indirect mapping
53-
// points to the start of the physical lba mapping, it may change to other
54-
// laddr after remap
55-
// 3. intermediate_base: the laddr key of the physical lba mapping, intermediate_key
56-
// and intermediate_base should be the same when doing cloning
57-
// 4. intermediate_offset: intermediate_key - intermediate_base
58-
// 5. intermediate_length: the length of the actual physical lba mapping
59-
// 6. paddr: the paddr recorded in the physical lba mapping pointed to by the
60-
// indirect lba mapping being queried;
61-
//
62-
// NOTE THAT, for direct BtreeLBAMappings, their intermediate_keys are the same as
63-
// their keys.
64-
public:
65-
BtreeLBAMapping(op_context_t ctx)
66-
: LBAMapping(ctx) {}
67-
BtreeLBAMapping(
68-
op_context_t c,
69-
LBALeafNodeRef parent,
70-
uint16_t pos,
71-
lba_map_val_t &val,
72-
lba_node_meta_t meta)
73-
: LBAMapping(
74-
c,
75-
parent,
76-
pos,
77-
val.pladdr.is_paddr() ? val.pladdr.get_paddr() : P_ADDR_NULL,
78-
val.len,
79-
meta),
80-
key(meta.begin),
81-
indirect(val.pladdr.is_laddr()),
82-
intermediate_key(indirect ? val.pladdr.get_laddr() : L_ADDR_NULL),
83-
intermediate_length(indirect ? val.len : 0),
84-
raw_val(val.pladdr),
85-
map_val(val),
86-
parent_modifications(parent->modifications)
87-
{}
88-
89-
lba_map_val_t get_map_val() const {
90-
return map_val;
91-
}
92-
93-
bool is_indirect() const final {
94-
return indirect;
95-
}
96-
97-
void make_indirect(
98-
laddr_t new_key,
99-
extent_len_t length,
100-
laddr_t interkey = L_ADDR_NULL)
101-
{
102-
assert(!indirect);
103-
indirect = true;
104-
intermediate_base = key;
105-
intermediate_length = len;
106-
adjust_mutable_indirect_attrs(new_key, length, interkey);
107-
}
108-
109-
laddr_t get_key() const final {
110-
return key;
111-
}
112-
113-
pladdr_t get_raw_val() const {
114-
return raw_val;
115-
}
116-
117-
laddr_t get_intermediate_key() const final {
118-
assert(is_indirect());
119-
assert(intermediate_key != L_ADDR_NULL);
120-
return intermediate_key;
121-
}
122-
123-
laddr_t get_intermediate_base() const final {
124-
assert(is_indirect());
125-
assert(intermediate_base != L_ADDR_NULL);
126-
return intermediate_base;
127-
}
128-
129-
extent_len_t get_intermediate_offset() const final {
130-
assert(intermediate_key >= intermediate_base);
131-
assert((intermediate_key == L_ADDR_NULL)
132-
== (intermediate_base == L_ADDR_NULL));
133-
return intermediate_key.get_byte_distance<extent_len_t>(intermediate_base);
134-
}
135-
136-
extent_len_t get_intermediate_length() const final {
137-
assert(is_indirect());
138-
assert(intermediate_length);
139-
return intermediate_length;
140-
}
141-
142-
bool is_clone() const final {
143-
return get_map_val().refcount > 1;
144-
}
145-
146-
uint32_t get_checksum() const final {
147-
return get_map_val().checksum;
148-
}
149-
150-
void adjust_mutable_indirect_attrs(
151-
laddr_t new_key,
152-
extent_len_t length,
153-
laddr_t interkey = L_ADDR_NULL)
154-
{
155-
assert(indirect);
156-
assert(value.is_paddr());
157-
intermediate_key = (interkey == L_ADDR_NULL ? key : interkey);
158-
key = new_key;
159-
len = length;
160-
}
161-
162-
uint64_t get_parent_modifications() const {
163-
return parent_modifications;
164-
}
165-
166-
bool parent_modified() const final {
167-
ceph_assert(parent);
168-
ceph_assert(is_parent_viewable());
169-
auto &p = static_cast<LBALeafNode&>(*parent);
170-
return p.modified_since(parent_modifications);
171-
}
172-
173-
void maybe_fix_pos() final {
174-
assert(is_parent_viewable());
175-
if (!parent_modified()) {
176-
return;
177-
}
178-
LOG_PREFIX(BtreeLBAMapping::maybe_fix_pos);
179-
auto &p = static_cast<LBALeafNode&>(*parent);
180-
p.maybe_fix_mapping_pos(*this);
181-
SUBDEBUGT(seastore_lba, "fixed pin {}",
182-
ctx.trans, static_cast<LBAMapping&>(*this));
183-
}
184-
185-
LBAMappingRef refresh_with_pending_parent() final {
186-
LOG_PREFIX(BtreeLBAMapping::refresh_with_pending_parent);
187-
assert(is_parent_valid() && !is_parent_viewable());
188-
auto &p = static_cast<LBALeafNode&>(*parent);
189-
auto &viewable_p = static_cast<LBALeafNode&>(
190-
*p.find_pending_version(ctx.trans, get_key()));
191-
auto new_pin = viewable_p.get_mapping(ctx, get_key());
192-
SUBDEBUGT(seastore_lba, "new pin {}", ctx.trans, static_cast<LBAMapping&>(*new_pin));
193-
return new_pin;
194-
}
195-
bool is_stable() const final;
196-
bool is_data_stable() const final;
197-
get_child_ret_t<lba_manager::btree::LBALeafNode, LogicalChildNode>
198-
get_logical_extent(Transaction &t);
199-
200-
protected:
201-
LBAMappingRef _duplicate(
202-
op_context_t ctx) const final {
203-
auto pin = std::unique_ptr<BtreeLBAMapping>(new BtreeLBAMapping(ctx));
204-
pin->key = key;
205-
pin->intermediate_base = intermediate_base;
206-
pin->intermediate_key = intermediate_key;
207-
pin->intermediate_length = intermediate_length;
208-
pin->indirect = indirect;
209-
pin->raw_val = raw_val;
210-
pin->map_val = map_val;
211-
pin->parent_modifications = parent_modifications;
212-
return pin;
213-
}
214-
private:
215-
void _new_pos(uint16_t pos) {
216-
this->pos = pos;
217-
}
218-
219-
laddr_t key = L_ADDR_NULL;
220-
bool indirect = false;
221-
laddr_t intermediate_key = L_ADDR_NULL;
222-
laddr_t intermediate_base = L_ADDR_NULL;
223-
extent_len_t intermediate_length = 0;
224-
pladdr_t raw_val;
225-
lba_map_val_t map_val;
226-
uint64_t parent_modifications = 0;
227-
friend struct LBALeafNode;
228-
};
229-
230-
using BtreeLBAMappingRef = std::unique_ptr<BtreeLBAMapping>;
231-
23232
using LBABtree = FixedKVBtree<
23333
laddr_t, lba_map_val_t, LBAInternalNode,
23434
LBALeafNode, LBACursor, LBA_BLOCK_SIZE>;

0 commit comments

Comments
 (0)