]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/mon: extract mon::Client::_finish_auth()
authorKefu Chai <kchai@redhat.com>
Tue, 22 Sep 2020 06:08:00 +0000 (14:08 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 22 Sep 2020 09:07:47 +0000 (17:07 +0800)
for better readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/mon/MonClient.cc
src/crimson/mon/MonClient.h

index 3d11747829516f33e504edf486b8e1d98b7039cc..5c9d4279a04fa50e395be69da6918a8e0c1ce703 100644 (file)
@@ -975,41 +975,9 @@ seastar::future<> Client::reopen_session(int rank)
           });
       }
     }).then([peer, this](auto result) {
-      if (result == Connection::AuthResult::canceled) {
-       return seastar::now();
-      }
-
-      if (!is_hunting()) {
-        return seastar::now();
-      }
-      logger().info("found mon.{}", monmap.get_name(peer));
-
-      auto found = std::find_if(
-       pending_conns.begin(), pending_conns.end(),
-       [peer](auto& conn) {
-         return conn->is_my_peer(peer);
-       });
-      if (found == pending_conns.end()) {
-       // Happens if another connection has won the race
-       ceph_assert(active_con && pending_conns.empty());
-       logger().info(
-         "no pending connection for mon.{}, peer {}",
-         monmap.get_name(peer),
-         peer);
-       return seastar::now();
+      if (result != Connection::AuthResult::canceled) {
+        _finish_auth(peer);
       }
-
-      ceph_assert(!active_con && !pending_conns.empty());
-      active_con = std::move(*found);
-      found->reset();
-      for (auto& conn : pending_conns) {
-        if (conn) {
-          conn->close();
-        }
-      }
-      pending_conns.clear();
-      return seastar::now();
-    }).then([]() {
       logger().debug("reopen_session mon connection attempts complete");
     }).handle_exception([](auto ep) {
       logger().error("mon connections failed with ep {}", ep);
@@ -1024,6 +992,37 @@ seastar::future<> Client::reopen_session(int rank)
   });
 }
 
+void Client::_finish_auth(const entity_addr_t& peer)
+{
+  if (!is_hunting()) {
+    return;
+  }
+  logger().info("found mon.{}", monmap.get_name(peer));
+
+  auto found = std::find_if(
+    pending_conns.begin(), pending_conns.end(),
+    [peer](auto& conn) {
+      return conn->is_my_peer(peer);
+  });
+  if (found == pending_conns.end()) {
+    // Happens if another connection has won the race
+    ceph_assert(active_con && pending_conns.empty());
+    logger().info("no pending connection for mon.{}, peer {}",
+      monmap.get_name(peer), peer);
+    return;
+  }
+
+  ceph_assert(!active_con && !pending_conns.empty());
+  active_con = std::move(*found);
+  found->reset();
+  for (auto& conn : pending_conns) {
+    if (conn) {
+      conn->close();
+    }
+  }
+  pending_conns.clear();
+}
+
 Client::command_result_t
 Client::run_command(const std::vector<std::string>& cmd,
                     const bufferlist& bl)
index 9a05e7ab78d42f1fb2b2a6527c7e221073b405ae..0f651dd5d1769c68401c5d15e3a03d9159187732 100644 (file)
@@ -163,6 +163,7 @@ private:
   seastar::future<> reopen_session(int rank);
   std::vector<unsigned> get_random_mons(unsigned n) const;
   seastar::future<> _add_conn(unsigned rank, uint64_t global_id);
+  void _finish_auth(const entity_addr_t& peer);
   crimson::common::Gated gate;
 
   // messages that are waiting for the active_con to be available