From: chunmei Liu Date: Thu, 22 Aug 2019 07:47:40 +0000 (-0700) Subject: crimson: add FuturizedCollection X-Git-Tag: v15.1.0~1751^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0fbedd538c1015cbc93363320b22088439419484;p=ceph-ci.git crimson: add FuturizedCollection we will need to talk to BlueStore, and currently `ceph::os::Collection` only works with `CyanStore`, so a wrapper around `ceph::os::Collection` is added. we can subclass it to adapt to CyanStore and to BlueStore. the underlying concrete `FuturizedStore` classes are responsible to cast `FuturizedCollection` to their own `Collection` type if they want to access the interface not exposed by `FuturizedCollection`. Signed-off-by: chunmei Liu --- diff --git a/src/crimson/os/cyan_collection.cc b/src/crimson/os/cyan_collection.cc index 82403dbc948..775cc85e6da 100644 --- a/src/crimson/os/cyan_collection.cc +++ b/src/crimson/os/cyan_collection.cc @@ -6,7 +6,7 @@ namespace ceph::os { Collection::Collection(const coll_t& c) - : cid{c} + : FuturizedCollection{c} {} Collection::~Collection() = default; diff --git a/src/crimson/os/cyan_collection.h b/src/crimson/os/cyan_collection.h index 1bab93fd71d..fdc07d8fe76 100644 --- a/src/crimson/os/cyan_collection.h +++ b/src/crimson/os/cyan_collection.h @@ -11,6 +11,8 @@ #include "include/buffer.h" #include "osd/osd_types.h" +#include "futurized_collection.h" + namespace ceph::os { class Object; @@ -24,10 +26,7 @@ class Object; * ObjectStore users may get collection handles with open_collection() (or, * for bootstrapping a new collection, create_new_collection()). */ -struct Collection : public boost::intrusive_ref_counter< - Collection, - boost::thread_unsafe_counter> -{ +struct Collection final : public FuturizedCollection { using ObjectRef = boost::intrusive_ptr; int bits = 0; // always use bufferlist object for testing @@ -38,23 +37,15 @@ struct Collection : public boost::intrusive_ref_counter< bool exists = true; Collection(const coll_t& c); - ~Collection(); + ~Collection() final; ObjectRef create_object() const; ObjectRef get_object(ghobject_t oid); ObjectRef get_or_create_object(ghobject_t oid); uint64_t used_bytes() const; - const coll_t &get_cid() const { - return cid; - } - void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& p); -private: - const coll_t cid; }; -using CollectionRef = boost::intrusive_ptr; - } diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index 337e819471d..650dcb896ad 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -52,7 +52,7 @@ seastar::future<> CyanStore::mount() if (int r = cbl.read_file(fn.c_str(), &err); r < 0) { throw std::runtime_error("read_file"); } - CollectionRef c{new Collection{coll}}; + boost::intrusive_ptr c{new Collection{coll}}; auto p = cbl.cbegin(); c->decode(p); coll_map[coll] = c; @@ -125,11 +125,12 @@ store_statfs_t CyanStore::stat() const } seastar::future, ghobject_t> -CyanStore::list_objects(CollectionRef c, +CyanStore::list_objects(CollectionRef ch, const ghobject_t& start, const ghobject_t& end, uint64_t limit) const { + auto c = static_cast(ch.get()); logger().debug("{} {} {} {} {}", __func__, c->get_cid(), start, end, limit); std::vector objects; @@ -170,12 +171,13 @@ seastar::future> CyanStore::list_collections() return seastar::make_ready_future>(std::move(collections)); } -seastar::future CyanStore::read(CollectionRef c, +seastar::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) { @@ -200,10 +202,11 @@ seastar::future CyanStore::read(CollectionRef c, return seastar::make_ready_future(std::move(bl)); } -seastar::future CyanStore::get_attr(CollectionRef c, +seastar::future CyanStore::get_attr(CollectionRef ch, const ghobject_t& oid, std::string_view name) const { + auto c = static_cast(ch.get()); logger().debug("{} {} {}", __func__, c->get_cid(), oid); auto o = c->get_object(oid); @@ -219,9 +222,10 @@ seastar::future CyanStore::get_attr(CollectionRef c, } } -seastar::future CyanStore::get_attrs(CollectionRef c, +seastar::future CyanStore::get_attrs(CollectionRef ch, const ghobject_t& oid) { + auto c = static_cast(ch.get()); logger().debug("{} {} {}", __func__, c->get_cid(), oid); auto o = c->get_object(oid); @@ -232,10 +236,11 @@ seastar::future CyanStore::get_attrs(CollectionRef c, } seastar::future -CyanStore::omap_get_values(CollectionRef c, +CyanStore::omap_get_values(CollectionRef ch, const ghobject_t& oid, const omap_keys_t& keys) { + auto c = static_cast(ch.get()); logger().debug("{} {} {}", __func__, c->get_cid(), oid); auto o = c->get_object(oid); @@ -253,10 +258,11 @@ CyanStore::omap_get_values(CollectionRef c, seastar::future CyanStore::omap_get_values( - CollectionRef c, + CollectionRef ch, const ghobject_t &oid, const std::optional &start ) { + auto c = static_cast(ch.get()); logger().debug( "{} {} {}", __func__, c->get_cid(), oid); @@ -599,7 +605,7 @@ int CyanStore::_create_collection(const coll_t& cid, int bits) return 0; } -CollectionRef CyanStore::_get_collection(const coll_t& cid) +boost::intrusive_ptr CyanStore::_get_collection(const coll_t& cid) { auto cp = coll_map.find(cid); if (cp == coll_map.end()) diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h index f1f2a1ec515..7cdbab948c3 100644 --- a/src/crimson/os/cyan_store.h +++ b/src/crimson/os/cyan_store.h @@ -12,7 +12,6 @@ #include #include -#include "crimson/os/cyan_collection.h" #include "osd/osd_types.h" #include "include/uuid.h" @@ -28,8 +27,8 @@ class CyanStore final : public FuturizedStore { constexpr static unsigned MAX_KEYS_PER_OMAP_GET_CALL = 32; const std::string path; - std::unordered_map coll_map; - std::map new_coll_map; + std::unordered_map> coll_map; + std::map> new_coll_map; uint64_t used_bytes = 0; uuid_d osd_fsid; @@ -113,7 +112,7 @@ private: int _setattrs(const coll_t& cid, const ghobject_t& oid, std::map& aset); int _create_collection(const coll_t& cid, int bits); - CollectionRef _get_collection(const coll_t& cid); + boost::intrusive_ptr _get_collection(const coll_t& cid); }; } diff --git a/src/crimson/os/futurized_collection.h b/src/crimson/os/futurized_collection.h new file mode 100644 index 00000000000..ad72d17c021 --- /dev/null +++ b/src/crimson/os/futurized_collection.h @@ -0,0 +1,36 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include +#include +#include + +#include "osd/osd_types.h" + +namespace ceph::os { + +class FuturizedCollection + : public boost::intrusive_ref_counter +{ +public: + FuturizedCollection(const coll_t& cid) + : cid{cid} {} + virtual ~FuturizedCollection() {} + virtual seastar::future<> flush() { + return seastar::now(); + } + virtual seastar::future flush_commit() { + return seastar::make_ready_future(true); + } + const coll_t& get_cid() const { + return cid; + } +private: + const coll_t cid; +}; + +using CollectionRef = boost::intrusive_ptr; +} diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index a5e3654f1fc..edd7866dfde 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -17,7 +17,7 @@ namespace ceph::os { -class Collection; +class FuturizedCollection; class Transaction; class FuturizedStore { @@ -64,7 +64,7 @@ public: virtual seastar::future<> mkfs(uuid_d new_osd_fsid) = 0; virtual store_statfs_t stat() const = 0; - using CollectionRef = boost::intrusive_ptr; + using CollectionRef = boost::intrusive_ptr; virtual seastar::future read(CollectionRef c, const ghobject_t& oid, uint64_t offset, diff --git a/src/crimson/osd/ec_backend.cc b/src/crimson/osd/ec_backend.cc index 010b52121c7..cc136528278 100644 --- a/src/crimson/osd/ec_backend.cc +++ b/src/crimson/osd/ec_backend.cc @@ -1,6 +1,5 @@ #include "ec_backend.h" -#include "crimson/os/cyan_collection.h" #include "crimson/osd/shard_services.h" ECBackend::ECBackend(shard_id_t shard, diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index 312ab278f16..6b2468d440c 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -27,7 +27,7 @@ #include "crimson/mon/MonClient.h" #include "crimson/net/Connection.h" #include "crimson/net/Messenger.h" -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "crimson/os/cyan_object.h" #include "crimson/os/futurized_store.h" #include "crimson/osd/heartbeat.h" diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index 4e8523c0f64..0377edfd9dc 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -50,7 +50,6 @@ namespace ceph::net { namespace ceph::os { class FuturizedStore; - struct Collection; class Transaction; } diff --git a/src/crimson/osd/osd_meta.cc b/src/crimson/osd/osd_meta.cc index 8b449117d2d..fd2e63319ba 100644 --- a/src/crimson/osd/osd_meta.cc +++ b/src/crimson/osd/osd_meta.cc @@ -2,7 +2,7 @@ #include -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "crimson/os/futurized_store.h" #include "os/Transaction.h" diff --git a/src/crimson/osd/osd_meta.h b/src/crimson/osd/osd_meta.h index 613e393df56..18cc0d86725 100644 --- a/src/crimson/osd/osd_meta.h +++ b/src/crimson/osd/osd_meta.h @@ -9,8 +9,8 @@ #include "osd/osd_types.h" namespace ceph::os { + class FuturizedCollection; class FuturizedStore; - class Collection; class Transaction; } @@ -20,10 +20,10 @@ class OSDMeta { template using Ref = boost::intrusive_ptr; ceph::os::FuturizedStore* store; - Ref coll; + Ref coll; public: - OSDMeta(Ref coll, + OSDMeta(Ref coll, ceph::os::FuturizedStore* store) : store{store}, coll{coll} {} diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index fa4e1401037..d6890834f5d 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -30,7 +30,7 @@ #include "crimson/net/Connection.h" #include "crimson/net/Messenger.h" -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "os/Transaction.h" #include "crimson/os/cyan_store.h" diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 31d8d315fdf..3111c9b30c7 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -19,6 +19,7 @@ #include "osd/PeeringState.h" #include "crimson/common/type_helpers.h" +#include "crimson/os/futurized_collection.h" #include "crimson/osd/osd_operations/client_request.h" #include "crimson/osd/osd_operations/peering_event.h" #include "crimson/osd/osd_operations/replicated_request.h" diff --git a/src/crimson/osd/pg_backend.cc b/src/crimson/osd/pg_backend.cc index 89b9f3f49dc..7287099f03b 100644 --- a/src/crimson/osd/pg_backend.cc +++ b/src/crimson/osd/pg_backend.cc @@ -12,7 +12,7 @@ #include "messages/MOSDOp.h" -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "crimson/os/cyan_object.h" #include "crimson/os/futurized_store.h" #include "replicated_backend.h" diff --git a/src/crimson/osd/pg_backend.h b/src/crimson/osd/pg_backend.h index 7f3dd4fb3a9..e698ebe77fc 100644 --- a/src/crimson/osd/pg_backend.h +++ b/src/crimson/osd/pg_backend.h @@ -9,7 +9,7 @@ #include #include "crimson/os/futurized_store.h" -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "crimson/osd/acked_peers.h" #include "crimson/common/shared_lru.h" #include "os/Transaction.h" @@ -26,7 +26,7 @@ namespace ceph::osd { class PGBackend { protected: - using CollectionRef = boost::intrusive_ptr; + using CollectionRef = ceph::os::CollectionRef; using ec_profile_t = std::map; public: diff --git a/src/crimson/osd/pg_meta.cc b/src/crimson/osd/pg_meta.cc index 30ef48b37c8..969060d4b2d 100644 --- a/src/crimson/osd/pg_meta.cc +++ b/src/crimson/osd/pg_meta.cc @@ -2,7 +2,7 @@ #include -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "crimson/os/futurized_store.h" // prefix pgmeta_oid keys with _ so that PGLog::read_log_and_missing() can diff --git a/src/crimson/osd/replicated_backend.cc b/src/crimson/osd/replicated_backend.cc index 44ca03af29f..9cddf664e0c 100644 --- a/src/crimson/osd/replicated_backend.cc +++ b/src/crimson/osd/replicated_backend.cc @@ -3,7 +3,6 @@ #include "messages/MOSDRepOpReply.h" #include "crimson/common/log.h" -#include "crimson/os/cyan_collection.h" #include "crimson/os/cyan_object.h" #include "crimson/os/futurized_store.h" #include "crimson/osd/shard_services.h" diff --git a/src/crimson/osd/shard_services.h b/src/crimson/osd/shard_services.h index c89c4ddf6f6..6dbcde01ff7 100644 --- a/src/crimson/osd/shard_services.h +++ b/src/crimson/osd/shard_services.h @@ -8,7 +8,7 @@ #include "osd_operation.h" #include "msg/MessageRef.h" -#include "crimson/os/cyan_collection.h" +#include "crimson/os/futurized_collection.h" #include "osd/PeeringState.h" #include "crimson/osd/osdmap_service.h"