]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
7c673cae FG |
3 | |
4 | #ifndef RGW_REALM_WATCHER_H | |
5 | #define RGW_REALM_WATCHER_H | |
6 | ||
7 | #include "include/rados/librados.hpp" | |
11fdf7f2 | 8 | #include "include/ceph_assert.h" |
7c673cae FG |
9 | #include "common/Timer.h" |
10 | #include "common/Cond.h" | |
11 | ||
12 | class RGWRados; | |
13 | class RGWRealm; | |
14 | ||
15 | enum class RGWRealmNotify { | |
16 | Reload, | |
17 | ZonesNeedPeriod, | |
18 | }; | |
19 | WRITE_RAW_ENCODER(RGWRealmNotify); | |
20 | ||
21 | /** | |
22 | * RGWRealmWatcher establishes a watch on the current RGWRealm's control object, | |
23 | * and forwards notifications to registered observers. | |
24 | */ | |
25 | class RGWRealmWatcher : public librados::WatchCtx2 { | |
26 | public: | |
27 | /** | |
28 | * Watcher is an interface that allows the RGWRealmWatcher to pass | |
29 | * notifications on to other interested objects. | |
30 | */ | |
31 | class Watcher { | |
32 | public: | |
33 | virtual ~Watcher() = default; | |
34 | ||
35 | virtual void handle_notify(RGWRealmNotify type, | |
11fdf7f2 | 36 | bufferlist::const_iterator& p) = 0; |
7c673cae FG |
37 | }; |
38 | ||
11fdf7f2 | 39 | RGWRealmWatcher(CephContext* cct, const RGWRealm& realm); |
7c673cae FG |
40 | ~RGWRealmWatcher() override; |
41 | ||
42 | /// register a watcher for the given notification type | |
43 | void add_watcher(RGWRealmNotify type, Watcher& watcher); | |
44 | ||
45 | /// respond to realm notifications by calling the appropriate watcher | |
46 | void handle_notify(uint64_t notify_id, uint64_t cookie, | |
47 | uint64_t notifier_id, bufferlist& bl) override; | |
48 | ||
49 | /// reestablish the watch if it gets disconnected | |
50 | void handle_error(uint64_t cookie, int err) override; | |
51 | ||
52 | private: | |
53 | CephContext *const cct; | |
54 | ||
55 | /// keep a separate Rados client whose lifetime is independent of RGWRados | |
56 | /// so that we don't miss notifications during realm reconfiguration | |
57 | librados::Rados rados; | |
58 | librados::IoCtx pool_ctx; | |
11fdf7f2 | 59 | uint64_t watch_handle = 0; |
7c673cae FG |
60 | std::string watch_oid; |
61 | ||
11fdf7f2 | 62 | int watch_start(const RGWRealm& realm); |
7c673cae FG |
63 | int watch_restart(); |
64 | void watch_stop(); | |
65 | ||
66 | std::map<RGWRealmNotify, Watcher&> watchers; | |
67 | }; | |
68 | ||
69 | #endif // RGW_REALM_WATCHER_H |