crimson/mon: extract mon::Client::_finish_auth()

for better readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-09-22 14:08:00 +08:00
parent e806c4085d
commit 70ba744667
2 changed files with 34 additions and 34 deletions

View 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 (result != Connection::AuthResult::canceled) {
_finish_auth(peer);
}
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();
}
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)

View 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