Skip to content

Commit 10c0f2a

Browse files
committed
crimson/os/seastore/btree: add interfaces to check whether the mappings'
parents have been modified Signed-off-by: Xuehan Xu <[email protected]>
1 parent 3e1c083 commit 10c0f2a

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BtreeNodeMapping<key_t, val_t>::get_logical_extent(
2828
template <typename key_t, typename val_t>
2929
bool BtreeNodeMapping<key_t, val_t>::is_stable() const
3030
{
31-
assert(is_parent_valid());
31+
assert(!this->parent_modified());
3232
assert(pos != std::numeric_limits<uint16_t>::max());
3333
auto &p = (FixedKVNode<key_t>&)*parent;
3434
return p.is_child_stable(ctx, pos);
@@ -37,7 +37,7 @@ bool BtreeNodeMapping<key_t, val_t>::is_stable() const
3737
template <typename key_t, typename val_t>
3838
bool BtreeNodeMapping<key_t, val_t>::is_data_stable() const
3939
{
40-
assert(is_parent_valid());
40+
assert(!this->parent_modified());
4141
assert(pos != std::numeric_limits<uint16_t>::max());
4242
auto &p = (FixedKVNode<key_t>&)*parent;
4343
return p.is_child_data_stable(ctx, pos);

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,29 @@ struct FixedKVLeafNode
10041004
node_layout_t(this->get_bptr().c_str()) {}
10051005
FixedKVLeafNode(const FixedKVLeafNode &rhs)
10061006
: FixedKVNode<NODE_KEY>(rhs),
1007-
node_layout_t(this->get_bptr().c_str()) {}
1007+
node_layout_t(this->get_bptr().c_str()),
1008+
modifications(rhs.modifications) {}
10081009

10091010
static constexpr bool do_has_children = has_children;
1011+
// for the stable extent, modifications is always 0;
1012+
// it will increase for each transaction-local change, so that
1013+
// modifications can be detected (see BtreeLBAMapping.parent_modifications)
1014+
uint64_t modifications = 0;
1015+
10101016

10111017
bool have_children() const final {
10121018
return do_has_children;
10131019
}
10141020

1021+
void on_modify() {
1022+
modifications++;
1023+
}
1024+
1025+
bool modified_since(uint64_t v) const {
1026+
ceph_assert(v <= modifications);
1027+
return v != modifications;
1028+
}
1029+
10151030
bool is_leaf_and_has_children() const final {
10161031
return has_children;
10171032
}
@@ -1108,6 +1123,7 @@ struct FixedKVLeafNode
11081123
this->copy_sources.clear();
11091124
}
11101125
}
1126+
modifications = 0;
11111127
assert(this->is_initial_pending()
11121128
? this->copy_sources.empty():
11131129
true);
@@ -1129,6 +1145,7 @@ struct FixedKVLeafNode
11291145
} else {
11301146
this->set_parent_tracker_from_prior_instance();
11311147
}
1148+
modifications = 0;
11321149
}
11331150

11341151
uint16_t lower_bound_offset(NODE_KEY key) const final {

src/crimson/os/seastore/cached_extent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,10 @@ class PhysicalNodeMapping {
11521152
return !get_val().is_real();
11531153
}
11541154
virtual bool is_parent_valid() const = 0;
1155+
virtual bool parent_modified() const {
1156+
ceph_abort("impossible");
1157+
return false;
1158+
};
11551159

11561160
virtual ~PhysicalNodeMapping() {}
11571161
protected:

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
6262
: BtreeNodeMapping(ctx) {}
6363
BtreeLBAMapping(
6464
op_context_t<laddr_t> c,
65-
CachedExtentRef parent,
65+
LBALeafNodeRef parent,
6666
uint16_t pos,
6767
lba_map_val_t &val,
6868
lba_node_meta_t meta)
@@ -78,7 +78,8 @@ class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
7878
intermediate_key(indirect ? val.pladdr.get_laddr() : L_ADDR_NULL),
7979
intermediate_length(indirect ? val.len : 0),
8080
raw_val(val.pladdr),
81-
map_val(val)
81+
map_val(val),
82+
parent_modifications(parent->modifications)
8283
{}
8384

8485
lba_map_val_t get_map_val() const {
@@ -154,6 +155,17 @@ class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
154155
len = length;
155156
}
156157

158+
uint64_t get_parent_modifications() const {
159+
return parent_modifications;
160+
}
161+
162+
bool parent_modified() const final {
163+
ceph_assert(parent);
164+
ceph_assert(is_parent_valid());
165+
auto &p = static_cast<LBALeafNode&>(*parent);
166+
return p.modified_since(parent_modifications);
167+
}
168+
157169
protected:
158170
std::unique_ptr<BtreeNodeMapping<laddr_t, paddr_t>> _duplicate(
159171
op_context_t<laddr_t> ctx) const final {
@@ -165,6 +177,7 @@ class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
165177
pin->indirect = indirect;
166178
pin->raw_val = raw_val;
167179
pin->map_val = map_val;
180+
pin->parent_modifications = parent_modifications;
168181
return pin;
169182
}
170183
private:
@@ -175,6 +188,7 @@ class BtreeLBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
175188
extent_len_t intermediate_length = 0;
176189
pladdr_t raw_val;
177190
lba_map_val_t map_val;
191+
uint64_t parent_modifications = 0;
178192
};
179193

180194
using BtreeLBAMappingRef = std::unique_ptr<BtreeLBAMapping>;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ std::ostream &LBALeafNode::_print_detail(std::ostream &out) const
3131
{
3232
out << ", size=" << this->get_size()
3333
<< ", meta=" << this->get_meta()
34+
<< ", modifications=" << this->modifications
3435
<< ", my_tracker=" << (void*)this->my_tracker;
3536
if (this->my_tracker) {
3637
out << ", my_tracker->parent=" << (void*)this->my_tracker->get_parent().get();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct LBALeafNode
202202
assert(nextent->has_parent_tracker()
203203
&& nextent->get_parent_node<LBALeafNode>().get() == this);
204204
}
205+
this->on_modify();
205206
if (val.pladdr.is_paddr()) {
206207
val.pladdr = maybe_generate_relative(val.pladdr.get_paddr());
207208
}
@@ -222,6 +223,7 @@ struct LBALeafNode
222223
iter.get_offset(),
223224
addr,
224225
(void*)nextent);
226+
this->on_modify();
225227
this->insert_child_ptr(iter, nextent);
226228
if (val.pladdr.is_paddr()) {
227229
val.pladdr = maybe_generate_relative(val.pladdr.get_paddr());
@@ -241,6 +243,7 @@ struct LBALeafNode
241243
iter.get_offset(),
242244
iter.get_key());
243245
assert(iter != this->end());
246+
this->on_modify();
244247
this->remove_child_ptr(iter);
245248
return this->journal_remove(
246249
iter,

src/crimson/os/seastore/transaction_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class TransactionManager : public ExtentCallbackInterface {
221221
LBAMappingRef pin,
222222
extent_types_t type)
223223
{
224-
ceph_assert(pin->is_parent_valid());
224+
ceph_assert(!pin->parent_modified());
225225
auto v = pin->get_logical_extent(t);
226226
// checking the lba child must be atomic with creating
227227
// and linking the absent child

0 commit comments

Comments
 (0)