]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/seastore: factor out MDStore interface
authorSamuel Just <sjust@redhat.com>
Thu, 28 Oct 2021 08:37:13 +0000 (01:37 -0700)
committerchunmei-liu <chunmei.liu@intel.com>
Sat, 30 Oct 2021 01:03:59 +0000 (18:03 -0700)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/os/seastore/seastore.cc
src/crimson/os/seastore/seastore.h

index 304b38cbbc7e11bcdea79f1267e75e97abd798ab..3ba1795e502fa4fb695b015b006c975afd239e89 100644 (file)
@@ -35,13 +35,52 @@ using crimson::common::local_conf;
 
 namespace crimson::os::seastore {
 
+class FileMDStore final : public SeaStore::MDStore {
+  std::string root;
+public:
+  FileMDStore(std::string root) : root(root) {}
+
+  write_meta_ret write_meta(
+    const std::string& key, const std::string& value) final {
+    std::string path = fmt::format("{}/{}", root, key);
+    std::string fvalue = value;
+    fvalue += "\n";
+    ceph::bufferptr bp(fvalue.length());
+    ceph::bufferlist bl;
+    bp.copy_in(0, fvalue.length(), fvalue.c_str());
+    bl.push_back(bp);
+    return crimson::write_file(std::move(bl), path);
+  }
+
+  read_meta_ret read_meta(const std::string& key) final {
+    std::string path = fmt::format("{}/{}", root, key);
+    return seastar::file_exists(
+      path
+    ).then([path] (bool exist) {
+      if (exist) {
+       return crimson::read_file(path)
+         .then([] (auto tmp_buf) {
+           std::string v = {tmp_buf.get(), tmp_buf.size()};
+           std::size_t pos = v.find("\n");
+           std::string str = v.substr(0, pos);
+           return seastar::make_ready_future<std::optional<std::string>>(str);
+         });
+      } else {
+       return seastar::make_ready_future<std::optional<std::string>>(std::nullopt);
+      }
+    });
+  }
+};
+
 SeaStore::SeaStore(
   std::string root,
+  MDStoreRef mdstore,
   SegmentManagerRef sm,
   TransactionManagerRef tm,
   CollectionManagerRef cm,
   OnodeManagerRef om)
   : root(root),
+    mdstore(std::move(mdstore)),
     segment_manager(std::move(sm)),
     transaction_manager(std::move(tm)),
     collection_manager(std::move(cm)),
@@ -50,6 +89,17 @@ SeaStore::SeaStore(
   register_metrics();
 }
 
+SeaStore::SeaStore(
+  std::string root,
+  SegmentManagerRef sm,
+  TransactionManagerRef tm,
+  CollectionManagerRef cm,
+  OnodeManagerRef om)
+  : SeaStore(
+    root,
+    std::make_unique<FileMDStore>(root),
+    std::move(sm), std::move(tm), std::move(cm), std::move(om)) {}
+
 SeaStore::~SeaStore() = default;
 
 void SeaStore::register_metrics()
@@ -1265,19 +1315,6 @@ boost::intrusive_ptr<SeastoreCollection> SeaStore::_get_collection(const coll_t&
   return new SeastoreCollection{cid};
 }
 
-seastar::future<> SeaStore::write_meta_file(const std::string& key,
-                                            const std::string& value)
-{
-  std::string path = fmt::format("{}/{}", root, key);
-  std::string fvalue = value;
-  fvalue += "\n";
-  ceph::bufferptr bp(fvalue.length());
-  ceph::bufferlist bl;
-  bp.copy_in(0, fvalue.length(), fvalue.c_str());
-  bl.push_back(bp);
-  return crimson::write_file(std::move(bl), path);
-}
-
 seastar::future<> SeaStore::write_meta(const std::string& key,
                                        const std::string& value)
 {
@@ -1298,45 +1335,28 @@ seastar::future<> SeaStore::write_meta(const std::string& key,
              });
            });
        }).safe_then([this, &key, &value] {
-         return write_meta_file(key, value);
+         return mdstore->write_meta(key, value);
        });
       }).handle_error(
        crimson::ct_error::assert_all{"Invalid error in SeaStore::write_meta"}
       );
 }
 
-seastar::future<std::optional<std::string>>
-SeaStore::read_meta_file(const std::string& key)
-{
-  std::string path = fmt::format("{}/{}", root, key);
-  return seastar::file_exists(
-    path
-  ).then([path] (bool exist) {
-    if (exist) {
-      return crimson::read_file(path)
-        .then([] (auto tmp_buf) {
-         std::string v = {tmp_buf.get(), tmp_buf.size()};
-         std::size_t pos = v.find("\n");
-         std::string str = v.substr(0, pos);
-         return seastar::make_ready_future<std::optional<std::string>>(str);
-       });
-    } else {
-      return seastar::make_ready_future<std::optional<std::string>>(std::nullopt);
-    }
-  });
-}
-
 seastar::future<std::tuple<int, std::string>> SeaStore::read_meta(const std::string& key)
 {
   LOG_PREFIX(SeaStore::read_meta);
   DEBUG("key: {}", key);
-  return read_meta_file(key).then([](auto v) {
+  return mdstore->read_meta(key).safe_then([](auto v) {
     if (v) {
       return std::make_tuple(0, std::move(*v));
     } else {
       return std::make_tuple(-1, std::string(""));
     }
-  });
+  }).handle_error(
+    crimson::ct_error::assert_all{
+      "Invalid error in SeaStore::read_meta"
+    }
+  );
 }
 
 uuid_d SeaStore::get_fsid() const
index 83b4625e134617ce88e0117278e50542a9b959e7..25fe0e0158c7d8356ce12a6280ad8c2df397afc7 100644 (file)
@@ -40,7 +40,34 @@ public:
 
 class SeaStore final : public FuturizedStore {
 public:
+  class MDStore {
+  public:
+    using base_iertr = crimson::errorator<
+      crimson::ct_error::input_output_error
+    >;
+
+    using write_meta_ertr = base_iertr;
+    using write_meta_ret = write_meta_ertr::future<>;
+    virtual write_meta_ret write_meta(
+      const std::string &key,
+      const std::string &val
+    ) = 0;
+
+    using read_meta_ertr = base_iertr;
+    using read_meta_ret = write_meta_ertr::future<std::optional<std::string>>;
+    virtual read_meta_ret read_meta(const std::string &key) = 0;
 
+    virtual ~MDStore() {}
+  };
+  using MDStoreRef = std::unique_ptr<MDStore>;
+
+  SeaStore(
+    std::string root,
+    MDStoreRef mdstore,
+    SegmentManagerRef sm,
+    TransactionManagerRef tm,
+    CollectionManagerRef cm,
+    OnodeManagerRef om);
   SeaStore(
     std::string root,
     SegmentManagerRef sm,
@@ -265,6 +292,7 @@ private:
     OMapManager::omap_list_config_t config);
 
   std::string root;
+  MDStoreRef mdstore;
   SegmentManagerRef segment_manager;
   std::vector<SegmentManagerRef> secondaries;
   TransactionManagerRef transaction_manager;