]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: factor out "maybe" from maybe_send_completion()
authorKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 13:04:52 +0000 (21:04 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 7 Mar 2021 13:04:55 +0000 (21:04 +0800)
for better readability

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

index bcf535ab1c630adb292fa94a1e0449856c15feab..590e992277727143e55f74277be385f05483fbab 100644 (file)
@@ -135,7 +135,11 @@ seastar::future<> Notify::remove_watcher(WatchRef watch)
   }
   [[maybe_unused]] const auto num_removed = watchers.erase(watch);
   assert(num_removed > 0);
-  return maybe_send_completion();
+  if (watchers.empty()) {
+    return send_completion();
+  } else {
+    return seastar::now();
+  }
 }
 
 
@@ -153,43 +157,40 @@ seastar::future<> Notify::complete_watcher(
   return remove_watcher(std::move(watch));
 }
 
-seastar::future<> Notify::maybe_send_completion(
+seastar::future<> Notify::send_completion(
   std::set<WatchRef> timedout_watchers)
 {
   logger().info("{} -- {} in progress watchers, {} timedout watchers {}",
                 __func__, watchers.size(), timedout_watchers.size());
-  if (watchers.empty() || !timedout_watchers.empty()) {
-    logger().debug("{} sending notify replies: {}", __func__, notify_replies);
-    complete = true;
-    timeout_timer.cancel();
-
-    ceph::bufferlist empty;
-    auto reply = make_message<MWatchNotify>(
-      ninfo.cookie,
-      user_version,
-      ninfo.notify_id,
-      CEPH_WATCH_EVENT_NOTIFY_COMPLETE,
-      empty,
-      client_gid);
-    ceph::bufferlist reply_bl;
-    {
-      std::vector<std::pair<uint64_t,uint64_t>> missed;
-      missed.reserve(std::size(timedout_watchers));
-      boost::insert(
-       missed, std::begin(missed),
-       timedout_watchers | boost::adaptors::transformed([] (auto w) {
-          return std::make_pair(w->get_watcher_gid(), w->get_cookie());
-        }));
-      ceph::encode(notify_replies, reply_bl);
-      ceph::encode(missed, reply_bl);
-    }
-    reply->set_data(std::move(reply_bl));
-    if (!timedout_watchers.empty()) {
-      reply->return_code = -ETIMEDOUT;
-    }
-    return conn->send(std::move(reply));
+  logger().debug("{} sending notify replies: {}", __func__, notify_replies);
+  complete = true;
+  timeout_timer.cancel();
+
+  ceph::bufferlist empty;
+  auto reply = make_message<MWatchNotify>(
+    ninfo.cookie,
+    user_version,
+    ninfo.notify_id,
+    CEPH_WATCH_EVENT_NOTIFY_COMPLETE,
+    empty,
+    client_gid);
+  ceph::bufferlist reply_bl;
+  {
+    std::vector<std::pair<uint64_t,uint64_t>> missed;
+    missed.reserve(std::size(timedout_watchers));
+    boost::insert(
+      missed, std::begin(missed),
+      timedout_watchers | boost::adaptors::transformed([] (auto w) {
+        return std::make_pair(w->get_watcher_gid(), w->get_cookie());
+      }));
+    ceph::encode(notify_replies, reply_bl);
+    ceph::encode(missed, reply_bl);
   }
-  return seastar::now();
+  reply->set_data(std::move(reply_bl));
+  if (!timedout_watchers.empty()) {
+    reply->return_code = -ETIMEDOUT;
+  }
+  return conn->send(std::move(reply));
 }
 
 void Notify::do_timeout()
@@ -201,7 +202,7 @@ void Notify::do_timeout()
   for (auto& watcher : watchers) {
     watcher->cancel_notify(ninfo.notify_id);
   }
-  std::ignore = maybe_send_completion(std::move(watchers));
+  std::ignore = send_completion(std::move(watchers));
   watchers.clear();
 }
 
index 3632f427280c9246cf9f4365d24a9060a998d75a..b654efa41c436c9822108119c346660c762065b9 100644 (file)
@@ -124,7 +124,7 @@ class Notify {
   uint64_t get_id() const { return ninfo.notify_id; }
 
   /// Sends notify completion if watchers.empty() or timeout
-  seastar::future<> maybe_send_completion(
+  seastar::future<> send_completion(
     std::set<WatchRef> timedout_watchers = {});
 
   /// Called on Notify timeout
@@ -207,11 +207,13 @@ seastar::future<> Notify::create_n_propagate(
     begin,
     end,
     std::forward<Args>(args)...);
-  return seastar::do_for_each(begin, end, [=] (auto& watchref) {
-    return watchref->start_notify(notify);
-  }).then([notify = std::move(notify)] {
-    return notify->maybe_send_completion();
-  });
+  if (begin == end) {
+    return notify->send_completion();
+  } else {
+    return seastar::do_for_each(begin, end, [=] (auto& watchref) {
+      return watchref->start_notify(notify);
+    });
+  }
 }
 
 } // namespace crimson::osd