Skip to content

Commit 262221d

Browse files
authored
Merge pull request ceph#61261 from xxhdx1985126/wip-seastore-lba-backref-mapping
crimson/os/seastore: refactor LBAMapping Reviewed-by: Yingxin Cheng <[email protected]>
2 parents 4a03c75 + cadb202 commit 262221d

File tree

14 files changed

+221
-190
lines changed

14 files changed

+221
-190
lines changed

src/crimson/os/seastore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(crimson_seastore_srcs
22
cached_extent.cc
3+
lba_mapping.cc
34
seastore_types.cc
45
segment_manager.cc
56
segment_manager/ephemeral.cc
@@ -19,7 +20,6 @@ set(crimson_seastore_srcs
1920
omap_manager.cc
2021
omap_manager/btree/btree_omap_manager.cc
2122
omap_manager/btree/omap_btree_node_impl.cc
22-
btree/btree_range_pin.cc
2323
btree/fixed_kv_node.cc
2424
onode.cc
2525
onode_manager/staged-fltree/node.cc

src/crimson/os/seastore/async_cleaner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "crimson/os/seastore/randomblock_manager_group.h"
1818
#include "crimson/os/seastore/transaction.h"
1919
#include "crimson/os/seastore/segment_seq_allocator.h"
20+
#include "crimson/os/seastore/backref_mapping.h"
2021

2122
namespace crimson::os::seastore {
2223

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,28 @@
99

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

12-
constexpr size_t BACKREF_BLOCK_SIZE = 4096;
13-
14-
class BtreeBackrefMapping : public BtreeNodeMapping<paddr_t, laddr_t> {
15-
extent_types_t type;
12+
class BtreeBackrefMapping : public BackrefMapping {
1613
public:
1714
BtreeBackrefMapping(op_context_t<paddr_t> ctx)
18-
: BtreeNodeMapping(ctx) {}
15+
: BackrefMapping(ctx) {}
1916
BtreeBackrefMapping(
2017
op_context_t<paddr_t> ctx,
2118
CachedExtentRef parent,
2219
uint16_t pos,
2320
backref_map_val_t &val,
2421
backref_node_meta_t &&meta)
25-
: BtreeNodeMapping(
22+
: BackrefMapping(
23+
val.type,
2624
ctx,
2725
parent,
2826
pos,
2927
val.laddr,
3028
val.len,
31-
std::forward<backref_node_meta_t>(meta)),
32-
type(val.type)
33-
{}
34-
extent_types_t get_type() const final {
35-
return type;
36-
}
37-
38-
bool is_clone() const final {
39-
return false;
40-
}
41-
42-
protected:
43-
std::unique_ptr<BtreeNodeMapping<paddr_t, laddr_t>> _duplicate(
44-
op_context_t<paddr_t> ctx) const final {
45-
return std::unique_ptr<BtreeNodeMapping<paddr_t, laddr_t>>(
46-
new BtreeBackrefMapping(ctx));
47-
}
29+
std::forward<backref_node_meta_t>(meta)) {}
4830
};
4931

32+
constexpr size_t BACKREF_BLOCK_SIZE = 4096;
33+
5034
using BackrefBtree = FixedKVBtree<
5135
paddr_t, backref_map_val_t, BackrefInternalNode,
5236
BackrefLeafNode, BtreeBackrefMapping, BACKREF_BLOCK_SIZE, false>;

src/crimson/os/seastore/backref_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "crimson/os/seastore/cache.h"
77
#include "crimson/os/seastore/cached_extent.h"
88
#include "crimson/os/seastore/transaction.h"
9+
#include "crimson/os/seastore/backref_mapping.h"
910

1011
namespace crimson::os::seastore {
1112

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
4+
#pragma once
5+
6+
#include "crimson/os/seastore/btree/btree_range_pin.h"
7+
8+
namespace crimson::os::seastore {
9+
10+
class BackrefMapping : public BtreeNodeMapping<paddr_t, laddr_t> {
11+
extent_types_t type;
12+
public:
13+
BackrefMapping(op_context_t<paddr_t> ctx)
14+
: BtreeNodeMapping(ctx) {}
15+
template <typename... T>
16+
BackrefMapping(extent_types_t type, T&&... t)
17+
: BtreeNodeMapping(std::forward<T>(t)...),
18+
type(type) {}
19+
extent_types_t get_type() const {
20+
return type;
21+
}
22+
};
23+
24+
using BackrefMappingRef = std::unique_ptr<BackrefMapping>;
25+
using backref_pin_list_t = std::list<BackrefMappingRef>;
26+
27+
} // namespace crimson::os::seastore

src/crimson/os/seastore/btree/btree_range_pin.cc

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/crimson/os/seastore/btree/btree_range_pin.h

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
#include "crimson/common/log.h"
99

10-
#include "crimson/os/seastore/cache.h"
1110
#include "crimson/os/seastore/cached_extent.h"
1211
#include "crimson/os/seastore/seastore_types.h"
12+
#include "crimson/os/seastore/transaction.h"
1313

1414
namespace crimson::os::seastore {
15+
class Cache;
1516

1617
template <typename node_key_t>
1718
struct op_context_t {
@@ -116,8 +117,6 @@ class BtreeNodeMapping : public PhysicalNodeMapping<key_t, val_t> {
116117
extent_len_t len = 0;
117118
fixed_kv_node_meta_t<key_t> range;
118119
uint16_t pos = std::numeric_limits<uint16_t>::max();
119-
120-
virtual std::unique_ptr<BtreeNodeMapping> _duplicate(op_context_t<key_t>) const = 0;
121120
fixed_kv_node_meta_t<key_t> _get_pin_range() const {
122121
return range;
123122
}
@@ -139,11 +138,7 @@ class BtreeNodeMapping : public PhysicalNodeMapping<key_t, val_t> {
139138
len(len),
140139
range(meta),
141140
pos(pos)
142-
{
143-
if (!parent->is_pending()) {
144-
this->child_pos = {parent, pos};
145-
}
146-
}
141+
{}
147142

148143
CachedExtentRef get_parent() const final {
149144
return parent;
@@ -162,11 +157,6 @@ class BtreeNodeMapping : public PhysicalNodeMapping<key_t, val_t> {
162157
return len;
163158
}
164159

165-
extent_types_t get_type() const override {
166-
ceph_abort("should never happen");
167-
return extent_types_t::ROOT;
168-
}
169-
170160
val_t get_val() const final {
171161
if constexpr (std::is_same_v<val_t, paddr_t>) {
172162
return value.get_paddr();
@@ -180,16 +170,6 @@ class BtreeNodeMapping : public PhysicalNodeMapping<key_t, val_t> {
180170
return range.begin;
181171
}
182172

183-
PhysicalNodeMappingRef<key_t, val_t> duplicate() const final {
184-
auto ret = _duplicate(ctx);
185-
ret->range = range;
186-
ret->value = value;
187-
ret->parent = parent;
188-
ret->len = len;
189-
ret->pos = pos;
190-
return ret;
191-
}
192-
193173
bool has_been_invalidated() const final {
194174
return parent->has_been_invalidated();
195175
}
@@ -215,9 +195,6 @@ class BtreeNodeMapping : public PhysicalNodeMapping<key_t, val_t> {
215195
return unviewable;
216196
}
217197

218-
get_child_ret_t<LogicalCachedExtent> get_logical_extent(Transaction&) final;
219-
bool is_stable() const final;
220-
bool is_data_stable() const final;
221198
bool is_parent_viewable() const final {
222199
ceph_assert(parent);
223200
if (!parent->is_valid()) {

src/crimson/os/seastore/cached_extent.cc

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "crimson/common/log.h"
88

99
#include "crimson/os/seastore/btree/fixed_kv_node.h"
10+
#include "crimson/os/seastore/lba_mapping.h"
1011

1112
namespace {
1213
[[maybe_unused]] seastar::logger& logger() {
@@ -142,6 +143,12 @@ void LogicalCachedExtent::on_replace_prior() {
142143
parent->children[off] = this;
143144
}
144145

146+
void LogicalCachedExtent::maybe_set_intermediate_laddr(LBAMapping &mapping) {
147+
laddr = mapping.is_indirect()
148+
? mapping.get_intermediate_base()
149+
: mapping.get_key();
150+
}
151+
145152
parent_tracker_t::~parent_tracker_t() {
146153
// this is parent's tracker, reset it
147154
auto &p = (FixedKVNode<laddr_t>&)*parent;
@@ -150,32 +157,6 @@ parent_tracker_t::~parent_tracker_t() {
150157
}
151158
}
152159

153-
std::ostream &operator<<(std::ostream &out, const LBAMapping &rhs)
154-
{
155-
out << "LBAMapping(" << rhs.get_key()
156-
<< "~0x" << std::hex << rhs.get_length() << std::dec
157-
<< "->" << rhs.get_val();
158-
if (rhs.is_indirect()) {
159-
out << ",indirect(" << rhs.get_intermediate_base()
160-
<< "~0x" << std::hex << rhs.get_intermediate_length()
161-
<< "@0x" << rhs.get_intermediate_offset() << std::dec
162-
<< ")";
163-
}
164-
out << ")";
165-
return out;
166-
}
167-
168-
std::ostream &operator<<(std::ostream &out, const lba_pin_list_t &rhs)
169-
{
170-
bool first = true;
171-
out << '[';
172-
for (const auto &i: rhs) {
173-
out << (first ? "" : ",") << *i;
174-
first = false;
175-
}
176-
return out << ']';
177-
}
178-
179160
bool BufferSpace::is_range_loaded(extent_len_t offset, extent_len_t length) const
180161
{
181162
assert(length > 0);

0 commit comments

Comments
 (0)