]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os: add junction between OSD's ops and Seastore's OrderingHandle.
authorRadosław Zarzyński <rzarzyns@redhat.com>
Tue, 26 Apr 2022 13:50:32 +0000 (15:50 +0200)
committerRadosław Zarzyński <rzarzyns@redhat.com>
Thu, 5 May 2022 02:06:32 +0000 (04:06 +0200)
Signed-off-by: Radosław Zarzyński <rzarzyns@redhat.com>
src/crimson/os/seastore/ordering_handle.h
src/crimson/osd/osd_operation.h

index b44860f092991a69b2855f71afba73694a74eb25..add75066be4d139b1b15ddafdf6ffe1369f8be79 100644 (file)
@@ -6,9 +6,36 @@
 #include <seastar/core/shared_mutex.hh>
 
 #include "crimson/common/operation.h"
+#include "crimson/osd/osd_operation.h"
 
 namespace crimson::os::seastore {
 
+struct WritePipeline {
+  struct ReserveProjectedUsage : OrderedExclusivePhaseT<ReserveProjectedUsage> {
+    constexpr static auto type_name = "WritePipeline::reserve_projected_usage";
+  } reserve_projected_usage;
+  struct OolWrites : UnorderedStageT<OolWrites> {
+    constexpr static auto type_name = "UnorderedStage::ool_writes_stage";
+  } ool_writes;
+  struct Prepare : OrderedExclusivePhaseT<Prepare> {
+    constexpr static auto type_name = "WritePipeline::prepare_phase";
+  } prepare;
+  struct DeviceSubmission : OrderedConcurrentPhaseT<DeviceSubmission> {
+    constexpr static auto type_name = "WritePipeline::device_submission_phase";
+  } device_submission;
+  struct Finalize : OrderedExclusivePhaseT<Finalize> {
+    constexpr static auto type_name = "WritePipeline::finalize_phase";
+  } finalize;
+
+  using  BlockingEvents = std::tuple<
+    ReserveProjectedUsage::BlockingEvent,
+    OolWrites::BlockingEvent,
+    Prepare::BlockingEvent,
+    DeviceSubmission::BlockingEvent,
+    Finalize::BlockingEvent
+  >;
+};
+
 /**
  * PlaceholderOperation
  *
@@ -17,31 +44,85 @@ namespace crimson::os::seastore {
  * Until then (and for tests likely permanently) we'll use this unregistered
  * placeholder for the pipeline phases necessary for journal correctness.
  */
-class PlaceholderOperation : public Operation {
+class PlaceholderOperation : public crimson::osd::PhasedOperationT<PlaceholderOperation> {
 public:
-  using IRef = boost::intrusive_ptr<PlaceholderOperation>;
+  constexpr static auto type = 0U;
+  constexpr static auto type_name =
+    "crimson::os::seastore::PlaceholderOperation";
 
-  unsigned get_type() const final {
-    return 0;
+  static PlaceholderOperation::IRef create() {
+    return IRef{new PlaceholderOperation()};
   }
 
-  const char *get_type_name() const final {
-    return "crimson::os::seastore::PlaceholderOperation";
-  }
+  WritePipeline::BlockingEvents tracking_events;
 
 private:
   void dump_detail(ceph::Formatter *f) const final {}
   void print(std::ostream &) const final {}
 };
 
-struct OrderingHandle {
+struct OperationProxy {
   OperationRef op;
-  PipelineHandle phase_handle;
+  OperationProxy(OperationRef op) : op(std::move(op)) {}
+
+  virtual seastar::future<> enter(WritePipeline::ReserveProjectedUsage&) = 0;
+  virtual seastar::future<> enter(WritePipeline::OolWrites&) = 0;
+  virtual seastar::future<> enter(WritePipeline::Prepare&) = 0;
+  virtual seastar::future<> enter(WritePipeline::DeviceSubmission&) = 0;
+  virtual seastar::future<> enter(WritePipeline::Finalize&) = 0;
+
+  virtual void exit() = 0;
+  virtual seastar::future<> complete() = 0;
+
+  virtual ~OperationProxy() = default;
+};
+
+template <typename OpT>
+struct OperationProxyT : OperationProxy {
+  OperationProxyT(typename OpT::IRef op) : OperationProxy(op) {}
+
+  OpT* that() {
+    return static_cast<OpT*>(op.get());
+  }
+  const OpT* that() const {
+    return static_cast<const OpT*>(op.get());
+  }
+
+  seastar::future<> enter(WritePipeline::ReserveProjectedUsage& s) final {
+    return that()->enter_stage(s);
+  }
+  seastar::future<> enter(WritePipeline::OolWrites& s) final {
+    return that()->enter_stage(s);
+  }
+  seastar::future<> enter(WritePipeline::Prepare& s) final {
+    return that()->enter_stage(s);
+  }
+  seastar::future<> enter(WritePipeline::DeviceSubmission& s) final {
+    return that()->enter_stage(s);
+  }
+  seastar::future<> enter(WritePipeline::Finalize& s) final {
+    return that()->enter_stage(s);
+  }
+
+  void exit() final {
+    return that()->handle.exit();
+  }
+  seastar::future<> complete() final {
+    return that()->handle.complete();
+  }
+};
+
+struct OrderingHandle {
+  // we can easily optimize this dynalloc out as all concretes are
+  // supposed to have exactly the same size.
+  std::unique_ptr<OperationProxy> op;
   seastar::shared_mutex *collection_ordering_lock = nullptr;
 
-  OrderingHandle(OperationRef &&op) : op(std::move(op)) {}
+  // in the future we might add further constructors / template to type
+  // erasure while extracting the location of tracking events.
+  OrderingHandle(std::unique_ptr<OperationProxy> op) : op(std::move(op)) {}
   OrderingHandle(OrderingHandle &&other)
-    : op(std::move(other.op)), phase_handle(std::move(other.phase_handle)),
+    : op(std::move(other.op)),
       collection_ordering_lock(other.collection_ordering_lock) {
     other.collection_ordering_lock = nullptr;
   }
@@ -61,16 +142,15 @@ struct OrderingHandle {
 
   template <typename T>
   seastar::future<> enter(T &t) {
-    //return op->with_blocking_future(phase_handle.enter(t));
-    return seastar::now();
+    return op->enter(t);
   }
 
   void exit() {
-    return phase_handle.exit();
+    op->exit();
   }
 
   seastar::future<> complete() {
-    return phase_handle.complete();
+    return op->complete();
   }
 
   ~OrderingHandle() {
@@ -79,25 +159,19 @@ struct OrderingHandle {
 };
 
 inline OrderingHandle get_dummy_ordering_handle() {
-  return OrderingHandle{new PlaceholderOperation};
+  using PlaceholderOpProxy = OperationProxyT<PlaceholderOperation>;
+  return OrderingHandle{
+    std::make_unique<PlaceholderOpProxy>(PlaceholderOperation::create())};
 }
 
-struct WritePipeline {
-  OrderedExclusivePhase reserve_projected_usage{
-    "WritePipeline::reserve_projected_usage"
-  };
-  UnorderedStage ool_writes{
-    "UnorderedStage::ool_writes_stage"
-  };
-  OrderedExclusivePhase prepare{
-    "WritePipeline::prepare_phase"
-  };
-  OrderedConcurrentPhase device_submission{
-    "WritePipeline::device_submission_phase"
-  };
-  OrderedExclusivePhase finalize{
-    "WritePipeline::finalize_phase"
+} // namespace crimson::os::seastore
+
+namespace crimson {
+  template <>
+  struct EventBackendRegistry<os::seastore::PlaceholderOperation> {
+    static std::tuple<> get_backends() {
+      return {};
+    }
   };
-};
+} // namespace crimson
 
-}
index 66f2ef9eb77b46f34456d1dc71285a9901b5ec2d..f3e4f6386d0d3fa69ce8cce24341a4821d9d31d5 100644 (file)
@@ -8,6 +8,11 @@
 #include "crimson/osd/scheduler/scheduler.h"
 #include "osd/osd_types.h"
 
+namespace crimson::os::seastore {
+  template<class OpT>
+  class OperationProxyT;
+}
+
 namespace crimson::osd {
 
 enum class OperationTypeCode {
@@ -188,6 +193,9 @@ protected:
   }
 
   PipelineHandle handle;
+
+  template <class OpT>
+  friend class crimson::os::seastore::OperationProxyT;
 };
 
 /**