diff options
author | Yingxin Cheng <yingxin.cheng@intel.com> | 2024-09-10 05:52:56 +0200 |
---|---|---|
committer | Yingxin Cheng <yingxin.cheng@intel.com> | 2024-10-08 04:34:43 +0200 |
commit | 1ee32107df9c641908bc0b908be47f1d5af3bf63 (patch) | |
tree | 88604f87ef52d09e33eb56471a884bb8daaad6f3 /src/crimson/os | |
parent | crimson/os/seastore: workaround log linkage issue under clang14 (diff) | |
download | ceph-1ee32107df9c641908bc0b908be47f1d5af3bf63.tar.xz ceph-1ee32107df9c641908bc0b908be47f1d5af3bf63.zip |
crimson/os/seastore/transaction_manager: misc cleanups
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
Diffstat (limited to 'src/crimson/os')
-rw-r--r-- | src/crimson/os/seastore/transaction_manager.cc | 44 | ||||
-rw-r--r-- | src/crimson/os/seastore/transaction_manager.h | 112 |
2 files changed, 74 insertions, 82 deletions
diff --git a/src/crimson/os/seastore/transaction_manager.cc b/src/crimson/os/seastore/transaction_manager.cc index a76b7fbe0c9..0fd23ef6afb 100644 --- a/src/crimson/os/seastore/transaction_manager.cc +++ b/src/crimson/os/seastore/transaction_manager.cc @@ -98,7 +98,8 @@ TransactionManager::mkfs_ertr::future<> TransactionManager::mkfs() }); } -TransactionManager::mount_ertr::future<> TransactionManager::mount() +TransactionManager::mount_ertr::future<> +TransactionManager::mount() { LOG_PREFIX(TransactionManager::mount); INFO("enter"); @@ -175,7 +176,8 @@ TransactionManager::mount_ertr::future<> TransactionManager::mount() ); } -TransactionManager::close_ertr::future<> TransactionManager::close() { +TransactionManager::close_ertr::future<> +TransactionManager::close() { LOG_PREFIX(TransactionManager::close); INFO("enter"); return epm->stop_background( @@ -241,11 +243,11 @@ TransactionManager::ref_ret TransactionManager::remove( }); } -TransactionManager::ref_ret TransactionManager::_dec_ref( +TransactionManager::ref_ret TransactionManager::remove( Transaction &t, laddr_t offset) { - LOG_PREFIX(TransactionManager::_dec_ref); + LOG_PREFIX(TransactionManager::remove); TRACET("{}", t, offset); return lba_manager->decref_extent(t, offset ).si_then([this, FNAME, offset, &t](auto result) -> ref_ret { @@ -273,17 +275,18 @@ TransactionManager::refs_ret TransactionManager::remove( LOG_PREFIX(TransactionManager::remove); DEBUG("{} offsets", offsets.size()); return seastar::do_with(std::move(offsets), std::vector<unsigned>(), - [this, &t] (auto &&offsets, auto &refcnt) { - return trans_intr::do_for_each(offsets.begin(), offsets.end(), - [this, &t, &refcnt] (auto &laddr) { - return this->remove(t, laddr).si_then([&refcnt] (auto ref) { - refcnt.push_back(ref); - return ref_iertr::now(); - }); - }).si_then([&refcnt] { - return ref_iertr::make_ready_future<std::vector<unsigned>>(std::move(refcnt)); + [this, &t](auto &&offsets, auto &refcnts) { + return trans_intr::do_for_each(offsets.begin(), offsets.end(), + [this, &t, &refcnts](auto &laddr) { + return this->remove(t, laddr + ).si_then([&refcnts](auto ref) { + refcnts.push_back(ref); + return ref_iertr::now(); }); + }).si_then([&refcnts] { + return ref_iertr::make_ready_future<std::vector<unsigned>>(std::move(refcnts)); }); + }); } TransactionManager::submit_transaction_iertr::future<> @@ -340,6 +343,7 @@ TransactionManager::update_lba_mappings( return; } if (extent->is_logical()) { + assert(is_logical_type(extent->get_type())); // for rewritten extents, last_committed_crc should have been set // because the crc of the original extent may be reused. // also see rewrite_logical_extent() @@ -359,6 +363,7 @@ TransactionManager::update_lba_mappings( #endif lextents.emplace_back(extent->template cast<LogicalCachedExtent>()); } else { + assert(is_physical_type(extent->get_type())); pextents.emplace_back(extent); } }; @@ -566,7 +571,8 @@ TransactionManager::rewrite_logical_extent( 0, lextent->get_length(), extent_ref_count_t(0), - [this, lextent, &t](auto &extents, auto &off, auto &left, auto &refcount) { + [this, lextent, &t] + (auto &extents, auto &off, auto &left, auto &refcount) { return trans_intr::do_for_each( extents, [lextent, this, &t, &off, &left, &refcount](auto &nextent) { @@ -665,11 +671,6 @@ TransactionManager::rewrite_extent_ret TransactionManager::rewrite_extent( t.get_rewrite_stats().account_n_dirty(); } - if (is_backref_node(extent->get_type())) { - DEBUGT("rewriting backref extent -- {}", t, *extent); - return backref_manager->rewrite_extent(t, extent); - } - if (is_root_type(extent->get_type())) { DEBUGT("rewriting root extent -- {}", t, *extent); cache->duplicate_for_write(t, extent); @@ -677,8 +678,13 @@ TransactionManager::rewrite_extent_ret TransactionManager::rewrite_extent( } if (extent->is_logical()) { + assert(is_logical_type(extent->get_type())); return rewrite_logical_extent(t, extent->cast<LogicalCachedExtent>()); + } else if (is_backref_node(extent->get_type())) { + DEBUGT("rewriting backref extent -- {}", t, *extent); + return backref_manager->rewrite_extent(t, extent); } else { + assert(is_lba_node(extent->get_type())); DEBUGT("rewriting physical extent -- {}", t, *extent); return lba_manager->rewrite_extent(t, extent); } diff --git a/src/crimson/os/seastore/transaction_manager.h b/src/crimson/os/seastore/transaction_manager.h index 828b8a25592..6d1b010ab69 100644 --- a/src/crimson/os/seastore/transaction_manager.h +++ b/src/crimson/os/seastore/transaction_manager.h @@ -215,49 +215,6 @@ public: }); } - template <typename T> - std::variant<LBAMappingRef, base_iertr::future<TCachedExtentRef<T>>> - get_extent_if_linked( - Transaction &t, - LBAMappingRef pin) - { - ceph_assert(pin->is_parent_viewable()); - // checking the lba child must be atomic with creating - // and linking the absent child - auto v = pin->get_logical_extent(t); - if (v.has_child()) { - return v.get_child_fut().safe_then([pin=std::move(pin)](auto extent) { -#ifndef NDEBUG - auto lextent = extent->template cast<LogicalCachedExtent>(); - auto pin_laddr = pin->get_key(); - if (pin->is_indirect()) { - pin_laddr = pin->get_intermediate_base(); - } - assert(lextent->get_laddr() == pin_laddr); -#endif - return extent->template cast<T>(); - }); - } else { - return pin; - } - } - - base_iertr::future<LogicalCachedExtentRef> read_pin_by_type( - Transaction &t, - LBAMappingRef pin, - extent_types_t type) - { - ceph_assert(!pin->parent_modified()); - auto v = pin->get_logical_extent(t); - // checking the lba child must be atomic with creating - // and linking the absent child - if (v.has_child()) { - return std::move(v.get_child_fut()); - } else { - return pin_to_extent_by_type(t, std::move(pin), type); - } - } - /// Obtain mutable copy of extent LogicalCachedExtentRef get_mutable_extent(Transaction &t, LogicalCachedExtentRef ref) { LOG_PREFIX(TransactionManager::get_mutable_extent); @@ -282,7 +239,6 @@ public: return ret; } - using ref_iertr = LBAManager::ref_iertr; using ref_ret = ref_iertr::future<extent_ref_count_t>; @@ -302,26 +258,15 @@ public: * remove * * Remove the extent and the corresponding lba mapping, - * users must make sure that lba mapping's refcount is 1 + * users must make sure that lba mapping's refcount > 1 */ ref_ret remove( Transaction &t, LogicalCachedExtentRef &ref); - /** - * remove - * - * 1. Remove the indirect mapping(s), and if refcount drops to 0, - * also remove the direct mapping and retire the extent. - * - * 2. Remove the direct mapping(s) and retire the extent if - * refcount drops to 0. - */ ref_ret remove( Transaction &t, - laddr_t offset) { - return _dec_ref(t, offset); - } + laddr_t offset); /// remove refcount for list of offset using refs_ret = ref_iertr::future<std::vector<unsigned>>; @@ -411,7 +356,10 @@ public: } template <typename T> - read_extent_ret<T> get_mutable_extent_by_laddr(Transaction &t, laddr_t laddr, extent_len_t len) { + read_extent_ret<T> get_mutable_extent_by_laddr( + Transaction &t, + laddr_t laddr, + extent_len_t len) { return get_pin(t, laddr ).si_then([this, &t, len](auto pin) { ceph_assert(pin->is_data_stable() && !pin->is_zero_reserved()); @@ -853,6 +801,49 @@ private: shard_stats_t& shard_stats; + template <typename T> + std::variant<LBAMappingRef, base_iertr::future<TCachedExtentRef<T>>> + get_extent_if_linked( + Transaction &t, + LBAMappingRef pin) + { + ceph_assert(pin->is_parent_viewable()); + // checking the lba child must be atomic with creating + // and linking the absent child + auto v = pin->get_logical_extent(t); + if (v.has_child()) { + return v.get_child_fut().safe_then([pin=std::move(pin)](auto extent) { +#ifndef NDEBUG + auto lextent = extent->template cast<LogicalCachedExtent>(); + auto pin_laddr = pin->get_key(); + if (pin->is_indirect()) { + pin_laddr = pin->get_intermediate_base(); + } + assert(lextent->get_laddr() == pin_laddr); +#endif + return extent->template cast<T>(); + }); + } else { + return pin; + } + } + + base_iertr::future<LogicalCachedExtentRef> read_pin_by_type( + Transaction &t, + LBAMappingRef pin, + extent_types_t type) + { + ceph_assert(!pin->parent_modified()); + auto v = pin->get_logical_extent(t); + // checking the lba child must be atomic with creating + // and linking the absent child + if (v.has_child()) { + return std::move(v.get_child_fut()); + } else { + return pin_to_extent_by_type(t, std::move(pin), type); + } + } + rewrite_extent_ret rewrite_logical_extent( Transaction& t, LogicalCachedExtentRef extent); @@ -862,11 +853,6 @@ private: ExtentPlacementManager::dispatch_result_t dispatch_result, std::optional<journal_seq_t> seq_to_trim = std::nullopt); - /// Remove refcount for offset - ref_ret _dec_ref( - Transaction &t, - laddr_t offset); - using update_lba_mappings_ret = LBAManager::update_mappings_ret; update_lba_mappings_ret update_lba_mappings( Transaction &t, |