]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: modify md_config_obs_impl API
authorRonen Friedman <rfriedma@redhat.com>
Wed, 15 Jan 2025 07:33:58 +0000 (01:33 -0600)
committerRonen Friedman <rfriedma@redhat.com>
Sat, 25 Jan 2025 15:41:51 +0000 (09:41 -0600)
Adding a new version of the API used by the configuration
manager to find out what keys are handled by the specific
observer (and thus should be registered to be updated on
changes).

The new interface (get_tracked_keys()) returns a vector
of moveable strings.

Modify the ObserverMgr to use this new interface
when avaiable. The existing 'char**' based interface
is maintained for now, until all its clients are updated.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/config_obs.h
src/common/config_obs_mgr.h

index 20d12ad83343a2c57fd9ac48924a40bcd38cac47..a36d4c2aca0208036f064d227a24d4e12d3ef855 100644 (file)
@@ -16,6 +16,7 @@
 #define CEPH_CONFIG_OBS_H
 
 #include <set>
+#include <vector>
 #include <string>
 
 #include "common/config_fwd.h"
@@ -31,17 +32,32 @@ template<class ConfigProxy>
 class md_config_obs_impl {
 public:
   virtual ~md_config_obs_impl() {}
+
   /** @brief Get a table of strings specifying the configuration keys in which the object is interested.
    * This is called when the object is subscribed to configuration changes with add_observer().
    * The returned table should not be freed until the observer is removed with remove_observer().
-   * Note that it is not possible to change the set of tracked keys without re-subscribing. */
-  virtual const char** get_tracked_conf_keys() const = 0;
+   * Note that it is not possible to change the set of tracked keys without re-subscribing.
+   *
+   * DEPRECATED! Use get_tracked_keys() instead.
+   */
+  virtual const char** get_tracked_conf_keys() const {
+    return nullptr;
+  }
+
+  /**
+   * Returns a vector of strings specifying the configuration keys in which
+   * the object is interested.
+   * Note - the strings in the returned vector are 'moveable'. The caller
+   * (ostensibly the observer manager) is expected to move them into its
+   * map.
+   */
+  virtual std::vector<std::string> get_tracked_keys() const noexcept {
+    return {};
+  }
+
   /// React to a configuration change.
   virtual void handle_conf_change(const ConfigProxy& conf,
                                  const std::set <std::string> &changed) = 0;
-  /// Unused for now
-  virtual void handle_subsys_change(const ConfigProxy& conf,
-                                   const std::set<int>& changed) { }
 };
 }
 
index 5336538e4387440436919659d47c435dca5e5871..805e0d16c43a6c36d3866207ebcbb7a16923d9d4 100644 (file)
@@ -60,10 +60,17 @@ private:
 template<class ConfigObs>
 void ObserverMgr<ConfigObs>::add_observer(ConfigObs* observer)
 {
-  const char **keys = observer->get_tracked_conf_keys();
   auto ptr = std::make_shared<ConfigObs*>(observer);
-  for (const char ** k = keys; *k; ++k) {
-    observers.emplace(*k, ptr);
+
+  for (auto&& k : observer->get_tracked_keys()) {
+    observers.emplace(std::move(k), ptr);
+  }
+
+  // legacy observer interface:
+  if (const char** keys = observer->get_tracked_conf_keys(); keys) {
+    for (const char** k = keys; *k; ++k) {
+      observers.emplace(*k, ptr);
+    }
   }
 }