]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/mon: let reopen_session() return future<bool>
authorKefu Chai <kchai@redhat.com>
Tue, 2 Mar 2021 10:53:48 +0000 (18:53 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 2 Mar 2021 11:04:28 +0000 (19:04 +0800)
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 <kchai@redhat.com>
src/crimson/mon/MonClient.cc
src/crimson/mon/MonClient.h

index b42e98f885694f04ae3f28d58dc48e93481e45a8..13bb3cf9ff34fe17c81f3b618462fc11233ab29c 100644 (file)
@@ -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<unsigned> 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<bool> Client::reopen_session(int rank)
 {
   logger().info("{} to mon.{}", __func__, rank);
   vector<unsigned> 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;
     }
   });
 }
index f6bb75da3aa135cfd8cc7c1db9063efc387185b0..70222196f3303cfea696c9d074f27f85cdadf2dd 100644 (file)
@@ -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<bool> 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);