Skip to content

Commit 8c6cede

Browse files
committed
crimson/os/seastore/cache: introduce maybe_add_to_read_set()
And only touch extent if it is absent in transaction. Signed-off-by: Yingxin Cheng <[email protected]>
1 parent 6933f4c commit 8c6cede

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/crimson/os/seastore/cache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ class Cache {
494494
} else {
495495
// stable from trans-view
496496
assert(!p_extent->is_pending_in_trans(t.get_trans_id()));
497-
t.add_to_read_set(p_extent);
498-
touch_extent(*p_extent);
497+
if (t.maybe_add_to_read_set(p_extent)) {
498+
touch_extent(*p_extent);
499+
}
499500
}
500501
} else {
501502
assert(!extent->is_stable_writting());

src/crimson/os/seastore/transaction.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,37 @@ class Transaction {
137137
}
138138
}
139139

140+
// Returns true if added, false if already added or weak
141+
bool maybe_add_to_read_set(CachedExtentRef ref) {
142+
if (is_weak()) {
143+
return false;
144+
}
145+
146+
assert(ref->is_valid());
147+
148+
auto it = ref->transactions.lower_bound(
149+
this, read_set_item_t<Transaction>::trans_cmp_t());
150+
if (it != ref->transactions.end() && it->t == this) {
151+
return false;
152+
}
153+
154+
auto [iter, inserted] = read_set.emplace(this, ref);
155+
ceph_assert(inserted);
156+
ref->transactions.insert_before(
157+
it, const_cast<read_set_item_t<Transaction>&>(*iter));
158+
return true;
159+
}
160+
140161
void add_to_read_set(CachedExtentRef ref) {
141-
if (is_weak()) return;
162+
if (is_weak()) {
163+
return;
164+
}
142165

143166
assert(ref->is_valid());
144167

145168
auto it = ref->transactions.lower_bound(
146169
this, read_set_item_t<Transaction>::trans_cmp_t());
147-
if (it != ref->transactions.end() && it->t == this) return;
170+
assert(it == ref->transactions.end() || it->t != this);
148171

149172
auto [iter, inserted] = read_set.emplace(this, ref);
150173
ceph_assert(inserted);

0 commit comments

Comments
 (0)