]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: add basic loggings for SocketConnection
authorYingxin <yingxin.cheng@intel.com>
Tue, 25 Dec 2018 06:01:54 +0000 (14:01 +0800)
committerYingxin <yingxincheng@gmail.com>
Thu, 3 Jan 2019 07:41:44 +0000 (15:41 +0800)
Signed-off-by: Yingxin <yingxin.cheng@intel.com>
src/crimson/net/Connection.h
src/crimson/net/Messenger.h
src/crimson/net/SocketConnection.cc
src/crimson/net/SocketConnection.h
src/crimson/net/SocketMessenger.h

index cc2f4eabf85771a826e0df13c8a22d2955760a87..4e4c1f4220f1ed977752455e1987251c58ef0453 100644 (file)
@@ -53,6 +53,15 @@ class Connection : public boost::intrusive_ref_counter<Connection,
 
   /// close the connection and cancel any any pending futures from read/send
   virtual seastar::future<> close() = 0;
+
+  virtual void print(ostream& out) const = 0;
 };
 
+inline ostream& operator<<(ostream& out, const Connection& conn) {
+  out << "[";
+  conn.print(out);
+  out << "]";
+  return out;
+}
+
 } // namespace ceph::net
index 0d8484fd2c21b4539c5e5d4344ec748fe12af24c..1e2b473a0f7affea84cc4723fbef8d2a05f45bb4 100644 (file)
@@ -71,6 +71,15 @@ class Messenger {
   void set_crc_header() {
     crc_flags |= MSG_CRC_HEADER;
   }
+
+  virtual void print(ostream& out) const = 0;
 };
 
+inline ostream& operator<<(ostream& out, const Messenger& msgr) {
+  out << "[";
+  msgr.print(out);
+  out << "]";
+  return out;
+}
+
 } // namespace ceph::net
index ef8281d5a79adb7e7e059d7b6c4cf1ebdda9a6c1..672062592401dc07e36d84284f49c696958ddc86 100644 (file)
@@ -95,7 +95,7 @@ void SocketConnection::read_tags_until_next_message()
             return handle_keepalive2_ack()
               .then([this] { return stop_t::no; });
           case CEPH_MSGR_TAG_CLOSE:
-            std::cout << "close" << std::endl;
+            logger().info("{} got tag close", *this);
             break;
           }
           return seastar::make_ready_future<stop_t>(stop_t::no);
@@ -322,6 +322,7 @@ seastar::future<> SocketConnection::close()
     ceph_assert(state == state_t::connecting);
     close_ready = pending_dispatch.close().finally(std::move(cleanup));
   }
+  logger().debug("{} trigger closing, was {}", *this, static_cast<int>(state));
   state = state_t::closing;
   return close_ready.get_future();
 }
@@ -543,7 +544,7 @@ SocketConnection::handle_keepalive2()
   return socket->read_exactly(sizeof(ceph_timespec))
     .then([this] (auto buf) {
       k.ack.stamp = *reinterpret_cast<const ceph_timespec*>(buf.get());
-      std::cout << "keepalive2 " << k.ack.stamp.tv_sec << std::endl;
+      logger().info("{} keepalive2 {}", *this, k.ack.stamp.tv_sec);
       return socket->write_flush(make_static_packet(k.ack));
     });
 }
@@ -555,7 +556,7 @@ SocketConnection::handle_keepalive2_ack()
     .then([this] (auto buf) {
       auto t = reinterpret_cast<const ceph_timespec*>(buf.get());
       k.ack_stamp = *t;
-      std::cout << "keepalive2 ack " << t->tv_sec << std::endl;
+      logger().info("{} keepalive2 ack {}", *this, t->tv_sec);
     });
 }
 
@@ -778,6 +779,7 @@ SocketConnection::start_connect(const entity_addr_t& _peer_addr,
   peer_addr = _peer_addr;
   peer_type = _peer_type;
   messenger.register_conn(this);
+  logger().debug("{} trigger connecting, was {}", *this, static_cast<int>(state));
   state = state_t::connecting;
   seastar::with_gate(pending_dispatch, [this] {
       return seastar::connect(peer_addr.in4_addr())
@@ -826,6 +828,7 @@ SocketConnection::start_connect(const entity_addr_t& _peer_addr,
           execute_open();
         }).handle_exception([this] (std::exception_ptr eptr) {
           // TODO: handle fault in the connecting state
+          logger().warn("{} connecting fault: {}", *this, eptr);
           close();
         });
     });
@@ -840,6 +843,7 @@ SocketConnection::start_accept(seastar::connected_socket&& fd,
   peer_addr = _peer_addr;
   socket.emplace(std::move(fd));
   messenger.accept_conn(this);
+  logger().debug("{} trigger accepting, was {}", *this, static_cast<int>(state));
   state = state_t::accepting;
   seastar::with_gate(pending_dispatch, [this] {
       // encode/send server's handshake header
@@ -878,6 +882,7 @@ SocketConnection::start_accept(seastar::connected_socket&& fd,
           execute_open();
         }).handle_exception([this] (std::exception_ptr eptr) {
           // TODO: handle fault in the accepting state
+          logger().warn("{} accepting fault: {}", *this, eptr);
           close();
         });
     });
@@ -886,6 +891,7 @@ SocketConnection::start_accept(seastar::connected_socket&& fd,
 void
 SocketConnection::execute_open()
 {
+  logger().debug("{} trigger open, was {}", *this, static_cast<int>(state));
   state = state_t::open;
   seastar::with_gate(pending_dispatch, [this] {
       // start background processing of tags
@@ -910,8 +916,9 @@ SocketConnection::execute_open()
           } else {
             throw e;
           }
-        }).handle_exception([] (std::exception_ptr eptr) {
+        }).handle_exception([this] (std::exception_ptr eptr) {
           // TODO: handle fault in the open state
+          logger().warn("{} open fault: {}", *this, eptr);
         });
     });
 }
@@ -931,3 +938,8 @@ seastar::future<> SocketConnection::fault()
   }
   return seastar::sleep(h.backoff);
 }
+
+void SocketConnection::print(ostream& out) const {
+    messenger.print(out);
+    out << " >> " << peer_addr;
+}
index effb594c14fa87a250b4046bed0527b4ffb78001..38713eb40b58090a422c78637a55c764d6823c66 100644 (file)
@@ -175,6 +175,8 @@ class SocketConnection : public Connection {
 
   seastar::future<> close() override;
 
+  void print(ostream& out) const override;
+
  public:
   /// start a handshake from the client's perspective,
   /// only call when SocketConnection first construct
index c348f5920b329cb5dc7882bad19193eb88bf9591..06941fba96435a606f6b4594208b8d8985426ca4 100644 (file)
@@ -52,6 +52,11 @@ class SocketMessenger final : public Messenger {
 
   seastar::future<> shutdown() override;
 
+  void print(ostream& out) const override {
+    out << get_myname()
+        << " " << get_myaddr();
+  }
+
  public:
   void set_default_policy(const SocketPolicy& p);
   void set_policy(entity_type_t peer_type, const SocketPolicy& p);