From 1cb13e87ab48c66dcf761ee8348464f9b18c0d5e Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Wed, 11 Dec 2024 15:57:53 +0800 Subject: [PATCH] crimson/os/seastore: unify omaptree interfaces Signed-off-by: Yingxin Cheng Signed-off-by: Myoungwon Oh --- src/crimson/os/seastore/seastore.cc | 145 ++++++++++++++-------------- src/crimson/os/seastore/seastore.h | 113 +++++++++++----------- 2 files changed, 132 insertions(+), 126 deletions(-) diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 940f195a062ac..cddaf2d7af683 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -1215,7 +1215,7 @@ SeaStore::Shard::readv( using crimson::os::seastore::omap_manager::BtreeOMapManager; -SeaStore::Shard::_omap_get_value_ret +SeaStore::Shard::omaptree_get_value_ret SeaStore::Shard::_get_attr( Transaction& t, Onode& onode, @@ -1236,7 +1236,7 @@ SeaStore::Shard::_get_attr( return seastar::make_ready_future(std::move(bl)); } DEBUGT("name={} ...", t, name); - return _omap_get_value(t, get_omap_root(omap_type_t::XATTR, onode), name); + return omaptree_get_value(t, get_omap_root(omap_type_t::XATTR, onode), name); } SeaStore::Shard::get_attr_errorator::future @@ -1276,8 +1276,8 @@ SeaStore::Shard::_get_attrs( LOG_PREFIX(SeaStoreS::_get_attrs); DEBUGT("...", t); auto& layout = onode.get_layout(); - return do_omap_get_values( - t, std::nullopt, get_omap_root(omap_type_t::XATTR, onode) + return omaptree_get_values( + t, get_omap_root(omap_type_t::XATTR, onode), std::nullopt ).si_then([&layout, &t, FNAME](auto p) { auto& attrs = std::get<1>(p); DEBUGT("got {} attrs, OI length=0x{:x}, SS length=0x{:x}", @@ -1410,15 +1410,16 @@ SeaStore::Shard::omap_get_values( { auto r = select_log_omap_root(onode); omap_root_t root = r.get(onode.get_metadata_hint(device->get_block_size())); - return _omap_get_values(t, std::move(root), keys); + return omaptree_get_values( + t, std::move(root), keys); }).finally([this] { assert(shard_stats.pending_read_num); --(shard_stats.pending_read_num); }); } -SeaStore::Shard::_omap_get_value_ret -SeaStore::Shard::_omap_get_value( +SeaStore::Shard::omaptree_get_value_ret +SeaStore::Shard::omaptree_get_value( Transaction& t, omap_root_t&& root, std::string_view key) const @@ -1427,15 +1428,15 @@ SeaStore::Shard::_omap_get_value( BtreeOMapManager(*transaction_manager), std::move(root), std::string(key), - [&t](auto &manager, auto& root, auto& key) -> _omap_get_value_ret + [&t](auto &manager, auto& root, auto& key) -> omaptree_get_value_ret { - LOG_PREFIX(SeaStoreS::_omap_get_value); + LOG_PREFIX(SeaStoreS::omaptree_get_value); if (root.is_null()) { DEBUGT("key={} is absent because of null root", t, key); return crimson::ct_error::enodata::make(); } return manager.omap_get_value(root, t, key - ).si_then([&key, &t, FNAME](auto opt) -> _omap_get_value_ret { + ).si_then([&key, &t, FNAME](auto opt) -> omaptree_get_value_ret { if (!opt) { DEBUGT("key={} is absent", t, key); return crimson::ct_error::enodata::make(); @@ -1447,12 +1448,12 @@ SeaStore::Shard::_omap_get_value( } SeaStore::base_iertr::future -SeaStore::Shard::_omap_get_values( +SeaStore::Shard::omaptree_get_values( Transaction& t, omap_root_t&& root, const omap_keys_t& keys) const { - LOG_PREFIX(SeaStoreS::_omap_get_values); + LOG_PREFIX(SeaStoreS::omaptree_get_values); if (root.is_null()) { DEBUGT("{} keys are absent because of null root", t, keys.size()); return seastar::make_ready_future(); @@ -1489,15 +1490,15 @@ SeaStore::Shard::_omap_get_values( }); } -SeaStore::Shard::omap_list_ret -SeaStore::Shard::omap_list( - omap_root_t&& root, +SeaStore::Shard::omaptree_list_ret +SeaStore::Shard::omaptree_list( Transaction& t, + omap_root_t&& root, const std::optional& start, OMapManager::omap_list_config_t config) const { if (root.is_null()) { - return seastar::make_ready_future( + return seastar::make_ready_future( true, omap_values_t{} ); } @@ -1513,18 +1514,18 @@ SeaStore::Shard::omap_list( } SeaStore::base_iertr::future -SeaStore::Shard::do_omap_get_values( +SeaStore::Shard::omaptree_get_values( Transaction& t, - const std::optional& start, - omap_root_t&& root) const + omap_root_t&& root, + const std::optional& start) const { - LOG_PREFIX(SeaStoreS::do_omap_get_values); + LOG_PREFIX(SeaStoreS::omaptree_get_values); DEBUGT("start={} type={} ...", t, start.has_value() ? *start : "", root.get_type()); auto config = OMapManager::omap_list_config_t() .with_inclusive(false, false) .without_max(); - return omap_list(std::move(root), t, start, config + return omaptree_list(t, std::move(root), start, config ).si_then([FNAME, &t](omap_values_paged_t ret) { DEBUGT("got {} values, complete={}", t, std::get<1>(ret).size(), std::get<0>(ret)); @@ -1553,8 +1554,8 @@ SeaStore::Shard::omap_get_values( { auto root = select_log_omap_root(onode).get( onode.get_metadata_hint(device->get_block_size())); - return do_omap_get_values( - t, start, std::move(root)); + return omaptree_get_values( + t, std::move(root), start); }).finally([this] { assert(shard_stats.pending_read_num); --(shard_stats.pending_read_num); @@ -1889,11 +1890,11 @@ SeaStore::Shard::_do_transaction_step( onode->get_metadata_hint(device->get_block_size())); DEBUGT("op OMAP_SETKEYS, oid={}, omap size={}, type={} ...", *ctx.transaction, oid, aset.size(), root.get_type()); - return _omap_set_values( + return omaptree_set_keys( *ctx.transaction, + std::move(root), *onode, - std::move(aset), - std::move(root)); + std::move(aset)); } case Transaction::OP_OMAP_SETHEADER: { @@ -1911,11 +1912,11 @@ SeaStore::Shard::_do_transaction_step( onode->get_metadata_hint(device->get_block_size())); DEBUGT("op OMAP_RMKEYS, oid={}, omap size={}, type={} ...", *ctx.transaction, oid, keys.size(), root.get_type()); - return _omap_rmkeys( + return omaptree_rm_keys( *ctx.transaction, + std::move(root), *onode, - std::move(keys), - std::move(root)); + std::move(keys)); } case Transaction::OP_OMAP_RMKEYRANGE: { @@ -1926,11 +1927,11 @@ SeaStore::Shard::_do_transaction_step( onode->get_metadata_hint(device->get_block_size())); DEBUGT("op OMAP_RMKEYRANGE, oid={}, first={}, last={}, type={}...", *ctx.transaction, oid, first, last, root.get_type()); - return _omap_rmkeyrange( + return omaptree_rm_keyrange( *ctx.transaction, + std::move(root), *onode, - std::move(first), std::move(last), - std::move(root)); + std::move(first), std::move(last)); } case Transaction::OP_OMAP_CLEAR: { @@ -2202,12 +2203,12 @@ SeaStore::Shard::_write( }); } -SeaStore::Shard::tm_ret -SeaStore::Shard::_clone_omaps( +SeaStore::base_iertr::future<> +SeaStore::Shard::omaptree_clone( Transaction& t, + omap_type_t type, Onode& onode, - Onode& d_onode, - const omap_type_t type) + Onode& d_onode) { return trans_intr::repeat([&t, &onode, &d_onode, this, type] { return seastar::do_with( @@ -2216,22 +2217,22 @@ SeaStore::Shard::_clone_omaps( { auto config = OMapManager::omap_list_config_t() .with_inclusive(false, false); - return omap_list(get_omap_root(type, onode), t, start, config + return omaptree_list(t, get_omap_root(type, onode), start, config ).si_then([&t, &d_onode, this, type, &start](auto p) { auto complete = std::get<0>(p); auto &attrs = std::get<1>(p); if (attrs.empty()) { assert(complete); - return tm_iertr::make_ready_future< + return base_iertr::make_ready_future< seastar::stop_iteration>( seastar::stop_iteration::yes); } std::string nstart = attrs.rbegin()->first; - return _omap_set_values( + return omaptree_set_keys( t, + get_omap_root(type, d_onode), d_onode, - std::map(attrs.begin(), attrs.end()), - get_omap_root(type, d_onode) + std::map(attrs.begin(), attrs.end()) ).si_then([complete, nstart=std::move(nstart), &start]() mutable { if (complete) { return seastar::make_ready_future< @@ -2268,14 +2269,14 @@ SeaStore::Shard::_clone( onode, &d_onode}); }).si_then([&ctx, &onode, &d_onode, this] { - return _clone_omaps( - *ctx.transaction, onode, d_onode, omap_type_t::XATTR); + return omaptree_clone( + *ctx.transaction, omap_type_t::XATTR, onode, d_onode); }).si_then([&ctx, &onode, &d_onode, this] { - return _clone_omaps( - *ctx.transaction, onode, d_onode, omap_type_t::OMAP); + return omaptree_clone( + *ctx.transaction, omap_type_t::OMAP, onode, d_onode); }).si_then([&ctx, &onode, &d_onode, this] { - return _clone_omaps( - *ctx.transaction, onode, d_onode, omap_type_t::LOG); + return omaptree_clone( + *ctx.transaction, omap_type_t::LOG, onode, d_onode); }); } @@ -2310,12 +2311,12 @@ SeaStore::Shard::_zero( }); } -SeaStore::Shard::tm_ret -SeaStore::Shard::_omap_set_values( +SeaStore::base_iertr::future<> +SeaStore::Shard::omaptree_set_keys( Transaction& t, + omap_root_t&& root, Onode& onode, - std::map &&kvs, - omap_root_t&& root) + std::map&& kvs) { return seastar::do_with( BtreeOMapManager(*transaction_manager), @@ -2324,7 +2325,7 @@ SeaStore::Shard::_omap_set_values( (auto &omap_manager, auto &root) mutable { assert(root.get_type() < omap_type_t::NONE); - tm_iertr::future<> maybe_create_root = tm_iertr::now(); + base_iertr::future<> maybe_create_root = base_iertr::now(); if (root.is_null()) { maybe_create_root = omap_manager.initialize_omap(t, onode.get_metadata_hint(device->get_block_size()), @@ -2338,7 +2339,7 @@ SeaStore::Shard::_omap_set_values( ).si_then([&t, &root, &omap_manager, kvs=std::move(kvs)]() mutable { return omap_manager.omap_set_keys(root, t, std::move(kvs)); }).si_then([&root] { - return tm_iertr::make_ready_future(std::move(root)); + return base_iertr::make_ready_future(std::move(root)); }); }).si_then([&onode, &t](auto root) { if (root.must_update()) { @@ -2363,7 +2364,7 @@ SeaStore::Shard::_omap_clear( internal_context_t &ctx, Onode &onode) { - return _xattr_rmattr( + return omaptree_rm_key( *ctx.transaction, get_omap_root(omap_type_t::XATTR, onode), onode, @@ -2376,12 +2377,12 @@ SeaStore::Shard::_omap_clear( }); } -SeaStore::Shard::tm_ret -SeaStore::Shard::_omap_rmkeys( - Transaction &t, +SeaStore::base_iertr::future<> +SeaStore::Shard::omaptree_rm_keys( + Transaction& t, + omap_root_t&& root, Onode& onode, - omap_keys_t &&keys, - omap_root_t&& root) + omap_keys_t&& keys) { if (root.is_null()) { return seastar::now(); @@ -2407,13 +2408,13 @@ SeaStore::Shard::_omap_rmkeys( }); } -SeaStore::Shard::tm_ret -SeaStore::Shard::_omap_rmkeyrange( +SeaStore::base_iertr::future<> +SeaStore::Shard::omaptree_rm_keyrange( Transaction& t, + omap_root_t&& root, Onode& onode, std::string first, - std::string last, - omap_root_t &&root) + std::string last) { if (first > last) { LOG_PREFIX(SeaStoreS::_omap_rmkeyrange); @@ -2480,7 +2481,7 @@ SeaStore::Shard::_setattrs( if (!layout.oi_size) { // if oi was not in the layout, it probably exists in the omap, // need to remove it first - fut = _xattr_rmattr( + fut = omaptree_rm_key( *ctx.transaction, get_omap_root(omap_type_t::XATTR, onode), onode, @@ -2499,7 +2500,7 @@ SeaStore::Shard::_setattrs( if (likely(val.length() <= onode_layout_t::MAX_SS_LENGTH)) { if (!layout.ss_size) { - fut = _xattr_rmattr( + fut = omaptree_rm_key( *ctx.transaction, get_omap_root(omap_type_t::XATTR, onode), onode, @@ -2521,11 +2522,11 @@ SeaStore::Shard::_setattrs( DEBUGT("set attrs in omap", *ctx.transaction); return std::move(fut ).si_then([this, &onode, &ctx, aset=std::move(aset)]() mutable { - return _omap_set_values( + return omaptree_set_keys( *ctx.transaction, + get_omap_root(omap_type_t::XATTR, onode), onode, - std::move(aset), - get_omap_root(omap_type_t::XATTR, onode)); + std::move(aset)); }); } @@ -2543,7 +2544,7 @@ SeaStore::Shard::_rmattr( onode.clear_snapset(*ctx.transaction); return tm_iertr::now(); } else { - return _xattr_rmattr( + return omaptree_rm_key( *ctx.transaction, get_omap_root(omap_type_t::XATTR, onode), onode, @@ -2551,12 +2552,12 @@ SeaStore::Shard::_rmattr( } } -SeaStore::Shard::tm_ret -SeaStore::Shard::_xattr_rmattr( +SeaStore::base_iertr::future<> +SeaStore::Shard::omaptree_rm_key( Transaction& t, omap_root_t&& root, Onode& onode, - std::string &&name) + std::string&& name) { if (root.is_null()) { return base_iertr::now(); diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index 3a9bd38777902..d6a2e5c0315ab 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -348,28 +348,6 @@ public: }); } - using omap_list_bare_ret = OMapManager::omap_list_bare_ret; - using omap_list_ret = OMapManager::omap_list_ret; - omap_list_ret omap_list( - omap_root_t&& omap_root, - Transaction& t, - const std::optional& start, - OMapManager::omap_list_config_t config) const; - - using _omap_get_value_iertr = base_iertr::extend< - crimson::ct_error::enodata - >; - using _omap_get_value_ret = _omap_get_value_iertr::future; - _omap_get_value_ret _omap_get_value( - Transaction &t, - omap_root_t &&root, - std::string_view key) const; - - base_iertr::future _omap_get_values( - Transaction &t, - omap_root_t &&root, - const omap_keys_t &keys) const; - friend class SeaStoreOmapIterator; base_iertr::future _read( @@ -379,7 +357,11 @@ public: std::size_t len, uint32_t op_flags); - _omap_get_value_ret _get_attr( + using omaptree_get_value_iertr = base_iertr::extend< + crimson::ct_error::enodata + >; + using omaptree_get_value_ret = omaptree_get_value_iertr::future; + omaptree_get_value_ret _get_attr( Transaction& t, Onode& onode, std::string_view name) const; @@ -393,11 +375,6 @@ public: Onode& onode, const ghobject_t& oid); - base_iertr::future do_omap_get_values( - Transaction& t, - const std::optional& start, - omap_root_t&& omap_root) const; - base_iertr::future _fiemap( Transaction &t, Onode &onode, @@ -424,11 +401,6 @@ public: uint64_t offset, size_t len, ceph::bufferlist &&bl, uint32_t fadvise_flags); - tm_ret _clone_omaps( - Transaction &t, - Onode &onode, - Onode &d_onode, - const omap_type_t otype); tm_ret _clone( internal_context_t &ctx, Onode &onode, @@ -441,11 +413,6 @@ public: internal_context_t &ctx, Onode &onode, objaddr_t offset, extent_len_t len); - tm_ret _omap_set_values( - Transaction &t, - Onode &onode, - std::map &&aset, - omap_root_t&& omap_root); tm_ret _omap_set_header( internal_context_t &ctx, Onode &onode, @@ -453,17 +420,6 @@ public: tm_ret _omap_clear( internal_context_t &ctx, Onode &onode); - tm_ret _omap_rmkeys( - Transaction &t, - Onode &onode, - omap_keys_t &&aset, - omap_root_t &&_omap_root); - tm_ret _omap_rmkeyrange( - Transaction &t, - Onode &onode, - std::string first, - std::string last, - omap_root_t &&_omap_root); tm_ret _truncate( internal_context_t &ctx, Onode &onode, uint64_t size); @@ -478,11 +434,6 @@ public: tm_ret _rmattrs( internal_context_t &ctx, Onode &onode); - tm_ret _xattr_rmattr( - Transaction &t, - omap_root_t&& root, - Onode &onode, - std::string &&name); tm_ret _create_collection( internal_context_t &ctx, const coll_t& cid, int bits); @@ -519,6 +470,60 @@ public: return onode.get_root(type, device->get_block_size()); } + omaptree_get_value_ret omaptree_get_value( + Transaction& t, + omap_root_t&& root, + std::string_view key) const; + + using omaptree_list_bare_ret = OMapManager::omap_list_bare_ret; + using omaptree_list_ret = OMapManager::omap_list_ret; + omaptree_list_ret omaptree_list( + Transaction& t, + omap_root_t&& root, + const std::optional& start, + OMapManager::omap_list_config_t config) const; + + base_iertr::future omaptree_get_values( + Transaction& t, + omap_root_t&& root, + const omap_keys_t& keys) const; + + base_iertr::future omaptree_get_values( + Transaction& t, + omap_root_t&& root, + const std::optional& start) const; + + base_iertr::future<> omaptree_set_keys( + Transaction& t, + omap_root_t&& root, + Onode& onode, + std::map&& aset); + + base_iertr::future<> omaptree_rm_key( + Transaction& t, + omap_root_t&& root, + Onode& onode, + std::string&& name); + + base_iertr::future<> omaptree_rm_keys( + Transaction& t, + omap_root_t&& root, + Onode& onode, + omap_keys_t&& aset); + + base_iertr::future<> omaptree_rm_keyrange( + Transaction& t, + omap_root_t&& root, + Onode& onode, + std::string first, + std::string last); + + base_iertr::future<> omaptree_clone( + Transaction& t, + omap_type_t type, + Onode& onode, + Onode& d_onode); + base_iertr::future omaptree_do_clear( Transaction& t, omap_root_t&& root); -- 2.39.5