]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson: use lowres_system_clock for keepalive timestamps
authorKefu Chai <kchai@redhat.com>
Thu, 11 Apr 2019 08:55:47 +0000 (16:55 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 16 Apr 2019 14:14:11 +0000 (22:14 +0800)
we should use chrono types for representing time_point and duration,
utime_t could be used for the format on wire though.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/mon/MonClient.cc
src/crimson/net/Connection.h
src/crimson/net/ProtocolV2.cc
src/include/utime.h

index 7bcfd16cc20dd334031c2d2812f78a7f5305184f..f042275440ec7b04f6f27a4bf8ec681e970bec3b 100644 (file)
@@ -10,7 +10,6 @@
 #include "auth/AuthMethodList.h"
 #include "auth/RotatingKeyRing.h"
 
-#include "common/Clock.h"
 #include "common/hostname.h"
 
 #include "crimson/auth/KeyRing.h"
@@ -99,7 +98,8 @@ private:
   // v1
   seastar::promise<Ref<MAuthReply>> reply;
   // v2
-  utime_t auth_start;
+  using clock_t = seastar::lowres_system_clock;
+  clock_t::time_point auth_start;
   ceph::auth::method_t auth_method = 0;
   seastar::promise<> auth_done;
   AuthRegistry* auth_registry;
@@ -265,7 +265,7 @@ Connection::authenticate_v1(epoch_t epoch,
 
 seastar::future<> Connection::authenticate_v2()
 {
-  auth_start = ceph_clock_now();
+  auth_start = seastar::lowres_system_clock::now();
   return conn->send(make_message<MMonGetMap>()).then([this] {
     return auth_done.get_future();
   });
index b7481fc7db71a87fc5c1444bc09df21a46fc3098..32b057e1080659614645e5536d416bfabe67b522 100644 (file)
@@ -29,7 +29,9 @@ class Connection : public seastar::enable_shared_from_this<Connection> {
   entity_addr_t peer_addr;
   peer_type_t peer_type = -1;
   int64_t peer_id = -1;
-  utime_t last_keepalive, last_keepalive_ack;
+  using clock_t = seastar::lowres_system_clock;
+  clock_t::time_point last_keepalive;
+  clock_t::time_point last_keepalive_ack;
 
  public:
   uint64_t peer_global_id = 0;
@@ -60,14 +62,14 @@ class Connection : public seastar::enable_shared_from_this<Connection> {
 
   virtual void print(ostream& out) const = 0;
 
-  void set_last_keepalive(utime_t when) {
+  void set_last_keepalive(clock_t::time_point when) {
     last_keepalive = when;
   }
-  void set_last_keepalive_ack(utime_t when) {
+  void set_last_keepalive_ack(clock_t::time_point when) {
     last_keepalive_ack = when;
   }
-  utime_t get_last_keepalive() const { return last_keepalive; }
-  utime_t get_last_keepalive_ack() const { return last_keepalive_ack; }
+  auto get_last_keepalive() const { return last_keepalive; }
+  auto get_last_keepalive_ack() const { return last_keepalive_ack; }
 };
 
 inline ostream& operator<<(ostream& out, const Connection& conn) {
index c76fb0c8dedf056780523247810ac3d1a899f514..086914da95d6d0896bf90c42c696fe719429df16 100644 (file)
@@ -4,6 +4,8 @@
 #include "ProtocolV2.h"
 
 #include <seastar/core/lowres_clock.hh>
+#include <fmt/format.h>
+#include <fmt/time.h>
 
 #include "include/msgr.h"
 #include "include/random.h"
@@ -57,6 +59,36 @@ inline seastar::future<> unexpected_tag(const Tag& unexpected,
 
 } // namespace anonymous
 
+namespace fmt {
+template <>
+struct formatter<seastar::lowres_system_clock::time_point> {
+  // ignore the format string
+  template <typename ParseContext>
+  constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const seastar::lowres_system_clock::time_point& t,
+             FormatContext& ctx) {
+    struct tm bdt;
+    time_t tt = std::chrono::duration_cast<std::chrono::seconds>(
+      t.time_since_epoch()).count();
+    localtime_r(&tt, &bdt);
+    auto milliseconds = (t.time_since_epoch() %
+                        std::chrono::seconds(1)).count();
+    return format_to(ctx.out(), "{:%Y-%m-%d %H:%M:%S} {:03d}",
+                    bdt, milliseconds);
+  }
+};
+}
+
+namespace std {
+inline ostream& operator<<(
+  ostream& out, const seastar::lowres_system_clock::time_point& t)
+{
+  return out << fmt::format("{}", t);
+}
+}
+
 namespace ceph::net {
 
 ProtocolV2::ProtocolV2(Dispatcher& dispatcher,
@@ -1496,14 +1528,15 @@ void ProtocolV2::execute_ready()
               last_keepalive_ack_to_send = keepalive_frame.timestamp();
               logger().debug("{} got KEEPALIVE2 {}",
                              conn, last_keepalive_ack_to_send);
-              conn.last_keepalive = utime_t{seastar::lowres_system_clock::now()};
+              conn.set_last_keepalive(seastar::lowres_system_clock::now());
               notify_keepalive_ack();
             });
           case Tag::KEEPALIVE2_ACK:
             return read_frame_payload().then([this] {
               // handle_keepalive2_ack() logic
               auto keepalive_ack_frame = KeepAliveFrameAck::Decode(rx_segments_data.back());
-              conn.last_keepalive_ack = keepalive_ack_frame.timestamp();
+              conn.set_last_keepalive_ack(
+                seastar::lowres_system_clock::time_point{keepalive_ack_frame.timestamp()});
               logger().debug("{} got KEEPALIVE_ACK {}",
                              conn, conn.last_keepalive_ack);
             });
index b7327e0067e3661faeb0e674cf39285426bc501c..f2f88b55e0c8a9c470cee6500c4f89f7e6a4bbf5 100644 (file)
@@ -88,6 +88,11 @@ public:
     tv.tv_nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(
         t.time_since_epoch() % std::chrono::seconds(1)).count();
   }
+  explicit operator seastar::lowres_system_clock::time_point() const noexcept {
+    using clock_t = seastar::lowres_system_clock;
+    return clock_t::time_point{std::chrono::duration_cast<clock_t::duration>(
+      std::chrono::seconds{tv.tv_sec} + std::chrono::nanoseconds{tv.tv_nsec})};
+  }
 #endif
 
   utime_t(const struct timeval &v) {