From 1e711d8d8399f8cfceb5ae1773ccb0cff8ab9fe2 Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Tue, 16 Aug 2022 17:05:52 +0800 Subject: [PATCH] crimson/os/seastore/cached_extent: add on_invalidated interface Signed-off-by: Xuehan Xu (cherry picked from commit e5aabe6c306061b2ce3aff5ca30a9049c1a7f9bf) --- src/crimson/os/seastore/cache.cc | 4 ++-- src/crimson/os/seastore/cached_extent.cc | 8 ++++++++ src/crimson/os/seastore/cached_extent.h | 12 ++++++++++++ src/crimson/os/seastore/transaction.h | 8 ++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index ebeb123cf5e..f0c02b08b12 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -812,7 +812,7 @@ void Cache::invalidate_extent( { if (!extent.may_conflict()) { assert(extent.transactions.empty()); - extent.state = CachedExtent::extent_state_t::INVALID; + extent.set_invalid(t); return; } @@ -829,7 +829,7 @@ void Cache::invalidate_extent( mark_transaction_conflicted(*i.t, extent); } } - extent.state = CachedExtent::extent_state_t::INVALID; + extent.set_invalid(t); } void Cache::mark_transaction_conflicted( diff --git a/src/crimson/os/seastore/cached_extent.cc b/src/crimson/os/seastore/cached_extent.cc index 84f5f89c99b..c8447534451 100644 --- a/src/crimson/os/seastore/cached_extent.cc +++ b/src/crimson/os/seastore/cached_extent.cc @@ -90,6 +90,14 @@ std::ostream &LogicalCachedExtent::print_detail(std::ostream &out) const return print_detail_l(out); } +void CachedExtent::set_invalid(Transaction &t) { + state = extent_state_t::INVALID; + if (trans_view_hook.is_linked()) { + trans_view_hook.unlink(); + } + on_invalidated(t); +} + std::ostream &operator<<(std::ostream &out, const LBAPin &rhs) { return out << "LBAPin(" << rhs.get_key() << "~" << rhs.get_length() diff --git a/src/crimson/os/seastore/cached_extent.h b/src/crimson/os/seastore/cached_extent.h index 02450449551..4603d5a2cd8 100644 --- a/src/crimson/os/seastore/cached_extent.h +++ b/src/crimson/os/seastore/cached_extent.h @@ -242,6 +242,16 @@ public: * completes. */ virtual void on_replace_prior(Transaction &t) {} + + /** + * on_invalidated + * + * Called after the extent is invalidated, either by Cache::invalidate_extent + * or Transaction::add_to_retired_set. Implementation may use this + * call to adjust states that must be changed immediately once + * invalidated. + */ + virtual void on_invalidated(Transaction &t) {} /** * get_type * @@ -489,6 +499,8 @@ public: return ret; } + void set_invalid(Transaction &t); + private: template friend class read_set_item_t; diff --git a/src/crimson/os/seastore/transaction.h b/src/crimson/os/seastore/transaction.h index e7eef11427a..14ba61cee07 100644 --- a/src/crimson/os/seastore/transaction.h +++ b/src/crimson/os/seastore/transaction.h @@ -117,13 +117,13 @@ public: if (ref->is_exist_clean() || ref->is_exist_mutation_pending()) { existing_block_stats.dec(ref); - ref->state = CachedExtent::extent_state_t::INVALID; + ref->set_invalid(*this); write_set.erase(*ref); } else if (ref->is_initial_pending()) { - ref->state = CachedExtent::extent_state_t::INVALID; + ref->set_invalid(*this); write_set.erase(*ref); } else if (ref->is_mutation_pending()) { - ref->state = CachedExtent::extent_state_t::INVALID; + ref->set_invalid(*this); write_set.erase(*ref); assert(ref->prior_instance); retired_set.insert(ref->prior_instance); @@ -348,7 +348,7 @@ public: void invalidate_clear_write_set() { for (auto &&i: write_set) { - i.state = CachedExtent::extent_state_t::INVALID; + i.set_invalid(*this); } write_set.clear(); } -- 2.39.5