diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/rgw/rgw_realm_watcher.h | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/rgw/rgw_realm_watcher.h')
-rw-r--r-- | src/rgw/rgw_realm_watcher.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/rgw/rgw_realm_watcher.h b/src/rgw/rgw_realm_watcher.h new file mode 100644 index 00000000..03d7e939 --- /dev/null +++ b/src/rgw/rgw_realm_watcher.h @@ -0,0 +1,69 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef RGW_REALM_WATCHER_H +#define RGW_REALM_WATCHER_H + +#include "include/rados/librados.hpp" +#include "include/ceph_assert.h" +#include "common/Timer.h" +#include "common/Cond.h" + +class RGWRados; +class RGWRealm; + +enum class RGWRealmNotify { + Reload, + ZonesNeedPeriod, +}; +WRITE_RAW_ENCODER(RGWRealmNotify); + +/** + * RGWRealmWatcher establishes a watch on the current RGWRealm's control object, + * and forwards notifications to registered observers. + */ +class RGWRealmWatcher : public librados::WatchCtx2 { + public: + /** + * Watcher is an interface that allows the RGWRealmWatcher to pass + * notifications on to other interested objects. + */ + class Watcher { + public: + virtual ~Watcher() = default; + + virtual void handle_notify(RGWRealmNotify type, + bufferlist::const_iterator& p) = 0; + }; + + RGWRealmWatcher(CephContext* cct, const RGWRealm& realm); + ~RGWRealmWatcher() override; + + /// register a watcher for the given notification type + void add_watcher(RGWRealmNotify type, Watcher& watcher); + + /// respond to realm notifications by calling the appropriate watcher + void handle_notify(uint64_t notify_id, uint64_t cookie, + uint64_t notifier_id, bufferlist& bl) override; + + /// reestablish the watch if it gets disconnected + void handle_error(uint64_t cookie, int err) override; + + private: + CephContext *const cct; + + /// keep a separate Rados client whose lifetime is independent of RGWRados + /// so that we don't miss notifications during realm reconfiguration + librados::Rados rados; + librados::IoCtx pool_ctx; + uint64_t watch_handle = 0; + std::string watch_oid; + + int watch_start(const RGWRealm& realm); + int watch_restart(); + void watch_stop(); + + std::map<RGWRealmNotify, Watcher&> watchers; +}; + +#endif // RGW_REALM_WATCHER_H |