From 70ba7446674dd192cbd1ae2df1c26d3c1513b87b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 22 Sep 2020 14:08:00 +0800 Subject: [PATCH] crimson/mon: extract mon::Client::_finish_auth() for better readability Signed-off-by: Kefu Chai --- src/crimson/mon/MonClient.cc | 67 ++++++++++++++++++------------------ src/crimson/mon/MonClient.h | 1 + 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 3d11747829516..5c9d4279a04fa 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -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& cmd, const bufferlist& bl) diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index 9a05e7ab78d42..0f651dd5d1769 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -163,6 +163,7 @@ private: seastar::future<> reopen_session(int rank); std::vector 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 -- 2.39.5