From 0494b02fc53a4b1ff3517bd8dc3ce2a1e96f19ce Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 9 Sep 2019 14:48:19 +0200 Subject: [PATCH] crimson/os, crimson/osd: apply errorator along the read path, part 1. Signed-off-by: Radoslaw Zarzynski --- src/crimson/os/cyan_store.cc | 16 ++++++++-------- src/crimson/os/cyan_store.h | 11 ++++++----- src/crimson/os/futurized_store.h | 23 ++++++++++++++++++----- src/crimson/osd/osd_meta.cc | 14 +++++++++----- src/crimson/osd/replicated_backend.cc | 5 ++++- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index 1ccc78d33fa7b..75795c0639ed2 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -171,22 +171,22 @@ seastar::future> CyanStore::list_collections() return seastar::make_ready_future>(std::move(collections)); } -seastar::future CyanStore::read(CollectionRef ch, - const ghobject_t& oid, - uint64_t offset, - size_t len, - uint32_t op_flags) +CyanStore::read_errorator::future CyanStore::read( + CollectionRef ch, + const ghobject_t& oid, + uint64_t offset, + size_t len, + uint32_t op_flags) { auto c = static_cast(ch.get()); logger().debug("{} {} {} {}~{}", __func__, c->get_cid(), oid, offset, len); if (!c->exists) { - throw std::runtime_error(fmt::format("collection does not exist: {}", - c->get_cid())); + return crimson::make_error(); } ObjectRef o = c->get_object(oid); if (!o) { - throw std::runtime_error(fmt::format("object does not exist: {}", oid)); + return crimson::make_error(); } if (offset >= o->get_size()) return seastar::make_ready_future(); diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h index 96f3eb84a231e..fa40692e59af8 100644 --- a/src/crimson/os/cyan_store.h +++ b/src/crimson/os/cyan_store.h @@ -44,11 +44,12 @@ public: seastar::future<> mkfs(uuid_d new_osd_fsid) final; store_statfs_t stat() const final; - seastar::future read(CollectionRef c, - const ghobject_t& oid, - uint64_t offset, - size_t len, - uint32_t op_flags = 0) final; + read_errorator::future read( + CollectionRef c, + const ghobject_t& oid, + uint64_t offset, + size_t len, + uint32_t op_flags = 0) final; get_attr_errorator::future get_attr( CollectionRef c, const ghobject_t& oid, diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index 401f9d456d183..10bf6874c253d 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -42,11 +42,24 @@ public: virtual store_statfs_t stat() const = 0; using CollectionRef = boost::intrusive_ptr; - virtual seastar::future read(CollectionRef c, - const ghobject_t& oid, - uint64_t offset, - size_t len, - uint32_t op_flags = 0) = 0; + + // TODO: using read_errorator = ceph::errorator<...> + struct read_errorator : crimson::errorator { + // just for the makeshift period of switching to errorator + struct throw_as_runtime_error : discard_all { + auto operator()(const auto& e) { + throw std::runtime_error("legacy throwing"); + return discard_all::operator()(e); + } + }; + }; + virtual read_errorator::future read( + CollectionRef c, + const ghobject_t& oid, + uint64_t offset, + size_t len, + uint32_t op_flags = 0) = 0; + using get_attr_errorator = crimson::errorator< crimson::ct_error::enoent, crimson::ct_error::enodata>; diff --git a/src/crimson/osd/osd_meta.cc b/src/crimson/osd/osd_meta.cc index fd2e63319ba74..6baaf07d15438 100644 --- a/src/crimson/osd/osd_meta.cc +++ b/src/crimson/osd/osd_meta.cc @@ -6,6 +6,8 @@ #include "crimson/os/futurized_store.h" #include "os/Transaction.h" +using read_errorator = crimson::os::FuturizedStore::read_errorator; + void OSDMeta::create(ceph::os::Transaction& t) { t.create_collection(coll->get_cid(), 0); @@ -21,7 +23,9 @@ seastar::future OSDMeta::load_map(epoch_t e) { return store->read(coll, osdmap_oid(e), 0, 0, - CEPH_OSD_OP_FLAG_FADVISE_WILLNEED); + CEPH_OSD_OP_FLAG_FADVISE_WILLNEED).safe_then( + [] (auto&& bl) { return bl; }, + read_errorator::throw_as_runtime_error{}); } void OSDMeta::store_superblock(ceph::os::Transaction& t, @@ -35,12 +39,12 @@ void OSDMeta::store_superblock(ceph::os::Transaction& t, seastar::future OSDMeta::load_superblock() { return store->read(coll, superblock_oid(), 0, 0) - .then([this] (bufferlist&& bl) { + .safe_then([this] (bufferlist&& bl) { auto p = bl.cbegin(); OSDSuperblock superblock; decode(superblock, p); return seastar::make_ready_future(std::move(superblock)); - }); + }, read_errorator::throw_as_runtime_error{}); } seastar::future OSDMeta::load_final_pool_info(int64_t pool) { return store->read(coll, final_pool_info_oid(pool), - 0, 0).then([this] (bufferlist&& bl) { + 0, 0).safe_then([this] (bufferlist&& bl) { auto p = bl.cbegin(); pg_pool_t pi; string name; @@ -61,7 +65,7 @@ OSDMeta::load_final_pool_info(int64_t pool) { ec_profile_t>(std::move(pi), std::move(name), std::move(ec_profile)); - }); + }, read_errorator::throw_as_runtime_error{}); } ghobject_t OSDMeta::osdmap_oid(epoch_t epoch) diff --git a/src/crimson/osd/replicated_backend.cc b/src/crimson/osd/replicated_backend.cc index a72d3f19462fb..1955049bd4c4e 100644 --- a/src/crimson/osd/replicated_backend.cc +++ b/src/crimson/osd/replicated_backend.cc @@ -28,7 +28,10 @@ seastar::future ReplicatedBackend::_read(const hobject_t& hoid, uint64_t len, uint32_t flags) { - return store->read(coll, ghobject_t{hoid}, off, len, flags); + using read_errorator = ceph::os::FuturizedStore::read_errorator; + return store->read(coll, ghobject_t{hoid}, off, len, flags).safe_then( + [] (auto&& bl) { return bl; }, + read_errorator::throw_as_runtime_error{}); } seastar::future -- 2.39.5