crimson/net: compatible mode of crimson-msgr
authorYingxin Cheng <yingxincheng@gmail.com>
Wed, 23 Jan 2019 03:37:57 +0000 (11:37 +0800)
committerYingxin Cheng <yingxincheng@gmail.com>
Tue, 12 Feb 2019 08:48:02 +0000 (16:48 +0800)
Added a compatible mode with master_sid to support single-core
dispatcher.

Signed-off-by: Yingxin Cheng <yingxincheng@gmail.com>
src/crimson/net/Messenger.cc
src/crimson/net/Messenger.h
src/crimson/net/SocketMessenger.cc
src/crimson/net/SocketMessenger.h

index bd6c48b402241e322b3fdf6a3363e409a48bdad6..7f8665ef4a8ea15bb586b0d73e4655c751b683a7 100644 (file)
@@ -9,9 +9,10 @@ namespace ceph::net {
 seastar::future<Messenger*>
 Messenger::create(const entity_name_t& name,
                   const std::string& lname,
-                  const uint64_t nonce)
+                  const uint64_t nonce,
+                  const int master_sid)
 {
-  return create_sharded<SocketMessenger>(name, lname, nonce)
+  return create_sharded<SocketMessenger>(name, lname, nonce, master_sid)
     .then([](Messenger *msgr) {
       return msgr;
     });
index a8669f4fb0be6a6e5a7dce299aee3adbdfd2d095..e9e0de3539cfdaf02468b13a7a14b68a235d53f5 100644 (file)
@@ -90,7 +90,10 @@ class Messenger {
   virtual void print(ostream& out) const = 0;
 
   static seastar::future<Messenger*>
-  create(const entity_name_t& name, const std::string& lname, const uint64_t nonce);
+  create(const entity_name_t& name,
+         const std::string& lname,
+         const uint64_t nonce,
+         const int master_sid=-1);
 };
 
 inline ostream& operator<<(ostream& out, const Messenger& msgr) {
index c49729e8c37425122c46c5b37e2efee03a9f4a97..46a38ff7ebc9d93f8543b30145dddef0d8be8865 100644 (file)
@@ -32,8 +32,10 @@ namespace {
 
 SocketMessenger::SocketMessenger(const entity_name_t& myname,
                                  const std::string& logic_name,
-                                 uint32_t nonce)
+                                 uint32_t nonce,
+                                 int master_sid)
   : Messenger{myname},
+    master_sid{master_sid},
     sid{seastar::engine().cpu_id()},
     logic_name{logic_name},
     nonce{nonce}
@@ -231,6 +233,9 @@ void SocketMessenger::set_policy_throttler(entity_type_t peer_type,
 seastar::shard_id SocketMessenger::locate_shard(const entity_addr_t& addr)
 {
   ceph_assert(addr.get_family() == AF_INET);
+  if (master_sid >= 0) {
+    return master_sid;
+  }
   std::size_t seed = 0;
   boost::hash_combine(seed, addr.u.sin.sin_addr.s_addr);
   //boost::hash_combine(seed, addr.u.sin.sin_port);
@@ -260,6 +265,9 @@ void SocketMessenger::unaccept_conn(SocketConnectionRef conn)
 
 void SocketMessenger::register_conn(SocketConnectionRef conn)
 {
+  if (master_sid >= 0) {
+    ceph_assert(static_cast<int>(sid) == master_sid);
+  }
   auto [i, added] = connections.emplace(conn->get_peer_addr(), conn);
   std::ignore = i;
   ceph_assert(added);
index 20b0ad56e93f0a7e84355c56f79f9f94d5cbb51a..2a769ce69c5e3014df67eaa75af6618fdfc7111f 100644 (file)
@@ -31,6 +31,7 @@ namespace ceph::net {
 using SocketPolicy = ceph::net::Policy<ceph::thread::Throttle>;
 
 class SocketMessenger final : public Messenger, public seastar::peering_sharded_service<SocketMessenger> {
+  const int master_sid;
   const seastar::shard_id sid;
   seastar::promise<> shutdown_promise;
 
@@ -53,15 +54,17 @@ class SocketMessenger final : public Messenger, public seastar::peering_sharded_
                                                  const entity_type_t& peer_type);
   seastar::future<> do_shutdown();
   // conn sharding options:
-  // 1. Simplest: sharded by ip only
-  // 2. Balanced: sharded by ip + port + nonce,
+  // 0. Compatible (master_sid >= 0): place all connections to one master shard
+  // 1. Simplest (master_sid < 0): sharded by ip only
+  // 2. Balanced (not implemented): sharded by ip + port + nonce,
   //        but, need to move SocketConnection between cores.
   seastar::shard_id locate_shard(const entity_addr_t& addr);
 
  public:
   SocketMessenger(const entity_name_t& myname,
                   const std::string& logic_name,
-                  uint32_t nonce);
+                  uint32_t nonce,
+                  int master_sid);
 
   seastar::future<> set_myaddrs(const entity_addrvec_t& addr) override;