]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/Watch: drop redundant in_progress_watchers
authorSage Weil <sage@redhat.com>
Sat, 8 Nov 2014 00:35:41 +0000 (16:35 -0800)
committerSage Weil <sage@redhat.com>
Thu, 4 Dec 2014 18:32:38 +0000 (10:32 -0800)
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 <sage@redhat.com>
src/osd/ReplicatedPG.cc
src/osd/Watch.cc
src/osd/Watch.h

index 90fa1d53bfe807b22d4f2fc8179af14f8e878e87..084f85102f2e757e3c87ef200ca89aaee4701f9a 100644 (file)
@@ -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,
index 78d82993f300cf41f91c4054823f48b4a1b4ff34..9ca852a2621deba37693fec75007a1a3090ae3ce 100644 (file)
@@ -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
index dee3e1e2f59c6bcb70e174bb79bffa3a967c0496..7eb42e13c6de38804039748093815fd57ced62ad 100644 (file)
@@ -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,