From da2b40586a08eaa39256bdf8f45759ea6779bb8c Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Thu, 28 Oct 2021 01:37:13 -0700 Subject: [PATCH] crimson/os/seastore/seastore: factor out MDStore interface Signed-off-by: Samuel Just --- src/crimson/os/seastore/seastore.cc | 94 +++++++++++++++++------------ src/crimson/os/seastore/seastore.h | 28 +++++++++ 2 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 304b38cbbc7e1..3ba1795e502fa 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -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>(str); + }); + } else { + return seastar::make_ready_future>(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(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 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> -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>(str); - }); - } else { - return seastar::make_ready_future>(std::nullopt); - } - }); -} - seastar::future> 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 diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index 83b4625e13461..25fe0e0158c7d 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -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>; + virtual read_meta_ret read_meta(const std::string &key) = 0; + virtual ~MDStore() {} + }; + using MDStoreRef = std::unique_ptr; + + 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 secondaries; TransactionManagerRef transaction_manager; -- 2.39.5