Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_realm_watcher.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RGW_REALM_WATCHER_H
5 #define RGW_REALM_WATCHER_H
6
7 #include "include/rados/librados.hpp"
8 #include "include/assert.h"
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,
36                                bufferlist::iterator& p) = 0;
37   };
38
39   RGWRealmWatcher(CephContext* cct, RGWRealm& realm);
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;
59   uint64_t watch_handle;
60   std::string watch_oid;
61
62   int watch_start(RGWRealm& realm);
63   int watch_restart();
64   void watch_stop();
65
66   std::map<RGWRealmNotify, Watcher&> watchers;
67 };
68
69 #endif // RGW_REALM_WATCHER_H