]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: create_n_propagate
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 11 Dec 2019 09:13:41 +0000 (10:13 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 13 Feb 2020 23:11:40 +0000 (00:11 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/osd/ops_executer.cc
src/crimson/osd/watch.h

index 130663dd9ef41b005a9828ffea4c95c35c5bb624..c1191f0c817a789897c6bad83a8e6da4bbf11fdb 100644 (file)
@@ -295,7 +295,15 @@ OpsExecuter::watch_errorator::future<> OpsExecuter::do_op_notify(
       return seastar::now();
     },
     [] (auto&& ctx, ObjectContextRef obc) {
-      return seastar::now();
+      auto alive_watchers = obc->watchers | boost::adaptors::map_values
+                                          | boost::adaptors::filtered(
+        [] (const auto& w) {
+          // FIXME: filter as for the `is_ping` in `Watch::start_notify`
+          return w->is_alive();
+        });
+      return crimson::osd::Notify::create_n_propagate(
+        std::begin(alive_watchers),
+        std::end(alive_watchers));
   });
 }
 
index ed8f4a84b153533348070ca5bb847c05df70d41d..f26c9cb1620fc7e7d7ddbc332f1e7f804a3ba39e 100644 (file)
@@ -3,12 +3,18 @@
 
 #pragma once
 
+#include <iterator>
+#include <set>
+
 #include <seastar/core/shared_ptr.hh>
 
 #include "crimson/net/Connection.h"
 
 namespace crimson::osd {
 
+class Notify;
+using NotifyRef = seastar::shared_ptr<Notify>;
+
 // NOTE: really need to have this public. Otherwise `shared_from_this()`
 // will abort. According to cppreference.com:
 //
@@ -23,15 +29,27 @@ class Watch : public seastar::enable_shared_from_this<Watch> {
   // used by create().
   struct private_ctag_t{};
 
+  struct NotifyCmp {
+    inline bool operator()(NotifyRef lhs, NotifyRef rhs) const;
+  };
+  std::set<NotifyRef, NotifyCmp> in_progress_notifies;
+  crimson::net::ConnectionRef conn;
+
+  seastar::future<> start_notify(NotifyRef);
+  seastar::future<> send_notify_msg(NotifyRef);
+
+  friend Notify;
+
 public:
   Watch(private_ctag_t) {
   }
 
-  seastar::future<> connect(crimson::net::ConnectionRef, bool) {
-    return seastar::now();
+  seastar::future<> connect(crimson::net::ConnectionRef, bool);
+  bool is_alive() const {
+    return true;
   }
   bool is_connected() const {
-    return true;
+    return static_cast<bool>(conn);
   }
   void got_ping(utime_t) {
     // NOP
@@ -57,4 +75,52 @@ public:
 
 using WatchRef = seastar::shared_ptr<Watch>;
 
+class Notify {
+  std::set<WatchRef> watchers;
+
+  uint64_t get_id() const { return 0; }
+  void propagate() {}
+
+  template <class WatchIteratorT>
+  Notify(WatchIteratorT begin, WatchIteratorT end);
+  // this is a private tag for the public constructor that turns it into
+  // de facto private one. The motivation behind the hack is make_shared
+  // used by create_n_propagate factory.
+  struct private_ctag_t{};
+
+  friend Watch;
+
+public:
+  template <class... Args>
+  Notify(private_ctag_t, Args&&... args) : Notify(std::forward<Args>(args)...) {
+  }
+
+  template <class WatchIteratorT>
+  static seastar::future<> create_n_propagate(
+    WatchIteratorT begin,
+    WatchIteratorT end);
+};
+
+
+template <class WatchIteratorT>
+Notify::Notify(WatchIteratorT begin, WatchIteratorT end)
+  : watchers(begin, end) {
+}
+
+template <class WatchIteratorT>
+seastar::future<> Notify::create_n_propagate(
+  WatchIteratorT begin,
+  WatchIteratorT end)
+{
+  static_assert(
+    std::is_same_v<typename std::iterator_traits<WatchIteratorT>::value_type,
+                   crimson::osd::WatchRef>);
+  auto notify = seastar::make_shared<Notify>(private_ctag_t{}, begin, end);
+  seastar::do_for_each(begin, end, [=] (auto& watchref) {
+    return watchref->start_notify(notify);
+  }).then([notify = std::move(notify)] {;
+    notify->propagate();
+  });
+}
+
 } // namespace crimson::osd