]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados/: include watch cookie in notify_ack
authorSamuel Just <sam.just@inktank.com>
Tue, 12 Feb 2013 22:04:55 +0000 (14:04 -0800)
committerSamuel Just <sam.just@inktank.com>
Wed, 20 Feb 2013 21:29:20 +0000 (13:29 -0800)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/librados/IoCtxImpl.cc
src/librados/IoCtxImpl.h
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/osdc/Objecter.h

index ea63b2a59b4ce63fe7b1697eb8eaacf10656a5c4..800e27f90b6e7aae18e522011508d534019655d4 100644 (file)
@@ -1403,7 +1403,7 @@ int librados::IoCtxImpl::watch(const object_t& oid, uint64_t ver,
   lock->Lock();
 
   WatchContext *wc = new WatchContext(this, oid, ctx);
-  client->register_watcher(wc, oid, ctx, cookie);
+  client->register_watcher(wc, cookie);
   prepare_assert_ops(&rd);
   rd.watch(*cookie, ver, 1);
   bufferlist bl;
@@ -1431,12 +1431,14 @@ int librados::IoCtxImpl::watch(const object_t& oid, uint64_t ver,
 
 
 /* this is called with IoCtxImpl::lock held */
-int librados::IoCtxImpl::_notify_ack(const object_t& oid,
-                                    uint64_t notify_id, uint64_t ver)
+int librados::IoCtxImpl::_notify_ack(
+  const object_t& oid,
+  uint64_t notify_id, uint64_t ver,
+  uint64_t cookie)
 {
   ::ObjectOperation rd;
   prepare_assert_ops(&rd);
-  rd.notify_ack(notify_id, ver);
+  rd.notify_ack(notify_id, ver, cookie);
   objecter->read(oid, oloc, rd, snap_seq, (bufferlist*)NULL, 0, 0, 0);
 
   return 0;
@@ -1491,7 +1493,7 @@ int librados::IoCtxImpl::notify(const object_t& oid, uint64_t ver, bufferlist& b
 
   lock->Lock();
   WatchContext *wc = new WatchContext(this, oid, ctx);
-  client->register_watcher(wc, oid, ctx, &cookie);
+  client->register_watcher(wc, &cookie);
   uint32_t prot_ver = 1;
   uint32_t timeout = notify_timeout;
   ::encode(prot_ver, inbl);
@@ -1687,7 +1689,7 @@ void librados::IoCtxImpl::C_NotifyComplete::notify(uint8_t opcode,
 librados::WatchContext::WatchContext(IoCtxImpl *io_ctx_impl_,
                                     const object_t& _oc,
                                     librados::WatchCtx *_ctx)
-  : io_ctx_impl(io_ctx_impl_), oid(_oc), ctx(_ctx), linger_id(0)
+  : io_ctx_impl(io_ctx_impl_), oid(_oc), ctx(_ctx), linger_id(0), cookie(0)
 {
   io_ctx_impl->get();
 }
@@ -1706,7 +1708,7 @@ void librados::WatchContext::notify(Mutex *client_lock,
   ctx->notify(opcode, ver, payload);
   if (opcode != WATCH_NOTIFY_COMPLETE) {
     client_lock->Lock();
-    io_ctx_impl->_notify_ack(oid, notify_id, ver);
+    io_ctx_impl->_notify_ack(oid, notify_id, ver, cookie);
     client_lock->Unlock();
   }
 }
index 33d1f3ebd14af1161ebc41d44c701fbe002d43ff..c5b14cab8e36994f2ed267a211b90536c3617795 100644 (file)
@@ -194,7 +194,9 @@ struct librados::IoCtxImpl {
   int watch(const object_t& oid, uint64_t ver, uint64_t *cookie, librados::WatchCtx *ctx);
   int unwatch(const object_t& oid, uint64_t cookie);
   int notify(const object_t& oid, uint64_t ver, bufferlist& bl);
-  int _notify_ack(const object_t& oid, uint64_t notify_id, uint64_t ver);
+  int _notify_ack(
+    const object_t& oid, uint64_t notify_id, uint64_t ver,
+    uint64_t cookie);
 
   eversion_t last_version();
   void set_assert_version(uint64_t ver);
@@ -217,6 +219,7 @@ struct WatchContext : public RefCountedWaitObject {
   const object_t oid;
   librados::WatchCtx *ctx;
   uint64_t linger_id;
+  uint64_t cookie;
 
   WatchContext(IoCtxImpl *io_ctx_impl_,
               const object_t& _oc,
index 7e76b65694de42b184c812268bade8a488e6440c..feb0dfc3602a09ce4344627ccbef22f6156b6518 100644 (file)
@@ -478,14 +478,11 @@ int librados::RadosClient::pool_delete_async(const char *name, PoolAsyncCompleti
   return r;
 }
 
-void librados::RadosClient::register_watcher(WatchContext *wc,
-                                            const object_t& oid,
-                                            librados::WatchCtx *ctx,
-                                            uint64_t *cookie)
+void librados::RadosClient::register_watcher(WatchContext *wc, uint64_t *cookie)
 {
   assert(lock.is_locked());
-  *cookie = ++max_watch_cookie;
-  watchers[*cookie] = wc;
+  wc->cookie = *cookie = ++max_watch_cookie;
+  watchers[wc->cookie] = wc;
 }
 
 void librados::RadosClient::unregister_watcher(uint64_t cookie)
index 1f39f22fb3f31fef90bc7dc1e41dde990b9637b0..6dd6d109c6476be3f558811df3958de35228a05e 100644 (file)
@@ -97,8 +97,7 @@ public:
   uint64_t max_watch_cookie;
   map<uint64_t, librados::WatchContext *> watchers;
 
-  void register_watcher(librados::WatchContext *wc, const object_t& oid,
-                       librados::WatchCtx *ctx, uint64_t *cookie);
+  void register_watcher(librados::WatchContext *wc, uint64_t *cookie);
   void unregister_watcher(uint64_t cookie);
   void watch_notify(MWatchNotify *m);
   void get();
index baf600c53be5b64899b90e7d989245bb12e63b59..9ff02f6ab9380d0d1b94298270289565a840248a 100644 (file)
@@ -487,8 +487,10 @@ struct ObjectOperation {
     add_watch(CEPH_OSD_OP_NOTIFY, cookie, ver, 1, inbl); 
   }
 
-  void notify_ack(uint64_t notify_id, uint64_t ver) {
+  void notify_ack(uint64_t notify_id, uint64_t ver, uint64_t cookie) {
     bufferlist bl;
+    ::encode(notify_id, bl);
+    ::encode(cookie, bl);
     add_watch(CEPH_OSD_OP_NOTIFY_ACK, notify_id, ver, 0, bl);
   }