Skip to content

Commit 50d7036

Browse files
committed
crimson/os/seastore/cached_extent: rename get_transactional_view to
maybe_get_transactional_view It returns nullptr if the extent is not viewable by the transaction Signed-off-by: Xuehan Xu <[email protected]>
1 parent 02c012d commit 50d7036

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/crimson/os/seastore/cache.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,9 @@ class Cache : public ExtentTransViewRetriever,
517517
CachedExtentRef extent) final
518518
{
519519
assert(extent);
520-
return extent->get_transactional_view(t);
520+
auto ext = extent->maybe_get_transactional_view(t);
521+
ceph_assert(ext);
522+
return ext;
521523
}
522524

523525
get_extent_iertr::future<> maybe_wait_accessible(
@@ -611,7 +613,8 @@ class Cache : public ExtentTransViewRetriever,
611613
bool needs_step_2 = false;
612614
bool needs_touch = false;
613615
if (extent->is_stable()) {
614-
p_extent = extent->get_transactional_view(t);
616+
p_extent = extent->maybe_get_transactional_view(t);
617+
ceph_assert(p_extent);
615618
if (p_extent != extent.get()) {
616619
assert(!extent->is_pending_io());
617620
assert(p_extent->is_pending_in_trans(t.get_trans_id()));

src/crimson/os/seastore/cached_extent.cc

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,32 @@ CachedExtent::~CachedExtent()
7474
parent_index->erase(*this);
7575
}
7676
}
77-
CachedExtent* CachedExtent::get_transactional_view(Transaction &t) {
78-
return get_transactional_view(t.get_trans_id());
79-
}
77+
CachedExtent* CachedExtent::maybe_get_transactional_view(Transaction &t) {
78+
if (t.is_weak()) {
79+
return this;
80+
}
8081

81-
CachedExtent* CachedExtent::get_transactional_view(transaction_id_t tid) {
82-
auto it = mutation_pending_extents.find(tid, trans_spec_view_t::cmp_t());
83-
if (it != mutation_pending_extents.end()) {
84-
return (CachedExtent*)&(*it);
85-
} else {
82+
auto tid = t.get_trans_id();
83+
if (is_pending()) {
84+
ceph_assert(is_pending_in_trans(tid));
8685
return this;
8786
}
87+
88+
if (!mutation_pending_extents.empty()) {
89+
auto it = mutation_pending_extents.find(tid, trans_spec_view_t::cmp_t());
90+
if (it != mutation_pending_extents.end()) {
91+
return (CachedExtent*)&(*it);
92+
}
93+
}
94+
95+
if (!retired_transactions.empty()) {
96+
auto it = retired_transactions.find(tid, trans_spec_view_t::cmp_t());
97+
if (it != retired_transactions.end()) {
98+
return nullptr;
99+
}
100+
}
101+
102+
return this;
88103
}
89104

90105
std::ostream &LogicalCachedExtent::print_detail(std::ostream &out) const

src/crimson/os/seastore/cached_extent.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,7 @@ class CachedExtent
939939
}
940940
}
941941

942-
CachedExtent* get_transactional_view(Transaction &t);
943-
CachedExtent* get_transactional_view(transaction_id_t tid);
942+
CachedExtent* maybe_get_transactional_view(Transaction &t);
944943

945944
read_trans_set_t<Transaction> read_transactions;
946945

0 commit comments

Comments
 (0)