From 4dd6ec787a7ab8a1e74b195c02e3ac28a7ebbd3d Mon Sep 17 00:00:00 2001 From: Chunmei Liu Date: Tue, 21 Jan 2020 11:48:08 -0800 Subject: [PATCH] crimson:add more futurized store API for alien store since alien store is futurized store, need change all store API to be futurized. Signed-off-by: Chunmei Liu --- src/crimson/os/cyanstore/cyan_object.h | 2 + src/crimson/os/cyanstore/cyan_store.cc | 4 +- src/crimson/os/cyanstore/cyan_store.h | 4 +- src/crimson/os/futurized_collection.h | 3 +- src/crimson/os/futurized_store.h | 9 +++- src/crimson/osd/osd.cc | 61 +++++++++++++++----------- src/crimson/osd/osd_meta.cc | 6 +-- src/crimson/osd/osd_meta.h | 2 +- src/crimson/osd/pg_backend.h | 1 - 9 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/crimson/os/cyanstore/cyan_object.h b/src/crimson/os/cyanstore/cyan_object.h index 993fb903b92fa..912629de067ea 100644 --- a/src/crimson/os/cyanstore/cyan_object.h +++ b/src/crimson/os/cyanstore/cyan_object.h @@ -37,4 +37,6 @@ struct Object : public boost::intrusive_ref_counter< void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& p); }; +using ObjectRef = boost::intrusive_ptr; + } diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index 0cd89953743d2..b08859a43196d 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -115,13 +115,13 @@ seastar::future<> CyanStore::mkfs(uuid_d new_osd_fsid) }); } -store_statfs_t CyanStore::stat() const +seastar::future CyanStore::stat() const { logger().debug("{}", __func__); store_statfs_t st; st.total = crimson::common::local_conf().get_val("memstore_device_bytes"); st.available = st.total - used_bytes; - return st; + return seastar::make_ready_future(std::move(st)); } seastar::future, ghobject_t> diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 977cf2ff92937..d1172c679cfb6 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -11,6 +11,7 @@ #include #include +#include #include "osd/osd_types.h" #include "include/uuid.h" @@ -38,11 +39,12 @@ public: CyanStore(const std::string& path); ~CyanStore() final; + seastar::future<> stop() final {return seastar::now();} seastar::future<> mount() final; seastar::future<> umount() final; seastar::future<> mkfs(uuid_d new_osd_fsid) final; - store_statfs_t stat() const final; + seastar::future stat() const final; read_errorator::future read( CollectionRef c, diff --git a/src/crimson/os/futurized_collection.h b/src/crimson/os/futurized_collection.h index 2226a53aa1cee..06f7d2f47d5f2 100644 --- a/src/crimson/os/futurized_collection.h +++ b/src/crimson/os/futurized_collection.h @@ -10,6 +10,7 @@ #include "osd/osd_types.h" namespace crimson::os { +class FuturizedStore; class FuturizedCollection : public boost::intrusive_ref_counter flush() { - return seastar::now(); + return seastar::make_ready_future<>(); } virtual seastar::future flush_commit() { return seastar::make_ready_future(true); diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index 388b965148ee5..6bc228a00d003 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -35,14 +35,19 @@ public: explicit FuturizedStore(const FuturizedStore& o) = delete; const FuturizedStore& operator=(const FuturizedStore& o) = delete; + virtual seastar::future<> start() { + return seastar::now(); + } + virtual seastar::future<> stop() = 0; virtual seastar::future<> mount() = 0; virtual seastar::future<> umount() = 0; virtual seastar::future<> mkfs(uuid_d new_osd_fsid) = 0; - virtual store_statfs_t stat() const = 0; + virtual seastar::future stat() const = 0; using CollectionRef = boost::intrusive_ptr; - using read_errorator = crimson::errorator; + using read_errorator = crimson::errorator; virtual read_errorator::future read( CollectionRef c, const ghobject_t& oid, diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index e609990ad8765..147e6b9d3d8d3 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -125,7 +125,9 @@ CompatSet get_osd_initial_compat_set() seastar::future<> OSD::mkfs(uuid_d osd_uuid, uuid_d cluster_fsid) { - return store->mkfs(osd_uuid).then([this] { + return store->start().then([this, osd_uuid] { + return store->mkfs(osd_uuid); + }).then([this] { return store->mount(); }).then([cluster_fsid, this] { superblock.cluster_fsid = cluster_fsid; @@ -204,7 +206,9 @@ seastar::future<> OSD::start() startup_time = ceph::mono_clock::now(); - return store->mount().then([this] { + return store->start().then([this] { + return store->mount(); + }).then([this] { return store->open_collection(coll_t::meta()); }).then([this](auto ch) { meta_coll = make_unique(ch, store.get()); @@ -346,33 +350,38 @@ seastar::future<> OSD::_add_me_to_crush() if (!local_conf().get_val("osd_crush_update_on_start")) { return seastar::now(); } - const double weight = [this] { + auto get_weight = [this] { if (auto w = local_conf().get_val("osd_crush_initial_weight"); w >= 0) { - return w; + return seastar::make_ready_future(w); } else { - auto total = store->stat().total; - return std::max(.00001, double(total) / double(1ull << 40)); // TB + return store->stat().then([](auto st) { + auto total = st.total; + return seastar::make_ready_future( + std::max(.00001, + double(total) / double(1ull << 40))); // TB + }); } - }(); - const crimson::crush::CrushLocation loc{make_unique().get()}; - logger().info("{} crush location is {}", __func__, loc); - string cmd = fmt::format(R"({{ - "prefix": "osd crush create-or-move", - "id": {}, - "weight": {:.4f}, - "args": [{}] - }})", whoami, weight, loc); - return monc->run_command({cmd}, {}).then( - [](int32_t code, string message, bufferlist) { - if (code) { - logger().warn("fail to add to crush: {} ({})", message, code); - throw std::runtime_error("fail to add to crush"); - } else { - logger().info("added to crush: {}", message); - } - return seastar::now(); - }); + }; + return get_weight().then([this](auto weight) { + const crimson::crush::CrushLocation loc{make_unique().get()}; + logger().info("{} crush location is {}", __func__, loc); + string cmd = fmt::format(R"({{ + "prefix": "osd crush create-or-move", + "id": {}, + "weight": {:.4f}, + "args": [{}] + }})", whoami, weight, loc); + return monc->run_command({cmd}, {}); + }).then([](int32_t code, string message, bufferlist) { + if (code) { + logger().warn("fail to add to crush: {} ({})", message, code); + throw std::runtime_error("fail to add to crush"); + } else { + logger().info("added to crush: {}", message); + } + return seastar::now(); + }); } seastar::future<> OSD::_send_alive() @@ -436,6 +445,8 @@ seastar::future<> OSD::stop() cluster_msgr->shutdown()); }).then([this] { return store->umount(); + }).then([this] { + return store->stop(); }).handle_exception([](auto ep) { logger().error("error while stopping osd: {}", ep); }); diff --git a/src/crimson/osd/osd_meta.cc b/src/crimson/osd/osd_meta.cc index 56b627e7441a2..bd5880540be8f 100644 --- a/src/crimson/osd/osd_meta.cc +++ b/src/crimson/osd/osd_meta.cc @@ -28,7 +28,7 @@ seastar::future OSDMeta::load_map(epoch_t e) return store->read(coll, osdmap_oid(e), 0, 0, CEPH_OSD_OP_FLAG_FADVISE_WILLNEED).handle_error( - crimson::ct_error::enoent::handle([e] { + read_errorator::all_same_way([e] { throw std::runtime_error(fmt::format("read gave enoent on {}", osdmap_oid(e))); })); @@ -50,7 +50,7 @@ seastar::future OSDMeta::load_superblock() OSDSuperblock superblock; decode(superblock, p); return seastar::make_ready_future(std::move(superblock)); - }, crimson::ct_error::enoent::handle([] { + }, read_errorator::all_same_way([] { throw std::runtime_error(fmt::format("read gave enoent on {}", superblock_oid())); })); @@ -74,7 +74,7 @@ OSDMeta::load_final_pool_info(int64_t pool) { ec_profile_t>(std::move(pi), std::move(name), std::move(ec_profile)); - }, crimson::ct_error::enoent::handle([pool] { + },read_errorator::all_same_way([pool] { throw std::runtime_error(fmt::format("read gave enoent on {}", final_pool_info_oid(pool))); })); diff --git a/src/crimson/osd/osd_meta.h b/src/crimson/osd/osd_meta.h index 35e9a9c22f2fd..e4043c768cd53 100644 --- a/src/crimson/osd/osd_meta.h +++ b/src/crimson/osd/osd_meta.h @@ -7,6 +7,7 @@ #include #include #include "osd/osd_types.h" +#include "crimson/os/futurized_collection.h" namespace ceph::os { class Transaction; @@ -31,7 +32,6 @@ public: : store{store}, coll{coll} {} - auto collection() { return coll; } diff --git a/src/crimson/osd/pg_backend.h b/src/crimson/osd/pg_backend.h index d72997eff66ab..ae55fd289bf57 100644 --- a/src/crimson/osd/pg_backend.h +++ b/src/crimson/osd/pg_backend.h @@ -45,7 +45,6 @@ public: const ec_profile_t& ec_profile); using read_errorator = ll_read_errorator::extend< - crimson::ct_error::input_output_error, crimson::ct_error::object_corrupted>; read_errorator::future read( const object_info_t& oi, -- 2.39.5