]>
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_RBD_MIRROR_POOL_REPLAYER_H | |
5 | #define CEPH_RBD_MIRROR_POOL_REPLAYER_H | |
6 | ||
7 | #include "common/AsyncOpTracker.h" | |
8 | #include "common/Cond.h" | |
9 | #include "common/Mutex.h" | |
10 | #include "common/WorkQueue.h" | |
11 | #include "include/rados/librados.hpp" | |
12 | ||
13 | #include "ClusterWatcher.h" | |
14 | #include "LeaderWatcher.h" | |
15 | #include "PoolWatcher.h" | |
16 | #include "ImageDeleter.h" | |
17 | #include "types.h" | |
18 | ||
19 | #include <set> | |
20 | #include <map> | |
21 | #include <memory> | |
22 | #include <atomic> | |
23 | #include <string> | |
24 | ||
25 | class AdminSocketHook; | |
26 | ||
27 | namespace librbd { class ImageCtx; } | |
28 | ||
29 | namespace rbd { | |
30 | namespace mirror { | |
31 | ||
32 | template <typename> struct Threads; | |
33 | template <typename> class InstanceReplayer; | |
34 | template <typename> class InstanceWatcher; | |
35 | ||
36 | /** | |
37 | * Controls mirroring for a single remote cluster. | |
38 | */ | |
39 | class PoolReplayer { | |
40 | public: | |
41 | PoolReplayer(Threads<librbd::ImageCtx> *threads, | |
42 | std::shared_ptr<ImageDeleter> image_deleter, | |
7c673cae FG |
43 | int64_t local_pool_id, const peer_t &peer, |
44 | const std::vector<const char*> &args); | |
45 | ~PoolReplayer(); | |
46 | PoolReplayer(const PoolReplayer&) = delete; | |
47 | PoolReplayer& operator=(const PoolReplayer&) = delete; | |
48 | ||
49 | bool is_blacklisted() const; | |
50 | bool is_leader() const; | |
51 | ||
52 | int init(); | |
53 | void run(); | |
54 | ||
55 | void print_status(Formatter *f, stringstream *ss); | |
56 | void start(); | |
57 | void stop(bool manual); | |
58 | void restart(); | |
59 | void flush(); | |
60 | void release_leader(); | |
61 | ||
62 | private: | |
63 | struct PoolWatcherListener : public PoolWatcher<>::Listener { | |
64 | PoolReplayer *pool_replayer; | |
65 | bool local; | |
66 | ||
67 | PoolWatcherListener(PoolReplayer *pool_replayer, bool local) | |
68 | : pool_replayer(pool_replayer), local(local) { | |
69 | } | |
70 | ||
71 | void handle_update(const std::string &mirror_uuid, | |
72 | ImageIds &&added_image_ids, | |
73 | ImageIds &&removed_image_ids) override { | |
74 | pool_replayer->handle_update((local ? "" : mirror_uuid), | |
75 | std::move(added_image_ids), | |
76 | std::move(removed_image_ids)); | |
77 | } | |
78 | }; | |
79 | ||
80 | void handle_update(const std::string &mirror_uuid, | |
81 | ImageIds &&added_image_ids, | |
82 | ImageIds &&removed_image_ids); | |
83 | ||
84 | int init_rados(const std::string &cluster_name, | |
85 | const std::string &client_name, | |
86 | const std::string &description, RadosRef *rados_ref); | |
87 | ||
88 | void handle_post_acquire_leader(Context *on_finish); | |
89 | void handle_pre_release_leader(Context *on_finish); | |
90 | ||
91 | void init_local_pool_watcher(Context *on_finish); | |
92 | void handle_init_local_pool_watcher(int r, Context *on_finish); | |
93 | ||
94 | void init_remote_pool_watcher(Context *on_finish); | |
95 | ||
96 | void shut_down_pool_watchers(Context *on_finish); | |
97 | void handle_shut_down_pool_watchers(int r, Context *on_finish); | |
98 | ||
99 | void wait_for_update_ops(Context *on_finish); | |
100 | void handle_wait_for_update_ops(int r, Context *on_finish); | |
101 | ||
31f18b77 FG |
102 | void handle_update_leader(const std::string &leader_instance_id); |
103 | ||
7c673cae FG |
104 | Threads<librbd::ImageCtx> *m_threads; |
105 | std::shared_ptr<ImageDeleter> m_image_deleter; | |
7c673cae FG |
106 | mutable Mutex m_lock; |
107 | Cond m_cond; | |
108 | std::atomic<bool> m_stopping = { false }; | |
109 | bool m_manual_stop = false; | |
110 | bool m_blacklisted = false; | |
111 | ||
112 | peer_t m_peer; | |
113 | std::vector<const char*> m_args; | |
114 | RadosRef m_local_rados; | |
115 | RadosRef m_remote_rados; | |
116 | ||
117 | librados::IoCtx m_local_io_ctx; | |
118 | librados::IoCtx m_remote_io_ctx; | |
119 | ||
120 | int64_t m_local_pool_id = -1; | |
121 | ||
122 | PoolWatcherListener m_local_pool_watcher_listener; | |
123 | std::unique_ptr<PoolWatcher<> > m_local_pool_watcher; | |
124 | ||
125 | PoolWatcherListener m_remote_pool_watcher_listener; | |
126 | std::unique_ptr<PoolWatcher<> > m_remote_pool_watcher; | |
127 | ||
128 | std::unique_ptr<InstanceReplayer<librbd::ImageCtx>> m_instance_replayer; | |
129 | ||
130 | std::string m_asok_hook_name; | |
131 | AdminSocketHook *m_asok_hook; | |
132 | ||
133 | std::map<std::string, ImageIds> m_initial_mirror_image_ids; | |
134 | ||
135 | class PoolReplayerThread : public Thread { | |
136 | PoolReplayer *m_pool_replayer; | |
137 | public: | |
138 | PoolReplayerThread(PoolReplayer *pool_replayer) | |
139 | : m_pool_replayer(pool_replayer) { | |
140 | } | |
141 | void *entry() override { | |
142 | m_pool_replayer->run(); | |
143 | return 0; | |
144 | } | |
145 | } m_pool_replayer_thread; | |
146 | ||
147 | class LeaderListener : public LeaderWatcher<>::Listener { | |
148 | public: | |
149 | LeaderListener(PoolReplayer *pool_replayer) | |
150 | : m_pool_replayer(pool_replayer) { | |
151 | } | |
152 | ||
153 | protected: | |
154 | void post_acquire_handler(Context *on_finish) override { | |
155 | m_pool_replayer->handle_post_acquire_leader(on_finish); | |
156 | } | |
157 | ||
158 | void pre_release_handler(Context *on_finish) override { | |
159 | m_pool_replayer->handle_pre_release_leader(on_finish); | |
160 | } | |
161 | ||
31f18b77 FG |
162 | void update_leader_handler( |
163 | const std::string &leader_instance_id) override { | |
164 | m_pool_replayer->handle_update_leader(leader_instance_id); | |
165 | } | |
166 | ||
7c673cae FG |
167 | private: |
168 | PoolReplayer *m_pool_replayer; | |
169 | } m_leader_listener; | |
170 | ||
171 | std::unique_ptr<LeaderWatcher<> > m_leader_watcher; | |
172 | std::unique_ptr<InstanceWatcher<librbd::ImageCtx> > m_instance_watcher; | |
173 | AsyncOpTracker m_update_op_tracker; | |
174 | }; | |
175 | ||
176 | } // namespace mirror | |
177 | } // namespace rbd | |
178 | ||
179 | #endif // CEPH_RBD_MIRROR_POOL_REPLAYER_H |