]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/librados_test_stub/TestWatchNotify.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / librados_test_stub / TestWatchNotify.h
index baf56cb7e1af45de1d10ca09d5f046011d1b9b49..4d381373f09e9afd3eb5112d8455dd2303790334 100644 (file)
@@ -5,7 +5,7 @@
 #define CEPH_TEST_WATCH_NOTIFY_H
 
 #include "include/rados/librados.hpp"
-#include "common/Cond.h"
+#include "common/AsyncOpTracker.h"
 #include "common/Mutex.h"
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
@@ -17,6 +17,7 @@ class Finisher;
 
 namespace librados {
 
+class TestCluster;
 class TestRadosClient;
 
 class TestWatchNotify : boost::noncopyable {
@@ -47,34 +48,52 @@ public:
 
   typedef std::map<uint64_t, WatchHandle> WatchHandles;
 
+  struct ObjectHandler;
+  typedef boost::shared_ptr<ObjectHandler> SharedObjectHandler;
+
   struct Watcher {
+    Watcher(int64_t pool_id, const std::string& nspace, const std::string& oid)
+      : pool_id(pool_id), nspace(nspace), oid(oid) {
+    }
+
+    int64_t pool_id;
+    std::string nspace;
+    std::string oid;
+
+    SharedObjectHandler object_handler;
     WatchHandles watch_handles;
     NotifyHandles notify_handles;
   };
   typedef boost::shared_ptr<Watcher> SharedWatcher;
 
-  TestWatchNotify();
+  TestWatchNotify(TestCluster* test_cluster);
 
-  int list_watchers(const std::string& o,
-                    std::list<obj_watch_t> *out_watchers);
+  int list_watchers(int64_t pool_id, const std::string& nspace,
+                    const std::string& o, std::list<obj_watch_t> *out_watchers);
 
   void aio_flush(TestRadosClient *rados_client, Context *on_finish);
-  void aio_watch(TestRadosClient *rados_client, const std::string& o,
-                 uint64_t gid, uint64_t *handle, librados::WatchCtx2 *watch_ctx,
-                 Context *on_finish);
+  void aio_watch(TestRadosClient *rados_client, int64_t pool_id,
+                 const std::string& nspace, const std::string& o, uint64_t gid,
+                 uint64_t *handle, librados::WatchCtx *watch_ctx,
+                 librados::WatchCtx2 *watch_ctx2, Context *on_finish);
   void aio_unwatch(TestRadosClient *rados_client, uint64_t handle,
                    Context *on_finish);
-  void aio_notify(TestRadosClient *rados_client, const std::string& oid,
-                  bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl,
+  void aio_notify(TestRadosClient *rados_client, int64_t pool_id,
+                  const std::string& nspace, const std::string& oid,
+                  const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl,
                   Context *on_notify);
 
   void flush(TestRadosClient *rados_client);
-  int notify(TestRadosClient *rados_client, const std::string& o,
-             bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl);
-  void notify_ack(TestRadosClient *rados_client, const std::string& o,
+  int notify(TestRadosClient *rados_client, int64_t pool_id,
+             const std::string& nspace, const std::string& o, bufferlist& bl,
+             uint64_t timeout_ms, bufferlist *pbl);
+  void notify_ack(TestRadosClient *rados_client, int64_t pool_id,
+                  const std::string& nspace, const std::string& o,
                   uint64_t notify_id, uint64_t handle, uint64_t gid,
                   bufferlist& bl);
-  int watch(TestRadosClient *rados_client, const std::string& o, uint64_t gid,
+
+  int watch(TestRadosClient *rados_client, int64_t pool_id,
+            const std::string& nspace, const std::string& o, uint64_t gid,
             uint64_t *handle, librados::WatchCtx *ctx,
             librados::WatchCtx2 *ctx2);
   int unwatch(TestRadosClient *rados_client, uint64_t handle);
@@ -82,27 +101,46 @@ public:
   void blacklist(uint32_t nonce);
 
 private:
+  typedef std::tuple<int64_t, std::string, std::string> PoolFile;
+  typedef std::map<PoolFile, SharedWatcher> FileWatchers;
 
-  typedef std::map<std::string, SharedWatcher> FileWatchers;
+  TestCluster *m_test_cluster;
 
   uint64_t m_handle = 0;
   uint64_t m_notify_id = 0;
 
   Mutex m_lock;
-  uint64_t m_pending_notifies = 0;
+  AsyncOpTracker m_async_op_tracker;
 
-  Cond m_file_watcher_cond;
   FileWatchers m_file_watchers;
 
-  SharedWatcher get_watcher(const std::string& oid);
-
-  void execute_notify(TestRadosClient *rados_client, const std::string &oid,
-                      bufferlist &bl, uint64_t notify_id);
-  void ack_notify(TestRadosClient *rados_client, const std::string &oid,
+  SharedWatcher get_watcher(int64_t pool_id, const std::string& nspace,
+                            const std::string& oid);
+  void maybe_remove_watcher(SharedWatcher shared_watcher);
+
+  void execute_watch(TestRadosClient *rados_client, int64_t pool_id,
+                     const std::string& nspace, const std::string& o,
+                     uint64_t gid, uint64_t *handle,
+                     librados::WatchCtx *watch_ctx,
+                     librados::WatchCtx2 *watch_ctx2,
+                     Context *on_finish);
+  void execute_unwatch(TestRadosClient *rados_client, uint64_t handle,
+                       Context *on_finish);
+
+  void execute_notify(TestRadosClient *rados_client, int64_t pool_id,
+                      const std::string& nspace, const std::string &oid,
+                      const bufferlist &bl, bufferlist *pbl,
+                      Context *on_notify);
+  void ack_notify(TestRadosClient *rados_client, int64_t pool_id,
+                  const std::string& nspace, const std::string &oid,
                   uint64_t notify_id, const WatcherID &watcher_id,
                   const bufferlist &bl);
-  void finish_notify(TestRadosClient *rados_client, const std::string &oid,
+  void finish_notify(TestRadosClient *rados_client, int64_t pool_id,
+                     const std::string& nspace, const std::string &oid,
                      uint64_t notify_id);
+
+  void handle_object_removed(int64_t pool_id, const std::string& nspace,
+                             const std::string& oid);
 };
 
 } // namespace librados