From 8f6be7ddac7abdb61b669e89621a2942a13022c0 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Mar 2021 21:23:54 +0800 Subject: [PATCH] crimson/osd: differentiate Notify with and without watchers we don't need to arm the timer, if there is no watchers. Signed-off-by: Kefu Chai --- src/crimson/osd/watch.cc | 10 ++++++++++ src/crimson/osd/watch.h | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/crimson/osd/watch.cc b/src/crimson/osd/watch.cc index 590e9922777..261bd18040c 100644 --- a/src/crimson/osd/watch.cc +++ b/src/crimson/osd/watch.cc @@ -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) { diff --git a/src/crimson/osd/watch.h b/src/crimson/osd/watch.h index b654efa41c4..d9f7325d3ac 100644 --- a/src/crimson/osd/watch.h +++ b/src/crimson/osd/watch.h @@ -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 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::value_type, crimson::osd::WatchRef>); - auto notify = seastar::make_shared( - private_ctag_t{}, - begin, - end, - std::forward(args)...); if (begin == end) { + auto notify = seastar::make_shared( + private_ctag_t{}, + std::forward(args)...); return notify->send_completion(); } else { + auto notify = seastar::make_shared( + private_ctag_t{}, + begin, end, + std::forward(args)...); return seastar::do_for_each(begin, end, [=] (auto& watchref) { return watchref->start_notify(notify); }); -- 2.39.5