From 6f3a50a1d8f618889a956fff312ae21a6f5f34da Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Tue, 16 Jan 2024 16:58:17 +0800 Subject: [PATCH] crimson/os: add FuturizedStore::Shard::exists() interface Signed-off-by: Xuehan Xu (cherry picked from commit 6f0803a86af78965eb954d98e6095d96f0c32f1f) --- src/crimson/os/alienstore/alien_store.cc | 13 +++++++++++++ src/crimson/os/alienstore/alien_store.h | 3 +++ src/crimson/os/cyanstore/cyan_store.cc | 16 ++++++++++++++++ src/crimson/os/cyanstore/cyan_store.h | 6 +++++- src/crimson/os/futurized_store.h | 5 +++++ src/crimson/os/seastore/seastore.cc | 23 +++++++++++++++++++++++ src/crimson/os/seastore/seastore.h | 4 ++++ 7 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/crimson/os/alienstore/alien_store.cc b/src/crimson/os/alienstore/alien_store.cc index 32696775bb092..bfa8dbf42e79d 100644 --- a/src/crimson/os/alienstore/alien_store.cc +++ b/src/crimson/os/alienstore/alien_store.cc @@ -136,6 +136,19 @@ seastar::future<> AlienStore::stop() }); } +AlienStore::base_errorator::future +AlienStore::exists( + CollectionRef ch, + const ghobject_t& oid) +{ + return seastar::with_gate(op_gate, [=, this] { + return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, this] { + auto c = static_cast(ch.get()); + return store->exists(c->collection, oid); + }); + }); +} + AlienStore::mount_ertr::future<> AlienStore::mount() { logger().debug("{}", __func__); diff --git a/src/crimson/os/alienstore/alien_store.h b/src/crimson/os/alienstore/alien_store.h index 7138da955aa16..910bb153dcb48 100644 --- a/src/crimson/os/alienstore/alien_store.h +++ b/src/crimson/os/alienstore/alien_store.h @@ -33,6 +33,9 @@ public: mount_ertr::future<> mount() final; seastar::future<> umount() final; + base_errorator::future exists( + CollectionRef c, + const ghobject_t& oid) final; mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final; read_errorator::future read(CollectionRef c, const ghobject_t& oid, diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index 36230893d36ba..df68e8bd20f93 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -242,6 +242,22 @@ CyanStore::Shard::list_collections() return seastar::make_ready_future>(std::move(collections)); } +CyanStore::Shard::base_errorator::future +CyanStore::Shard::exists( + CollectionRef ch, + const ghobject_t &oid) +{ + auto c = static_cast(ch.get()); + if (!c->exists) { + return base_errorator::make_ready_future(false); + } + auto o = c->get_object(oid); + if (!o) { + return base_errorator::make_ready_future(false); + } + return base_errorator::make_ready_future(true); +} + CyanStore::Shard::read_errorator::future CyanStore::Shard::read( CollectionRef ch, diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 518222d82f651..04df5c707a566 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -26,6 +26,7 @@ class Transaction; namespace crimson::os { class CyanStore final : public FuturizedStore { +public: class Shard : public FuturizedStore::Shard { public: Shard(std::string path) @@ -35,6 +36,10 @@ class CyanStore final : public FuturizedStore { CollectionRef c, const ghobject_t& oid) final; + base_errorator::future exists( + CollectionRef ch, + const ghobject_t& oid) final; + read_errorator::future read( CollectionRef c, const ghobject_t& oid, @@ -158,7 +163,6 @@ class CyanStore final : public FuturizedStore { std::map> new_coll_map; }; -public: CyanStore(const std::string& path); ~CyanStore() final; diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index 783cd74859e3d..8398a5289b2dc 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -36,6 +36,7 @@ public: const Shard& operator=(const Shard& o) = delete; using CollectionRef = boost::intrusive_ptr; + using base_errorator = crimson::errorator; using read_errorator = crimson::errorator; virtual read_errorator::future read( @@ -51,6 +52,10 @@ public: interval_set& m, uint32_t op_flags = 0) = 0; + virtual base_errorator::future exists( + CollectionRef c, + const ghobject_t& oid) = 0; + using get_attr_errorator = crimson::errorator< crimson::ct_error::enoent, crimson::ct_error::enodata>; diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index eba19eabebebd..86eace1dd9b4a 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -852,6 +852,29 @@ SeaStore::Shard::read( }); } +SeaStore::Shard::base_errorator::future +SeaStore::Shard::exists( + CollectionRef c, + const ghobject_t& oid) +{ + LOG_PREFIX(SeaStore::exists); + DEBUG("oid {}", oid); + return repeat_with_onode( + c, + oid, + Transaction::src_t::READ, + "oid_exists", + op_type_t::READ, + [](auto&, auto&) { + return seastar::make_ready_future(true); + }).handle_error( + crimson::ct_error::enoent::handle([] { + return seastar::make_ready_future(false); + }), + crimson::ct_error::assert_all{"unexpected error"} + ); +} + SeaStore::Shard::read_errorator::future SeaStore::Shard::readv( CollectionRef ch, diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index bff0092f45332..8baa4cd658b0e 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -116,6 +116,10 @@ public: interval_set& m, uint32_t op_flags = 0) final; + base_errorator::future exists( + CollectionRef c, + const ghobject_t& oid) final; + get_attr_errorator::future get_attr( CollectionRef c, const ghobject_t& oid, -- 2.39.5