} else {
// stable from trans-view
assert(!p_extent->is_pending_in_trans(t.get_trans_id()));
- t.add_to_read_set(p_extent);
- touch_extent(*p_extent);
+ if (t.maybe_add_to_read_set(p_extent)) {
+ touch_extent(*p_extent);
+ }
}
} else {
assert(!extent->is_stable_writting());
}
}
+ // Returns true if added, false if already added or weak
+ bool maybe_add_to_read_set(CachedExtentRef ref) {
+ if (is_weak()) {
+ return false;
+ }
+
+ assert(ref->is_valid());
+
+ auto it = ref->transactions.lower_bound(
+ this, read_set_item_t<Transaction>::trans_cmp_t());
+ if (it != ref->transactions.end() && it->t == this) {
+ return false;
+ }
+
+ auto [iter, inserted] = read_set.emplace(this, ref);
+ ceph_assert(inserted);
+ ref->transactions.insert_before(
+ it, const_cast<read_set_item_t<Transaction>&>(*iter));
+ return true;
+ }
+
void add_to_read_set(CachedExtentRef ref) {
- if (is_weak()) return;
+ if (is_weak()) {
+ return;
+ }
assert(ref->is_valid());
auto it = ref->transactions.lower_bound(
this, read_set_item_t<Transaction>::trans_cmp_t());
- if (it != ref->transactions.end() && it->t == this) return;
+ assert(it == ref->transactions.end() || it->t != this);
auto [iter, inserted] = read_set.emplace(this, ref);
ceph_assert(inserted);