From 48a43f06db382618eeae7d4854b54ef9d304e790 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Wed, 15 Jan 2025 01:33:58 -0600 Subject: [PATCH] common: modify md_config_obs_impl API 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 --- src/common/config_obs.h | 26 +++++++++++++++++++++----- src/common/config_obs_mgr.h | 13 ++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/common/config_obs.h b/src/common/config_obs.h index 20d12ad83343a..a36d4c2aca020 100644 --- a/src/common/config_obs.h +++ b/src/common/config_obs.h @@ -16,6 +16,7 @@ #define CEPH_CONFIG_OBS_H #include +#include #include #include "common/config_fwd.h" @@ -31,17 +32,32 @@ template 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 get_tracked_keys() const noexcept { + return {}; + } + /// React to a configuration change. virtual void handle_conf_change(const ConfigProxy& conf, const std::set &changed) = 0; - /// Unused for now - virtual void handle_subsys_change(const ConfigProxy& conf, - const std::set& changed) { } }; } diff --git a/src/common/config_obs_mgr.h b/src/common/config_obs_mgr.h index 5336538e43874..805e0d16c43a6 100644 --- a/src/common/config_obs_mgr.h +++ b/src/common/config_obs_mgr.h @@ -60,10 +60,17 @@ private: template void ObserverMgr::add_observer(ConfigObs* observer) { - const char **keys = observer->get_tracked_conf_keys(); auto ptr = std::make_shared(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); + } } } -- 2.39.5