From b738fede07422680a36aadf212a6f7f4c73039e1 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Thu, 25 Aug 2022 21:11:31 +0800 Subject: [PATCH] crimson/os/seastore/async_cleaner: move ExtentCallbackInterface out of the class Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/async_cleaner.h | 252 +++++++++--------- .../os/seastore/extent_placement_manager.h | 2 +- src/crimson/os/seastore/transaction_manager.h | 40 +-- 3 files changed, 149 insertions(+), 145 deletions(-) diff --git a/src/crimson/os/seastore/async_cleaner.h b/src/crimson/os/seastore/async_cleaner.h index a44eb709e0c3f..b7965b5b6c5ab 100644 --- a/src/crimson/os/seastore/async_cleaner.h +++ b/src/crimson/os/seastore/async_cleaner.h @@ -265,6 +265,133 @@ private: std::ostream &operator<<(std::ostream &, const segments_info_t &); +/** + * Callback interface for querying extents and operating on transactions. + */ +class ExtentCallbackInterface { +public: + virtual ~ExtentCallbackInterface() = default; + + /// Creates empty transaction + /// weak transaction should be type READ + virtual TransactionRef create_transaction( + Transaction::src_t, const char *name, bool is_weak=false) = 0; + + /// Creates empty transaction with interruptible context + template + auto with_transaction_intr( + Transaction::src_t src, + const char* name, + Func &&f) { + return do_with_transaction_intr( + src, name, std::forward(f)); + } + + template + auto with_transaction_weak( + const char* name, + Func &&f) { + return do_with_transaction_intr( + Transaction::src_t::READ, name, std::forward(f) + ).handle_error( + crimson::ct_error::eagain::handle([] { + ceph_assert(0 == "eagain impossible"); + }), + crimson::ct_error::pass_further_all{} + ); + } + + /// See Cache::get_next_dirty_extents + using get_next_dirty_extents_iertr = trans_iertr< + crimson::errorator< + crimson::ct_error::input_output_error> + >; + using get_next_dirty_extents_ret = get_next_dirty_extents_iertr::future< + std::vector>; + virtual get_next_dirty_extents_ret get_next_dirty_extents( + Transaction &t, ///< [in] current transaction + journal_seq_t bound,///< [in] return extents with dirty_from < bound + size_t max_bytes ///< [in] return up to max_bytes of extents + ) = 0; + + using extent_mapping_ertr = crimson::errorator< + crimson::ct_error::input_output_error, + crimson::ct_error::eagain>; + using extent_mapping_iertr = trans_iertr< + crimson::errorator< + crimson::ct_error::input_output_error> + >; + + /** + * rewrite_extent + * + * Updates t with operations moving the passed extents to a new + * segment. extent may be invalid, implementation must correctly + * handle finding the current instance if it is still alive and + * otherwise ignore it. + */ + using rewrite_extent_iertr = extent_mapping_iertr; + using rewrite_extent_ret = rewrite_extent_iertr::future<>; + virtual rewrite_extent_ret rewrite_extent( + Transaction &t, + CachedExtentRef extent, + reclaim_gen_t target_generation, + sea_time_point modify_time) = 0; + + /** + * get_extent_if_live + * + * Returns extent at specified location if still referenced by + * lba_manager and not removed by t. + * + * See TransactionManager::get_extent_if_live and + * LBAManager::get_physical_extent_if_live. + */ + using get_extents_if_live_iertr = extent_mapping_iertr; + using get_extents_if_live_ret = get_extents_if_live_iertr::future< + std::list>; + virtual get_extents_if_live_ret get_extents_if_live( + Transaction &t, + extent_types_t type, + paddr_t addr, + laddr_t laddr, + seastore_off_t len) = 0; + + /** + * submit_transaction_direct + * + * Submits transaction without any space throttling. + */ + using submit_transaction_direct_iertr = trans_iertr< + crimson::errorator< + crimson::ct_error::input_output_error> + >; + using submit_transaction_direct_ret = + submit_transaction_direct_iertr::future<>; + virtual submit_transaction_direct_ret submit_transaction_direct( + Transaction &t, + std::optional seq_to_trim = std::nullopt) = 0; + +private: + template + auto do_with_transaction_intr( + Transaction::src_t src, + const char* name, + Func &&f) { + return seastar::do_with( + create_transaction(src, name, IsWeak), + [f=std::forward(f)](auto &ref_t) mutable { + return with_trans_intr( + *ref_t, + [f=std::forward(f)](auto& t) mutable { + return f(t); + } + ); + } + ); + } +}; + /** * Callback interface for journal trimming */ @@ -633,131 +760,6 @@ public: } }; - /// Callback interface for querying and operating on segments - class ExtentCallbackInterface { - public: - virtual ~ExtentCallbackInterface() = default; - - /// Creates empty transaction - /// weak transaction should be type READ - virtual TransactionRef create_transaction( - Transaction::src_t, const char *name, bool is_weak=false) = 0; - - /// Creates empty transaction with interruptible context - template - auto with_transaction_intr( - Transaction::src_t src, - const char* name, - Func &&f) { - return do_with_transaction_intr( - src, name, std::forward(f)); - } - - template - auto with_transaction_weak( - const char* name, - Func &&f) { - return do_with_transaction_intr( - Transaction::src_t::READ, name, std::forward(f) - ).handle_error( - crimson::ct_error::eagain::handle([] { - ceph_assert(0 == "eagain impossible"); - }), - crimson::ct_error::pass_further_all{} - ); - } - - /// See Cache::get_next_dirty_extents - using get_next_dirty_extents_iertr = trans_iertr< - crimson::errorator< - crimson::ct_error::input_output_error> - >; - using get_next_dirty_extents_ret = get_next_dirty_extents_iertr::future< - std::vector>; - virtual get_next_dirty_extents_ret get_next_dirty_extents( - Transaction &t, ///< [in] current transaction - journal_seq_t bound,///< [in] return extents with dirty_from < bound - size_t max_bytes ///< [in] return up to max_bytes of extents - ) = 0; - - using extent_mapping_ertr = crimson::errorator< - crimson::ct_error::input_output_error, - crimson::ct_error::eagain>; - using extent_mapping_iertr = trans_iertr< - crimson::errorator< - crimson::ct_error::input_output_error> - >; - - /** - * rewrite_extent - * - * Updates t with operations moving the passed extents to a new - * segment. extent may be invalid, implementation must correctly - * handle finding the current instance if it is still alive and - * otherwise ignore it. - */ - using rewrite_extent_iertr = extent_mapping_iertr; - using rewrite_extent_ret = rewrite_extent_iertr::future<>; - virtual rewrite_extent_ret rewrite_extent( - Transaction &t, - CachedExtentRef extent, - reclaim_gen_t target_generation, - sea_time_point modify_time) = 0; - - /** - * get_extent_if_live - * - * Returns extent at specified location if still referenced by - * lba_manager and not removed by t. - * - * See TransactionManager::get_extent_if_live and - * LBAManager::get_physical_extent_if_live. - */ - using get_extents_if_live_iertr = extent_mapping_iertr; - using get_extents_if_live_ret = get_extents_if_live_iertr::future< - std::list>; - virtual get_extents_if_live_ret get_extents_if_live( - Transaction &t, - extent_types_t type, - paddr_t addr, - laddr_t laddr, - seastore_off_t len) = 0; - - /** - * submit_transaction_direct - * - * Submits transaction without any space throttling. - */ - using submit_transaction_direct_iertr = trans_iertr< - crimson::errorator< - crimson::ct_error::input_output_error> - >; - using submit_transaction_direct_ret = - submit_transaction_direct_iertr::future<>; - virtual submit_transaction_direct_ret submit_transaction_direct( - Transaction &t, - std::optional seq_to_trim = std::nullopt) = 0; - - private: - template - auto do_with_transaction_intr( - Transaction::src_t src, - const char* name, - Func &&f) { - return seastar::do_with( - create_transaction(src, name, IsWeak), - [f=std::forward(f)](auto &ref_t) mutable { - return with_trans_intr( - *ref_t, - [f=std::forward(f)](auto& t) mutable { - return f(t); - } - ); - } - ); - } - }; - private: const bool detailed; const config_t config; diff --git a/src/crimson/os/seastore/extent_placement_manager.h b/src/crimson/os/seastore/extent_placement_manager.h index 60b3e2476db94..db29a714e5da9 100644 --- a/src/crimson/os/seastore/extent_placement_manager.h +++ b/src/crimson/os/seastore/extent_placement_manager.h @@ -94,7 +94,7 @@ public: void set_primary_device(Device *device); - void set_extent_callback(AsyncCleaner::ExtentCallbackInterface *cb) { + void set_extent_callback(ExtentCallbackInterface *cb) { cleaner->set_extent_callback(cb); } diff --git a/src/crimson/os/seastore/transaction_manager.h b/src/crimson/os/seastore/transaction_manager.h index 61fe024788db9..18cf0aed644c6 100644 --- a/src/crimson/os/seastore/transaction_manager.h +++ b/src/crimson/os/seastore/transaction_manager.h @@ -58,7 +58,7 @@ auto repeat_eagain(F &&f) { * Abstraction hiding reading and writing to persistence. * Exposes transaction based interface with read isolation. */ -class TransactionManager : public AsyncCleaner::ExtentCallbackInterface { +class TransactionManager : public ExtentCallbackInterface { public: using base_ertr = Cache::base_ertr; using base_iertr = Cache::base_iertr; @@ -82,15 +82,6 @@ public: using close_ertr = base_ertr; close_ertr::future<> close(); - /// Creates empty transaction - /// weak transaction should be type READ - TransactionRef create_transaction( - Transaction::src_t src, - const char* name, - bool is_weak=false) final { - return cache->create_transaction(src, name, is_weak); - } - /// Resets transaction void reset_transaction_preserve_handle(Transaction &t) { return cache->reset_transaction_preserve_handle(t); @@ -462,12 +453,6 @@ public: using submit_transaction_iertr = base_iertr; submit_transaction_iertr::future<> submit_transaction(Transaction &); - /// AsyncCleaner::ExtentCallbackInterface - using AsyncCleaner::ExtentCallbackInterface::submit_transaction_direct_ret; - submit_transaction_direct_ret submit_transaction_direct( - Transaction &t, - std::optional seq_to_trim = std::nullopt) final; - /** * flush * @@ -477,20 +462,37 @@ public: */ seastar::future<> flush(OrderingHandle &handle); - using AsyncCleaner::ExtentCallbackInterface::get_next_dirty_extents_ret; + /* + * ExtentCallbackInterface + */ + + /// weak transaction should be type READ + TransactionRef create_transaction( + Transaction::src_t src, + const char* name, + bool is_weak=false) final { + return cache->create_transaction(src, name, is_weak); + } + + using ExtentCallbackInterface::submit_transaction_direct_ret; + submit_transaction_direct_ret submit_transaction_direct( + Transaction &t, + std::optional seq_to_trim = std::nullopt) final; + + using ExtentCallbackInterface::get_next_dirty_extents_ret; get_next_dirty_extents_ret get_next_dirty_extents( Transaction &t, journal_seq_t seq, size_t max_bytes) final; - using AsyncCleaner::ExtentCallbackInterface::rewrite_extent_ret; + using ExtentCallbackInterface::rewrite_extent_ret; rewrite_extent_ret rewrite_extent( Transaction &t, CachedExtentRef extent, reclaim_gen_t target_generation, sea_time_point modify_time) final; - using AsyncCleaner::ExtentCallbackInterface::get_extents_if_live_ret; + using ExtentCallbackInterface::get_extents_if_live_ret; get_extents_if_live_ret get_extents_if_live( Transaction &t, extent_types_t type, -- 2.39.5