From: Yingxin Date: Tue, 25 Dec 2018 06:01:54 +0000 (+0800) Subject: crimson/net: add basic loggings for SocketConnection X-Git-Tag: v14.1.0~513^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7a2f4bf92503ff792413bd9d446f04ba6d21decf;p=ceph.git crimson/net: add basic loggings for SocketConnection Signed-off-by: Yingxin --- diff --git a/src/crimson/net/Connection.h b/src/crimson/net/Connection.h index cc2f4eabf857..4e4c1f4220f1 100644 --- a/src/crimson/net/Connection.h +++ b/src/crimson/net/Connection.h @@ -53,6 +53,15 @@ class Connection : public boost::intrusive_ref_counter 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 diff --git a/src/crimson/net/Messenger.h b/src/crimson/net/Messenger.h index 0d8484fd2c21..1e2b473a0f7a 100644 --- a/src/crimson/net/Messenger.h +++ b/src/crimson/net/Messenger.h @@ -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 diff --git a/src/crimson/net/SocketConnection.cc b/src/crimson/net/SocketConnection.cc index ef8281d5a79a..672062592401 100644 --- a/src/crimson/net/SocketConnection.cc +++ b/src/crimson/net/SocketConnection.cc @@ -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::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(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(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(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(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(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(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; +} diff --git a/src/crimson/net/SocketConnection.h b/src/crimson/net/SocketConnection.h index effb594c14fa..38713eb40b58 100644 --- a/src/crimson/net/SocketConnection.h +++ b/src/crimson/net/SocketConnection.h @@ -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 diff --git a/src/crimson/net/SocketMessenger.h b/src/crimson/net/SocketMessenger.h index c348f5920b32..06941fba9643 100644 --- a/src/crimson/net/SocketMessenger.h +++ b/src/crimson/net/SocketMessenger.h @@ -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);