]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_TEST_WATCH_NOTIFY_H | |
5 | #define CEPH_TEST_WATCH_NOTIFY_H | |
6 | ||
7 | #include "include/rados/librados.hpp" | |
11fdf7f2 | 8 | #include "common/AsyncOpTracker.h" |
7c673cae FG |
9 | #include "common/Mutex.h" |
10 | #include <boost/noncopyable.hpp> | |
11 | #include <boost/shared_ptr.hpp> | |
12 | #include <list> | |
13 | #include <map> | |
14 | ||
15 | class Cond; | |
16 | class Finisher; | |
17 | ||
18 | namespace librados { | |
19 | ||
11fdf7f2 | 20 | class TestCluster; |
7c673cae FG |
21 | class TestRadosClient; |
22 | ||
23 | class TestWatchNotify : boost::noncopyable { | |
24 | public: | |
25 | typedef std::pair<uint64_t, uint64_t> WatcherID; | |
26 | typedef std::set<WatcherID> WatcherIDs; | |
27 | typedef std::map<std::pair<uint64_t, uint64_t>, bufferlist> NotifyResponses; | |
28 | ||
29 | struct NotifyHandle { | |
30 | TestRadosClient *rados_client = nullptr; | |
31 | WatcherIDs pending_watcher_ids; | |
32 | NotifyResponses notify_responses; | |
33 | bufferlist *pbl = nullptr; | |
34 | Context *on_notify = nullptr; | |
35 | }; | |
36 | typedef boost::shared_ptr<NotifyHandle> SharedNotifyHandle; | |
37 | typedef std::map<uint64_t, SharedNotifyHandle> NotifyHandles; | |
38 | ||
39 | struct WatchHandle { | |
40 | TestRadosClient *rados_client = nullptr; | |
41 | std::string addr; | |
42 | uint32_t nonce; | |
43 | uint64_t gid; | |
44 | uint64_t handle; | |
45 | librados::WatchCtx* watch_ctx; | |
46 | librados::WatchCtx2* watch_ctx2; | |
47 | }; | |
48 | ||
49 | typedef std::map<uint64_t, WatchHandle> WatchHandles; | |
50 | ||
11fdf7f2 TL |
51 | struct ObjectHandler; |
52 | typedef boost::shared_ptr<ObjectHandler> SharedObjectHandler; | |
53 | ||
7c673cae | 54 | struct Watcher { |
11fdf7f2 TL |
55 | Watcher(int64_t pool_id, const std::string& nspace, const std::string& oid) |
56 | : pool_id(pool_id), nspace(nspace), oid(oid) { | |
57 | } | |
58 | ||
59 | int64_t pool_id; | |
60 | std::string nspace; | |
61 | std::string oid; | |
62 | ||
63 | SharedObjectHandler object_handler; | |
7c673cae FG |
64 | WatchHandles watch_handles; |
65 | NotifyHandles notify_handles; | |
66 | }; | |
67 | typedef boost::shared_ptr<Watcher> SharedWatcher; | |
68 | ||
11fdf7f2 | 69 | TestWatchNotify(TestCluster* test_cluster); |
7c673cae | 70 | |
11fdf7f2 TL |
71 | int list_watchers(int64_t pool_id, const std::string& nspace, |
72 | const std::string& o, std::list<obj_watch_t> *out_watchers); | |
7c673cae FG |
73 | |
74 | void aio_flush(TestRadosClient *rados_client, Context *on_finish); | |
11fdf7f2 TL |
75 | void aio_watch(TestRadosClient *rados_client, int64_t pool_id, |
76 | const std::string& nspace, const std::string& o, uint64_t gid, | |
77 | uint64_t *handle, librados::WatchCtx *watch_ctx, | |
78 | librados::WatchCtx2 *watch_ctx2, Context *on_finish); | |
7c673cae FG |
79 | void aio_unwatch(TestRadosClient *rados_client, uint64_t handle, |
80 | Context *on_finish); | |
11fdf7f2 TL |
81 | void aio_notify(TestRadosClient *rados_client, int64_t pool_id, |
82 | const std::string& nspace, const std::string& oid, | |
83 | const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, | |
7c673cae FG |
84 | Context *on_notify); |
85 | ||
86 | void flush(TestRadosClient *rados_client); | |
11fdf7f2 TL |
87 | int notify(TestRadosClient *rados_client, int64_t pool_id, |
88 | const std::string& nspace, const std::string& o, bufferlist& bl, | |
89 | uint64_t timeout_ms, bufferlist *pbl); | |
90 | void notify_ack(TestRadosClient *rados_client, int64_t pool_id, | |
91 | const std::string& nspace, const std::string& o, | |
7c673cae FG |
92 | uint64_t notify_id, uint64_t handle, uint64_t gid, |
93 | bufferlist& bl); | |
11fdf7f2 TL |
94 | |
95 | int watch(TestRadosClient *rados_client, int64_t pool_id, | |
96 | const std::string& nspace, const std::string& o, uint64_t gid, | |
7c673cae FG |
97 | uint64_t *handle, librados::WatchCtx *ctx, |
98 | librados::WatchCtx2 *ctx2); | |
99 | int unwatch(TestRadosClient *rados_client, uint64_t handle); | |
100 | ||
101 | void blacklist(uint32_t nonce); | |
102 | ||
103 | private: | |
11fdf7f2 TL |
104 | typedef std::tuple<int64_t, std::string, std::string> PoolFile; |
105 | typedef std::map<PoolFile, SharedWatcher> FileWatchers; | |
7c673cae | 106 | |
11fdf7f2 | 107 | TestCluster *m_test_cluster; |
7c673cae FG |
108 | |
109 | uint64_t m_handle = 0; | |
110 | uint64_t m_notify_id = 0; | |
111 | ||
112 | Mutex m_lock; | |
11fdf7f2 | 113 | AsyncOpTracker m_async_op_tracker; |
7c673cae | 114 | |
7c673cae FG |
115 | FileWatchers m_file_watchers; |
116 | ||
11fdf7f2 TL |
117 | SharedWatcher get_watcher(int64_t pool_id, const std::string& nspace, |
118 | const std::string& oid); | |
119 | void maybe_remove_watcher(SharedWatcher shared_watcher); | |
120 | ||
121 | void execute_watch(TestRadosClient *rados_client, int64_t pool_id, | |
122 | const std::string& nspace, const std::string& o, | |
123 | uint64_t gid, uint64_t *handle, | |
124 | librados::WatchCtx *watch_ctx, | |
125 | librados::WatchCtx2 *watch_ctx2, | |
126 | Context *on_finish); | |
127 | void execute_unwatch(TestRadosClient *rados_client, uint64_t handle, | |
128 | Context *on_finish); | |
129 | ||
130 | void execute_notify(TestRadosClient *rados_client, int64_t pool_id, | |
131 | const std::string& nspace, const std::string &oid, | |
132 | const bufferlist &bl, bufferlist *pbl, | |
133 | Context *on_notify); | |
134 | void ack_notify(TestRadosClient *rados_client, int64_t pool_id, | |
135 | const std::string& nspace, const std::string &oid, | |
7c673cae FG |
136 | uint64_t notify_id, const WatcherID &watcher_id, |
137 | const bufferlist &bl); | |
11fdf7f2 TL |
138 | void finish_notify(TestRadosClient *rados_client, int64_t pool_id, |
139 | const std::string& nspace, const std::string &oid, | |
7c673cae | 140 | uint64_t notify_id); |
11fdf7f2 TL |
141 | |
142 | void handle_object_removed(int64_t pool_id, const std::string& nspace, | |
143 | const std::string& oid); | |
7c673cae FG |
144 | }; |
145 | ||
146 | } // namespace librados | |
147 | ||
148 | #endif // CEPH_TEST_WATCH_NOTIFY_H |