]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: add ChainedDispatchers
authorKefu Chai <kchai@redhat.com>
Fri, 11 Jan 2019 09:53:15 +0000 (17:53 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 18 Jan 2019 04:36:59 +0000 (12:36 +0800)
it will be used to glue multiple dispatchers for subscribing events
emitted by messenger

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/CMakeLists.txt
src/crimson/osd/chained_dispatchers.cc [new file with mode: 0644]
src/crimson/osd/chained_dispatchers.h [new file with mode: 0644]

index 2c109366460966e218190101caab02f0bdae238a..9121bc1025da01d33876c306697b7dd553531ba0 100644 (file)
@@ -1,5 +1,6 @@
 add_executable(crimson-osd
   main.cc
-  osd.cc)
+  osd.cc
+  chained_dispatchers.cc)
 target_link_libraries(crimson-osd
   crimson-common crimson-os crimson)
diff --git a/src/crimson/osd/chained_dispatchers.cc b/src/crimson/osd/chained_dispatchers.cc
new file mode 100644 (file)
index 0000000..9f1b0f7
--- /dev/null
@@ -0,0 +1,75 @@
+#include "chained_dispatchers.h"
+#include "crimson/net/Connection.h"
+
+
+seastar::future<>
+ChainedDispatchers::ms_dispatch(ceph::net::ConnectionRef conn,
+                                MessageRef m) {
+  return seastar::do_for_each(dispatchers, [conn, m](Dispatcher* dispatcher) {
+    return dispatcher->ms_dispatch(conn, m);
+  });
+}
+
+seastar::future<>
+ChainedDispatchers::ms_handle_accept(ceph::net::ConnectionRef conn) {
+  return seastar::do_for_each(dispatchers, [conn](Dispatcher* dispatcher) {
+    return dispatcher->ms_handle_accept(conn);
+  });
+}
+
+seastar::future<>
+ChainedDispatchers::ms_handle_connect(ceph::net::ConnectionRef conn) {
+  return seastar::do_for_each(dispatchers, [conn](Dispatcher* dispatcher) {
+    return dispatcher->ms_handle_connect(conn);
+  });
+}
+
+seastar::future<>
+ChainedDispatchers::ms_handle_reset(ceph::net::ConnectionRef conn) {
+  return seastar::do_for_each(dispatchers, [conn](Dispatcher* dispatcher) {
+    return dispatcher->ms_handle_reset(conn);
+  });
+}
+
+seastar::future<>
+ChainedDispatchers::ms_handle_remote_reset(ceph::net::ConnectionRef conn) {
+  return seastar::do_for_each(dispatchers, [conn](Dispatcher* dispatcher) {
+    return dispatcher->ms_handle_remote_reset(conn);
+  });
+}
+
+seastar::future<std::unique_ptr<AuthAuthorizer>>
+ChainedDispatchers::ms_get_authorizer(peer_type_t peer_type, bool force_new)
+{
+  // since dispatcher returns a nullptr if it does not have the authorizer,
+  // let's use the chain-of-responsibility pattern here.
+  struct Params {
+    peer_type_t peer_type;
+    bool force_new;
+    std::deque<Dispatcher*>::iterator first, last;
+  } params = {peer_type, force_new,
+              dispatchers.begin(), dispatchers.end()};
+  return seastar::do_with(Params{params}, [this] (Params& params) {
+    using result_t = std::unique_ptr<AuthAuthorizer>;
+    return seastar::repeat_until_value([&] () {
+      auto& first = params.first;
+      if (first == params.last) {
+        // just give up
+        return seastar::make_ready_future<std::optional<result_t>>(result_t{});
+      } else {
+        return (*first)->ms_get_authorizer(params.peer_type,
+                                           params.force_new)
+          .then([&] (auto&& auth)-> std::optional<result_t> {
+          if (auth) {
+            // hooray!
+            return std::move(auth);
+          } else {
+            // try next one
+            ++first;
+            return {};
+          }
+        });
+      }
+    });
+  });
+}       
diff --git a/src/crimson/osd/chained_dispatchers.h b/src/crimson/osd/chained_dispatchers.h
new file mode 100644 (file)
index 0000000..a287e50
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*- 
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <deque>
+#include "crimson/net/Dispatcher.h"
+
+// in existing Messenger, dispatchers are put into a chain as described by
+// chain-of-responsibility pattern. we could do the same to stop processing
+// the message once any of the dispatchers claims this message, and prevent
+// other dispatchers from reading it. but this change is more involved as
+// it requires changing the ms_ methods to return a bool. so as an intermediate 
+// solution, we are using an observer dispatcher to notify all the interested
+// or unintersted parties.
+class ChainedDispatchers : public ceph::net::Dispatcher {
+  std::deque<Dispatcher*> dispatchers;
+public:
+  void push_front(Dispatcher* dispatcher) {
+    dispatchers.push_front(dispatcher);
+  }
+  void push_back(Dispatcher* dispatcher) {
+    dispatchers.push_back(dispatcher);
+  }
+  seastar::future<> ms_dispatch(ceph::net::ConnectionRef conn, MessageRef m) override;
+  seastar::future<> ms_handle_accept(ceph::net::ConnectionRef conn) override;
+  seastar::future<> ms_handle_connect(ceph::net::ConnectionRef conn) override;
+  seastar::future<> ms_handle_reset(ceph::net::ConnectionRef conn) override;
+  seastar::future<> ms_handle_remote_reset(ceph::net::ConnectionRef conn) override;
+  seastar::future<std::unique_ptr<AuthAuthorizer>>
+  ms_get_authorizer(peer_type_t peer_type, bool force_new) override;
+};