]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os: add FuturizedStore::Shard::exists() interface
authorXuehan Xu <xuxuehan@qianxin.com>
Tue, 16 Jan 2024 08:58:17 +0000 (16:58 +0800)
committerMatan Breizman <mbreizma@redhat.com>
Tue, 7 May 2024 11:33:06 +0000 (14:33 +0300)
Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
(cherry picked from commit 6f0803a86af78965eb954d98e6095d96f0c32f1f)

src/crimson/os/alienstore/alien_store.cc
src/crimson/os/alienstore/alien_store.h
src/crimson/os/cyanstore/cyan_store.cc
src/crimson/os/cyanstore/cyan_store.h
src/crimson/os/futurized_store.h
src/crimson/os/seastore/seastore.cc
src/crimson/os/seastore/seastore.h

index 32696775bb09271bd09fdeb2bf375003d275975e..bfa8dbf42e79dbdaa12d501f7a24b1eb3f88f258 100644 (file)
@@ -136,6 +136,19 @@ seastar::future<> AlienStore::stop()
   });
 }
 
+AlienStore::base_errorator::future<bool>
+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<AlienCollection*>(ch.get());
+      return store->exists(c->collection, oid);
+    });
+  });
+}
+
 AlienStore::mount_ertr::future<> AlienStore::mount()
 {
   logger().debug("{}", __func__);
index 7138da955aa16065a49039ae7320d88d0d494568..910bb153dcb486fa5bd87672581ed944bcb9e3c1 100644 (file)
@@ -33,6 +33,9 @@ public:
   mount_ertr::future<> mount() final;
   seastar::future<> umount() final;
 
+  base_errorator::future<bool> exists(
+    CollectionRef c,
+    const ghobject_t& oid) final;
   mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final;
   read_errorator::future<ceph::bufferlist> read(CollectionRef c,
                                    const ghobject_t& oid,
index 36230893d36baace0d1689ffc8197cf3c1030d60..df68e8bd20f93a771130de1feb50ad0d175b8f72 100644 (file)
@@ -242,6 +242,22 @@ CyanStore::Shard::list_collections()
   return seastar::make_ready_future<std::vector<coll_core_t>>(std::move(collections));
 }
 
+CyanStore::Shard::base_errorator::future<bool>
+CyanStore::Shard::exists(
+  CollectionRef ch,
+  const ghobject_t &oid)
+{
+  auto c = static_cast<Collection*>(ch.get());
+  if (!c->exists) {
+    return base_errorator::make_ready_future<bool>(false);
+  }
+  auto o = c->get_object(oid);
+  if (!o) {
+    return base_errorator::make_ready_future<bool>(false);
+  }
+  return base_errorator::make_ready_future<bool>(true);
+}
+
 CyanStore::Shard::read_errorator::future<ceph::bufferlist>
 CyanStore::Shard::read(
   CollectionRef ch,
index 518222d82f65129791ac9739ea5748179959e592..04df5c707a566d6b44db4e0b081361fe657f5419 100644 (file)
@@ -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<bool> exists(
+      CollectionRef ch,
+      const ghobject_t& oid) final;
+
     read_errorator::future<ceph::bufferlist> read(
       CollectionRef c,
       const ghobject_t& oid,
@@ -158,7 +163,6 @@ class CyanStore final : public FuturizedStore {
     std::map<coll_t, boost::intrusive_ptr<Collection>> new_coll_map;
   };
 
-public:
   CyanStore(const std::string& path);
   ~CyanStore() final;
 
index 783cd74859e3d60fa636b064f1435b9b517b1cb3..8398a5289b2dc0b6f4ca0f41e77ee2d2bd1ac68e 100644 (file)
@@ -36,6 +36,7 @@ public:
     const Shard& operator=(const Shard& o) = delete;
 
     using CollectionRef = boost::intrusive_ptr<FuturizedCollection>;
+    using base_errorator = crimson::errorator<crimson::ct_error::input_output_error>;
     using read_errorator = crimson::errorator<crimson::ct_error::enoent,
                                              crimson::ct_error::input_output_error>;
     virtual read_errorator::future<ceph::bufferlist> read(
@@ -51,6 +52,10 @@ public:
       interval_set<uint64_t>& m,
       uint32_t op_flags = 0) = 0;
 
+    virtual base_errorator::future<bool> exists(
+      CollectionRef c,
+      const ghobject_t& oid) = 0;
+
     using get_attr_errorator = crimson::errorator<
       crimson::ct_error::enoent,
       crimson::ct_error::enodata>;
index eba19eabebebdea4ea162b3251c3523e9a322d36..86eace1dd9b4a07f92934b681c83ed7f7cb4cd33 100644 (file)
@@ -852,6 +852,29 @@ SeaStore::Shard::read(
     });
 }
 
+SeaStore::Shard::base_errorator::future<bool>
+SeaStore::Shard::exists(
+  CollectionRef c,
+  const ghobject_t& oid)
+{
+  LOG_PREFIX(SeaStore::exists);
+  DEBUG("oid {}", oid);
+  return repeat_with_onode<bool>(
+    c,
+    oid,
+    Transaction::src_t::READ,
+    "oid_exists",
+    op_type_t::READ,
+    [](auto&, auto&) {
+    return seastar::make_ready_future<bool>(true);
+  }).handle_error(
+    crimson::ct_error::enoent::handle([] {
+      return seastar::make_ready_future<bool>(false);
+    }),
+    crimson::ct_error::assert_all{"unexpected error"}
+  );
+}
+
 SeaStore::Shard::read_errorator::future<ceph::bufferlist>
 SeaStore::Shard::readv(
   CollectionRef ch,
index bff0092f45332539ddb8c01c08cc8a0bf5548ee4..8baa4cd658b0e6e148913a97894328a35e5e4c3e 100644 (file)
@@ -116,6 +116,10 @@ public:
       interval_set<uint64_t>& m,
       uint32_t op_flags = 0) final;
 
+    base_errorator::future<bool> exists(
+      CollectionRef c,
+      const ghobject_t& oid) final;
+
     get_attr_errorator::future<ceph::bufferlist> get_attr(
       CollectionRef c,
       const ghobject_t& oid,