]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson: add FuturizedCollection
authorchunmei Liu <chunmei.liu@intel.com>
Thu, 22 Aug 2019 07:47:40 +0000 (00:47 -0700)
committerKefu Chai <kchai@redhat.com>
Tue, 27 Aug 2019 16:03:53 +0000 (00:03 +0800)
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 <chunmei.liu@intel.com>
18 files changed:
src/crimson/os/cyan_collection.cc
src/crimson/os/cyan_collection.h
src/crimson/os/cyan_store.cc
src/crimson/os/cyan_store.h
src/crimson/os/futurized_collection.h [new file with mode: 0644]
src/crimson/os/futurized_store.h
src/crimson/osd/ec_backend.cc
src/crimson/osd/osd.cc
src/crimson/osd/osd.h
src/crimson/osd/osd_meta.cc
src/crimson/osd/osd_meta.h
src/crimson/osd/pg.cc
src/crimson/osd/pg.h
src/crimson/osd/pg_backend.cc
src/crimson/osd/pg_backend.h
src/crimson/osd/pg_meta.cc
src/crimson/osd/replicated_backend.cc
src/crimson/osd/shard_services.h

index 82403dbc948c225eb67cb76c1eab9a40c1c0bdb4..775cc85e6daa59567cbc4057efd0dfcfd909fe8f 100644 (file)
@@ -6,7 +6,7 @@ namespace ceph::os
 {
 
 Collection::Collection(const coll_t& c)
-  : cid{c}
+  : FuturizedCollection{c}
 {}
 
 Collection::~Collection() = default;
index 1bab93fd71d01431d73e0530e1213b60fe7ae922..fdc07d8fe76f2d0449b6abb21a61e0258ec6573f 100644 (file)
@@ -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<Object>;
   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<Collection>;
-
 }
index 337e819471d6c5dc20eb9da9b35791a474779eb1..650dcb896ad5bd3acd932149a36a0a0b5aa7353d 100644 (file)
@@ -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<Collection> 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<std::vector<ghobject_t>, 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<Collection*>(ch.get());
   logger().debug("{} {} {} {} {}",
                  __func__, c->get_cid(), start, end, limit);
   std::vector<ghobject_t> objects;
@@ -170,12 +171,13 @@ seastar::future<std::vector<coll_t>> CyanStore::list_collections()
   return seastar::make_ready_future<std::vector<coll_t>>(std::move(collections));
 }
 
-seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef c,
+seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef ch,
                                             const ghobject_t& oid,
                                             uint64_t offset,
                                             size_t len,
                                             uint32_t op_flags)
 {
+  auto c = static_cast<Collection*>(ch.get());
   logger().debug("{} {} {} {}~{}",
                 __func__, c->get_cid(), oid, offset, len);
   if (!c->exists) {
@@ -200,10 +202,11 @@ seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef c,
   return seastar::make_ready_future<ceph::bufferlist>(std::move(bl));
 }
 
-seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef c,
+seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef ch,
                                                      const ghobject_t& oid,
                                                      std::string_view name) const
 {
+  auto c = static_cast<Collection*>(ch.get());
   logger().debug("{} {} {}",
                 __func__, c->get_cid(), oid);
   auto o = c->get_object(oid);
@@ -219,9 +222,10 @@ seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef c,
   }
 }
 
-seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef c,
+seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef ch,
                                                          const ghobject_t& oid)
 {
+  auto c = static_cast<Collection*>(ch.get());
   logger().debug("{} {} {}",
                 __func__, c->get_cid(), oid);
   auto o = c->get_object(oid);
@@ -232,10 +236,11 @@ seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef c,
 }
 
 seastar::future<CyanStore::omap_values_t>
