]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/net: move is_connected() from ProtocolV2 to Protocol
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 5 Dec 2022 08:30:25 +0000 (16:30 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Wed, 8 Feb 2023 06:07:41 +0000 (14:07 +0800)
Infer is_connected by connection events instead of the protocol V2
internals. That can save a cross-core operation for connection users
from the connection IO core to the handshake core.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/net/Protocol.cc
src/crimson/net/Protocol.h
src/crimson/net/ProtocolV2.cc
src/crimson/net/ProtocolV2.h
src/crimson/osd/heartbeat.cc

index b20af96097bc66909c1dae8ab86bb26385bb9bd4..12985bc7e001f0ce260340a006276d5fec4ca5a3 100644 (file)
@@ -151,6 +151,7 @@ void Protocol::set_out_state(
   bool dispatch_in = false;
   if (new_state == out_state_t::open) {
     // to open
+    ceph_assert_always(protocol_is_connected == true);
     assert(fa != nullptr);
     ceph_assert_always(frame_assembler == nullptr);
     frame_assembler = std::move(fa);
@@ -163,6 +164,8 @@ void Protocol::set_out_state(
 #endif
   } else if (out_state == out_state_t::open) {
     // from open
+    ceph_assert_always(protocol_is_connected == true);
+    protocol_is_connected = false;
     assert(fa == nullptr);
     ceph_assert_always(frame_assembler->is_socket_valid());
     frame_assembler->shutdown_socket();
@@ -271,12 +274,17 @@ void Protocol::reset_out()
 
 void Protocol::dispatch_accept()
 {
+  // protocol_is_connected can be from true to true here if the replacing is
+  // happening to a connected connection.
+  protocol_is_connected = true;
   dispatchers.ms_handle_accept(
     seastar::static_pointer_cast<SocketConnection>(conn.shared_from_this()));
 }
 
 void Protocol::dispatch_connect()
 {
+  ceph_assert_always(protocol_is_connected == false);
+  protocol_is_connected = true;
   dispatchers.ms_handle_connect(
     seastar::static_pointer_cast<SocketConnection>(conn.shared_from_this()));
 }
index c107bee66fd152f13a1b629e056358d6ed977b9a..4446e1781fbb1eeb4737f9ccaeadcd58494942d9 100644 (file)
@@ -21,8 +21,6 @@ class Protocol {
   Protocol(Protocol&&) = delete;
   virtual ~Protocol();
 
-  virtual bool is_connected() const = 0;
-
   virtual void close() = 0;
 
   virtual seastar::future<> close_clean_yielded() = 0;
@@ -53,6 +51,10 @@ class Protocol {
  public:
   using clock_t = seastar::lowres_system_clock;
 
+  bool is_connected() const {
+    return protocol_is_connected;
+  }
+
   seastar::future<> send(MessageURef msg);
 
   seastar::future<> send_keepalive();
@@ -168,6 +170,8 @@ class Protocol {
 
   FrameAssemblerV2Ref frame_assembler;
 
+  bool protocol_is_connected = false;
+
   /*
    * out states for writing
    */
index 875b3c257724d228d10fe207d17492062a8d320b..76e21de048463e2a3fe260b464f6dc3f94e86bc0 100644 (file)
@@ -166,12 +166,6 @@ ProtocolV2::ProtocolV2(ChainedDispatchers& dispatchers,
 
 ProtocolV2::~ProtocolV2() {}
 
-bool ProtocolV2::is_connected() const {
-  return state == state_t::READY ||
-         state == state_t::ESTABLISHING ||
-         state == state_t::REPLACING;
-}
-
 void ProtocolV2::start_connect(const entity_addr_t& _peer_addr,
                                const entity_name_t& _peer_name)
 {
index 12c1a63878acfc7859e813fff2bc3726eef3a1aa..ec4d26468139fd84550990336c2023d3e9ce8bff 100644 (file)
@@ -19,8 +19,6 @@ class ProtocolV2 final : public Protocol {
 
 // public to SocketConnection, but private to the others
  private:
-  bool is_connected() const override;
-
   void close() override;
 
   seastar::future<> close_clean_yielded() override;
index b4cdba6f2f213f4801f4f7cad6b15492cb988cbf..94b3d688627bcefdea7f4c40d83595aebba4b112 100644 (file)
@@ -406,7 +406,6 @@ void Heartbeat::Connection::replaced()
   racing_detected = true;
   logger().warn("Heartbeat::Connection::replaced(): {} racing", *this);
   assert(conn != replaced_conn);
-  assert(conn->is_connected());
 }
 
 void Heartbeat::Connection::reset()