From 6b6537d5b15546f9d32ba8c7076c154a084e75a0 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 2 Mar 2021 18:53:48 +0800 Subject: [PATCH] crimson/mon: let reopen_session() return future this change is for improve the readability. to emphasis that the next steps are performed only if a connection to monitor is established. Signed-off-by: Kefu Chai --- src/crimson/mon/MonClient.cc | 19 +++++++++++-------- src/crimson/mon/MonClient.h | 6 +++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index b42e98f8856..13bb3cf9ff3 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -516,8 +516,8 @@ void Client::ms_handle_reset(crimson::net::ConnectionRef conn, bool /* is_replac } else if (active_con && active_con->is_my_peer(conn->get_peer_addr())) { logger().warn("active conn reset {}", conn->get_peer_addr()); active_con.reset(); - return reopen_session(-1).then([this] { - if (active_con) { + return reopen_session(-1).then([this](bool opened) { + if (opened) { return on_session_opened(); } else { return seastar::now(); @@ -760,8 +760,8 @@ seastar::future<> Client::handle_monmap(crimson::net::ConnectionRef conn, } } else { logger().warn("mon.{} went away", cur_mon); - return reopen_session(-1).then([this] { - if (active_con) { + return reopen_session(-1).then([this](bool opened) { + if (opened) { return on_session_opened(); } else { return seastar::now(); @@ -886,8 +886,8 @@ std::vector Client::get_random_mons(unsigned n) const seastar::future<> Client::authenticate() { - return reopen_session(-1).then([this] { - if (active_con) { + return reopen_session(-1).then([this](bool opened) { + if (opened) { return on_session_opened(); } else { return seastar::now(); @@ -925,7 +925,7 @@ static entity_addr_t choose_client_addr( return entity_addr_t{}; } -seastar::future<> Client::reopen_session(int rank) +seastar::future Client::reopen_session(int rank) { logger().info("{} to mon.{}", __func__, rank); vector mons; @@ -963,8 +963,11 @@ seastar::future<> Client::reopen_session(int rank) return seastar::make_exception_future(ep); }); }).then([this] { - if (!active_con) { + if (active_con) { + return true; + } else { logger().warn("cannot establish the active_con with any mon"); + return false; } }); } diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index f6bb75da3aa..70222196f33 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -168,7 +168,11 @@ private: seastar::future<> authenticate(); bool is_hunting() const; - seastar::future<> reopen_session(int rank); + // @param rank, rank of the monitor to be connected, if it is less than 0, + // try to connect to all monitors in monmap, until one of them + // is connected. + // @return true if a connection is established to a monitor + 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); -- 2.39.5