-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<Collection*>(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<bool, CyanStore::omap_values_t>
 CyanStore::omap_get_values(
-    CollectionRef c,
+    CollectionRef ch,
     const ghobject_t &oid,
     const std::optional<string> &start
   ) {
+  auto c = static_cast<Collection*>(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<Collection> CyanStore::_get_collection(const coll_t& cid)
 {
   auto cp = coll_map.find(cid);
   if (cp == coll_map.end())
index f1f2a1ec515319fcd5cdd1b6c009d793b64c04a0..7cdbab948c3ea441373d9c8536d03ebd51e4874a 100644 (file)
@@ -12,7 +12,6 @@
 #include <optional>
 #include <seastar/core/future.hh>
 
-#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_t, CollectionRef> coll_map;
-  std::map<coll_t,CollectionRef> new_coll_map;
+  std::unordered_map<coll_t, boost::intrusive_ptr<Collection>> coll_map;
+  std::map<coll_t, boost::intrusive_ptr<Collection>> 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<std::string,bufferptr>& aset);
   int _create_collection(const coll_t& cid, int bits);
-  CollectionRef _get_collection(const coll_t& cid);
+  boost::intrusive_ptr<Collection> _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 (file)
index 0000000..ad72d17
--- /dev/null
@@ -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 <boost/intrusive_ptr.hpp>
+#include <boost/smart_ptr/intrusive_ref_counter.hpp>
+#include <seastar/core/future.hh>
+
+#include "osd/osd_types.h"
+
+namespace ceph::os {
+
+class FuturizedCollection
+  : public boost::intrusive_ref_counter<FuturizedCollection,
+                                        boost::thread_unsafe_counter>
+{
+public:
+  FuturizedCollection(const coll_t& cid)
+    : cid{cid} {}
+  virtual ~FuturizedCollection() {}
+  virtual seastar::future<> flush() {
+    return seastar::now();
+  }
+  virtual seastar::future<bool> flush_commit() {
+    return seastar::make_ready_future<bool>(true);
+  }
+  const coll_t& get_cid() const {
+    return cid;
+  }
+private:
+  const coll_t cid;
+};
+
+using CollectionRef =  boost::intrusive_ptr<FuturizedCollection>;
+}
index a5e3654f1fcef592f1a1a0a90346b9ef308824f9..edd7866dfdef967cd50f25d44f232bc333407db7 100644 (file)
@@ -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<Collection>;
+  using CollectionRef = boost::intrusive_ptr<FuturizedCollection>;
   virtual seastar::future<ceph::bufferlist> read(CollectionRef c,
                                   const ghobject_t& oid,
                                   uint64_t offset,
index 010b52121c7c419773b13bbab61c94b94db4e7b4..cc1365282780c56a8a1937a77f0cbf3efacce053 100644 (file)
@@ -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,
index 312ab278f16789353cd5f17c177c793fd0ecf75e..6b2468d440cd63382f89c54d22bbd2739478ffa4 100644 (file)
@@ -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"
index 4e8523c0f64a7d3af65ee6842d0c0b48299af0e5..0377edfd9dc87d3ca42dbbf9def2c2948c88ee5a 100644 (file)
@@ -50,7 +50,6 @@ namespace ceph::net {
 
 namespace ceph::os {
   class FuturizedStore;
-  struct Collection;
   class Transaction;
 }
 
index 8b449117d2ddfd4ec7a5e151973eacea32cab2e7..fd2e63319ba743f5f1e1b2a5326d9369306073d2 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <fmt/format.h>
 
-#include "crimson/os/cyan_collection.h"
+#include "crimson/os/futurized_collection.h"
 #include "crimson/os/futurized_store.h"
 #include "os/Transaction.h"
 
index 613e393df56ffafccac5e765cfb5e0384fe2eec2..18cc0d86725c9897565f5187897b9b76d8801f70 100644 (file)
@@ -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<typename T> using Ref = boost::intrusive_ptr<T>;
 
   ceph::os::FuturizedStore* store;
-  Ref<ceph::os::Collection> coll;
+  Ref<ceph::os::FuturizedCollection> coll;
 
 public:
-  OSDMeta(Ref<ceph::os::Collection> coll,
+  OSDMeta(Ref<ceph::os::FuturizedCollection> coll,
           ceph::os::FuturizedStore* store)
     : store{store}, coll{coll}
   {}
index fa4e1401037b3f1a805595ae11708a36f9dfe4b0..d6890834f5de52ec8b3fd6b65db2f317227cf603 100644 (file)
@@ -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"
 
index 31d8d315fdf33d59b4111ac8b8ab06c1fe57f283..3111c9b30c778a35805868ba081dc58a319ce533 100644 (file)
@@ -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"
index 89b9f3f49dc0461832c9fef055ce12dc8accbda7..7287099f03b1043f0c25c9b4e7333c9858163758 100644 (file)
@@ -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"
index 7f3dd4fb3a996505fb81e2b3dba63bae90753ab1..e698ebe77fcd9cfb356ac148d96b839830be6c78 100644 (file)
@@ -9,7 +9,7 @@
 #include <boost/smart_ptr/local_shared_ptr.hpp>
 
 #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<ceph::os::Collection>;
+  using CollectionRef = ceph::os::CollectionRef;
   using ec_profile_t = std::map<std::string, std::string>;
 
 public:
index 30ef48b37c888692bbf16bf4f0949b9530352806..969060d4b2d32e39db1037022a80eb0ea425c5b3 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <string_view>
 
-#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
index 44ca03af29f1ffd429c5cb6400ec4b1ae94771b9..9cddf664e0cfc5616782f1ec242f9d3c6a3c8d34 100644 (file)
@@ -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"
index c89c4ddf6f6cd2840f6fa20180abdfa73588c549..6dbcde01ff70b2937c9ae27d28c3d6e68230ffb8 100644 (file)
@@ -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"