From 7c8a1cd31f174cd391f0b215c72f34ee24f7061f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 7 Nov 2014 16:35:41 -0800 Subject: [PATCH] osd/Watch: drop redundant in_progress_watchers This is essentially watchers.size() at all times and obfuscates the code. In particular this makes the maybe_complete_notify() logic much clearer. Signed-off-by: Sage Weil --- src/osd/ReplicatedPG.cc | 1 - src/osd/Watch.cc | 17 +++++------------ src/osd/Watch.h | 7 ++----- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 90fa1d53bfe80..084f85102f2e7 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -5419,7 +5419,6 @@ void ReplicatedPG::do_osd_op_effects(OpContext *ctx) Notify::makeNotifyRef( conn, ctx->reqid.name.num(), - ctx->obc->watchers.size(), p->bl, p->timeout, p->cookie, diff --git a/src/osd/Watch.cc b/src/osd/Watch.cc index 78d82993f300c..9ca852a2621de 100644 --- a/src/osd/Watch.cc +++ b/src/osd/Watch.cc @@ -29,7 +29,6 @@ static ostream& _prefix( Notify::Notify( ConnectionRef client, uint64_t client_gid, - unsigned num_watchers, bufferlist &payload, uint32_t timeout, uint64_t cookie, @@ -37,7 +36,6 @@ Notify::Notify( uint64_t version, OSDService *osd) : client(client), client_gid(client_gid), - in_progress_watchers(num_watchers), complete(false), discarded(false), timed_out(false), @@ -53,7 +51,6 @@ Notify::Notify( NotifyRef Notify::makeNotifyRef( ConnectionRef client, uint64_t client_gid, - unsigned num_watchers, bufferlist &payload, uint32_t timeout, uint64_t cookie, @@ -62,7 +59,7 @@ NotifyRef Notify::makeNotifyRef( OSDService *osd) { NotifyRef ret( new Notify( - client, client_gid, num_watchers, + client, client_gid, payload, timeout, cookie, notify_id, version, osd)); @@ -100,7 +97,6 @@ void Notify::do_timeout() return; } - in_progress_watchers = 0; // we give up timed_out = true; // we will send the client an error code maybe_complete_notify(); assert(complete); @@ -160,9 +156,8 @@ void Notify::complete_watcher(WatchRef watch, bufferlist& reply_bl) dout(10) << "complete_watcher" << dendl; if (is_discarded()) return; - assert(in_progress_watchers > 0); + assert(watchers.count(watch)); watchers.erase(watch); - --in_progress_watchers; notify_replies.insert(make_pair(watch->get_watcher_gid(), reply_bl)); maybe_complete_notify(); } @@ -173,18 +168,17 @@ void Notify::complete_watcher_remove(WatchRef watch) dout(10) << __func__ << dendl; if (is_discarded()) return; - assert(in_progress_watchers > 0); + assert(watchers.count(watch)); watchers.erase(watch); - --in_progress_watchers; maybe_complete_notify(); } void Notify::maybe_complete_notify() { dout(10) << "maybe_complete_notify -- " - << in_progress_watchers + << watchers.size() << " in progress watchers " << dendl; - if (!in_progress_watchers) { + if (watchers.empty() || timed_out) { bufferlist bl; ::encode(notify_replies, bl); bufferlist empty; @@ -213,7 +207,6 @@ void Notify::init() Mutex::Locker l(lock); register_cb(); maybe_complete_notify(); - assert(in_progress_watchers == watchers.size()); } #define dout_subsys ceph_subsys_osd diff --git a/src/osd/Watch.h b/src/osd/Watch.h index dee3e1e2f59c6..7eb42e13c6de3 100644 --- a/src/osd/Watch.h +++ b/src/osd/Watch.h @@ -56,7 +56,6 @@ class Notify { WNotifyRef self; ConnectionRef client; uint64_t client_gid; - unsigned in_progress_watchers; bool complete; bool discarded; bool timed_out; ///< true if the notify timed out @@ -80,7 +79,7 @@ class Notify { return discarded || complete; } - /// Sends notify completion if in_progress_watchers == 0 + /// Sends notify completion if watchers.empty() or timeout void maybe_complete_notify(); /// Called on Notify timeout @@ -89,7 +88,6 @@ class Notify { Notify( ConnectionRef client, uint64_t client_gid, - unsigned num_watchers, bufferlist &payload, uint32_t timeout, uint64_t cookie, @@ -107,7 +105,7 @@ public: string gen_dbg_prefix() { stringstream ss; ss << "Notify(" << make_pair(cookie, notify_id) << " " - << " in_progress_watchers=" << in_progress_watchers + << " watchers=" << watchers.size() << ") "; return ss.str(); } @@ -117,7 +115,6 @@ public: static NotifyRef makeNotifyRef( ConnectionRef client, uint64_t client_gid, - unsigned num_watchers, bufferlist &payload, uint32_t timeout, uint64_t cookie, -- 2.39.5