]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/osd: differentiate Notify with and without watchers
authorKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 13:23:54 +0000 (21:23 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 13:41:51 +0000 (21:41 +0800)
we don't need to arm the timer, if there is no watchers.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/watch.cc
src/crimson/osd/watch.h

index 590e992277727143e55f74277be385f05483fbab..261bd18040cb8ad7173c7461314e28d6c9b9b158 100644 (file)
@@ -128,6 +128,16 @@ std::ostream &operator<<(std::ostream &out, const notify_reply_t &rhs)
   return out;
 }
 
+Notify::Notify(crimson::net::ConnectionRef conn,
+               const notify_info_t& ninfo,
+               const uint64_t client_gid,
+               const uint64_t user_version)
+  : ninfo(ninfo),
+    conn(std::move(conn)),
+    client_gid(client_gid),
+    user_version(user_version)
+{}
+
 seastar::future<> Notify::remove_watcher(WatchRef watch)
 {
   if (discarded || complete) {
index b654efa41c436c9822108119c346660c762065b9..d9f7325d3accacb1d4d2f5669a6116e6d51eca98 100644 (file)
@@ -130,6 +130,10 @@ class Notify {
   /// Called on Notify timeout
   void do_timeout();
 
+  Notify(crimson::net::ConnectionRef conn,
+         const notify_info_t& ninfo,
+         const uint64_t client_gid,
+         const uint64_t user_version);
   template <class WatchIteratorT>
   Notify(WatchIteratorT begin,
          WatchIteratorT end,
@@ -188,6 +192,7 @@ Notify::Notify(WatchIteratorT begin,
     conn(std::move(conn)),
     client_gid(client_gid),
     user_version(user_version) {
+  assert(!std::empty(watchers));
   if (ninfo.timeout) {
     timeout_timer.arm(std::chrono::seconds{ninfo.timeout});
   }
@@ -202,14 +207,16 @@ seastar::future<> Notify::create_n_propagate(
   static_assert(
     std::is_same_v<typename std::iterator_traits<WatchIteratorT>::value_type,
                    crimson::osd::WatchRef>);
-  auto notify = seastar::make_shared<Notify>(
-    private_ctag_t{},
-    begin,
-    end,
-    std::forward<Args>(args)...);
   if (begin == end) {
+    auto notify = seastar::make_shared<Notify>(
+      private_ctag_t{},
+      std::forward<Args>(args)...);
     return notify->send_completion();
   } else {
+    auto notify = seastar::make_shared<Notify>(
+      private_ctag_t{},
+      begin, end,
+      std::forward<Args>(args)...);
     return seastar::do_for_each(begin, end, [=] (auto& watchref) {
       return watchref->start_notify(notify);
     });