From c73df59c1d3aac5a23464c0493490faf9ca607f3 Mon Sep 17 00:00:00 2001 From: chunmei-liu Date: Tue, 26 Apr 2022 01:53:46 -0700 Subject: [PATCH] crimson/seastore: add OMAP_GET/SET_HEADER Signed-off-by: chunmei-liu --- src/crimson/os/alienstore/alien_store.cc | 10 ++-- src/crimson/os/alienstore/alien_store.h | 2 +- src/crimson/os/cyanstore/cyan_store.cc | 4 +- src/crimson/os/cyanstore/cyan_store.h | 2 +- src/crimson/os/futurized_store.h | 2 +- src/crimson/os/seastore/seastore.cc | 59 +++++++++++++----------- src/crimson/os/seastore/seastore.h | 2 +- src/crimson/os/seastore/seastore_types.h | 3 ++ src/crimson/osd/pg_backend.cc | 8 +++- 9 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/crimson/os/alienstore/alien_store.cc b/src/crimson/os/alienstore/alien_store.cc index 54d61f76bce09..da6fba75d14f9 100644 --- a/src/crimson/os/alienstore/alien_store.cc +++ b/src/crimson/os/alienstore/alien_store.cc @@ -336,7 +336,7 @@ AlienStore::get_attr(CollectionRef ch, // after-free issue. auto c = static_cast(ch.get()); return store->getattr(c->collection, oid, name.c_str(), value); - }).then([oid, &value] (int r) -> get_attr_errorator::future { + }).then([oid, &value](int r) -> get_attr_errorator::future { if (r == -ENOENT) { return crimson::ct_error::enoent::make(); } else if (r == -ENODATA) { @@ -554,21 +554,21 @@ seastar::future AlienStore::stat( auto AlienStore::omap_get_header(CollectionRef ch, const ghobject_t& oid) - -> read_errorator::future + -> get_attr_errorator::future { assert(tp); return do_with_op_gate(ceph::bufferlist(), [=](auto& bl) { return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, &bl] { auto c = static_cast(ch.get()); return store->omap_get_header(c->collection, oid, &bl); - }).then([&bl] (int r) -> read_errorator::future { + }).then([&bl](int r) -> get_attr_errorator::future { if (r == -ENOENT) { return crimson::ct_error::enoent::make(); } else if (r < 0) { logger().error("omap_get_header: {}", r); - return crimson::ct_error::input_output_error::make(); + ceph_assert(0 == "impossible"); } else { - return read_errorator::make_ready_future( + return get_attr_errorator::make_ready_future( std::move(bl)); } }); diff --git a/src/crimson/os/alienstore/alien_store.h b/src/crimson/os/alienstore/alien_store.h index b7927f50c91a5..f6ba12d2c94c5 100644 --- a/src/crimson/os/alienstore/alien_store.h +++ b/src/crimson/os/alienstore/alien_store.h @@ -106,7 +106,7 @@ public: seastar::future stat( CollectionRef, const ghobject_t&) final; - read_errorator::future omap_get_header( + get_attr_errorator::future omap_get_header( CollectionRef, const ghobject_t&) final; read_errorator::future> fiemap( diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index f10be4ad1b7ba..772ecae1447bc 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -322,7 +322,7 @@ CyanStore::omap_get_values(CollectionRef ch, auto CyanStore::omap_get_header(CollectionRef ch, const ghobject_t& oid) - -> read_errorator::future + -> get_attr_errorator::future { auto c = static_cast(ch.get()); auto o = c->get_object(oid); @@ -330,7 +330,7 @@ CyanStore::omap_get_header(CollectionRef ch, return crimson::ct_error::enoent::make(); } - return read_errorator::make_ready_future( + return get_attr_errorator::make_ready_future( o->omap_header); } diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 66ef00b25a2ad..edba296ac193d 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -115,7 +115,7 @@ public: const ghobject_t& end, uint64_t limit) const final; - read_errorator::future omap_get_header( + get_attr_errorator::future omap_get_header( CollectionRef c, const ghobject_t& oid) final; diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index eff6cb5e5d977..20f3a81f7dbdf 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -125,7 +125,7 @@ public: const std::optional &start ///< [in] start, empty for begin ) = 0; ///< @return values.empty() only if done - virtual read_errorator::future omap_get_header( + virtual get_attr_errorator::future omap_get_header( CollectionRef c, const ghobject_t& oid) = 0; diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 56e31ac19e01c..daf997b014d60 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -649,13 +649,12 @@ seastar::future SeaStore::stat( ); } -auto +SeaStore::get_attr_errorator::future SeaStore::omap_get_header( - CollectionRef c, + CollectionRef ch, const ghobject_t& oid) - -> read_errorator::future { - return seastar::make_ready_future(); + return get_attr(ch, oid, OMAP_HEADER_XATTR_KEY); } SeaStore::read_errorator::future @@ -1307,8 +1306,9 @@ SeaStore::tm_ret SeaStore::_omap_set_header( { LOG_PREFIX(SeaStore::_omap_set_header); DEBUGT("{} {} bytes", *ctx.transaction, *onode, header.length()); - assert(0 == "not supported yet"); - return tm_iertr::now(); + std::map to_set; + to_set[OMAP_HEADER_XATTR_KEY] = header; + return _setattrs(ctx, onode,std::move(to_set)); } SeaStore::tm_ret SeaStore::_omap_clear( @@ -1317,29 +1317,32 @@ SeaStore::tm_ret SeaStore::_omap_clear( { LOG_PREFIX(SeaStore::_omap_clear); DEBUGT("{} {} keys", *ctx.transaction, *onode); - if (auto omap_root = onode->get_layout().omap_root.get( - onode->get_metadata_hint(device->get_block_size())); - omap_root.is_null()) { - return seastar::now(); - } else { - return seastar::do_with( - BtreeOMapManager(*transaction_manager), - onode->get_layout().omap_root.get( - onode->get_metadata_hint(device->get_block_size())), - [&ctx, &onode]( - auto &omap_manager, - auto &omap_root) { - return omap_manager.omap_clear( - omap_root, - *ctx.transaction) - .si_then([&] { - if (omap_root.must_update()) { - onode->get_mutable_layout(*ctx.transaction - ).omap_root.update(omap_root); - } + return _xattr_rmattr(ctx, onode, std::string(OMAP_HEADER_XATTR_KEY)) + .si_then([this, &ctx, &onode]() -> tm_ret { + if (auto omap_root = onode->get_layout().omap_root.get( + onode->get_metadata_hint(device->get_block_size())); + omap_root.is_null()) { + return seastar::now(); + } else { + return seastar::do_with( + BtreeOMapManager(*transaction_manager), + onode->get_layout().omap_root.get( + onode->get_metadata_hint(device->get_block_size())), + [&ctx, &onode]( + auto &omap_manager, + auto &omap_root) { + return omap_manager.omap_clear( + omap_root, + *ctx.transaction) + .si_then([&] { + if (omap_root.must_update()) { + onode->get_mutable_layout(*ctx.transaction + ).omap_root.update(omap_root); + } + }); }); - }); - } + } + }); } SeaStore::tm_ret SeaStore::_omap_rmkeys( diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index 99cf024e7bb1c..3a4822dd6bff9 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -124,7 +124,7 @@ public: const std::optional &start ///< [in] start, empty for begin ) final; ///< @return values.empty() iff done - read_errorator::future omap_get_header( + get_attr_errorator::future omap_get_header( CollectionRef c, const ghobject_t& oid) final; diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index a45760ad47505..4980115829119 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -21,6 +21,9 @@ namespace crimson::os::seastore { +/* using a special xattr key "omap_header" to store omap header */ + const std::string OMAP_HEADER_XATTR_KEY = "omap_header"; + /* * Note: NULL value is usually the default and max value. */ diff --git a/src/crimson/osd/pg_backend.cc b/src/crimson/osd/pg_backend.cc index c6a74d2ec0124..5c7984fe7e4f0 100644 --- a/src/crimson/osd/pg_backend.cc +++ b/src/crimson/osd/pg_backend.cc @@ -1099,7 +1099,13 @@ PGBackend::omap_get_header( const crimson::os::CollectionRef& c, const ghobject_t& oid) const { - return store->omap_get_header(c, oid); + return store->omap_get_header(c, oid) + .handle_error( + crimson::ct_error::enodata::handle([] { + return seastar::make_ready_future(); + }), + ll_read_errorator::pass_further{} + ); } PGBackend::ll_read_ierrorator::future<> -- 2.39.5