Skip to content

Commit 519844b

Browse files
authored
Merge pull request ceph#61394 from ronen-fr/wip-rf-cacher-v2
common: modify md_config_obs_impl API Reviewed-by: Radoslaw Zarzynski <[email protected]> Reviewed-by: Patrick Donnelly <[email protected]>
2 parents 05bdd9f + 7c8f081 commit 519844b

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

src/common/ceph_context.cc

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ class LockdepObs : public md_config_obs_t {
120120
}
121121
}
122122

123-
const char** get_tracked_conf_keys() const override {
124-
static const char *KEYS[] = {"lockdep", NULL};
125-
return KEYS;
123+
std::vector<std::string> get_tracked_keys() const noexcept override {
124+
return {"lockdep"s};
126125
}
127126

128127
void handle_conf_change(const ConfigProxy& conf,
@@ -164,12 +163,8 @@ class MempoolObs : public md_config_obs_t,
164163
}
165164

166165
// md_config_obs_t
167-
const char** get_tracked_conf_keys() const override {
168-
static const char *KEYS[] = {
169-
"mempool_debug",
170-
NULL
171-
};
172-
return KEYS;
166+
std::vector<std::string> get_tracked_keys() const noexcept override {
167+
return {"mempool_debug"s};
173168
}
174169

175170
void handle_conf_change(const ConfigProxy& conf,
@@ -278,29 +273,27 @@ class LogObs : public md_config_obs_t {
278273
: log(l), lock(ceph::make_mutex("log_obs")) {
279274
}
280275

281-
const char** get_tracked_conf_keys() const override {
282-
static const char *KEYS[] = {
283-
"log_file",
284-
"log_max_new",
285-
"log_max_recent",
286-
"log_to_file",
287-
"log_to_syslog",
288-
"err_to_syslog",
289-
"log_stderr_prefix",
290-
"log_to_stderr",
291-
"err_to_stderr",
292-
"log_to_graylog",
293-
"err_to_graylog",
294-
"log_graylog_host",
295-
"log_graylog_port",
296-
"log_to_journald",
297-
"err_to_journald",
298-
"log_coarse_timestamps",
299-
"fsid",
300-
"host",
301-
NULL
276+
std::vector<std::string> get_tracked_keys() const noexcept override {
277+
return std::vector<std::string>{
278+
"log_file"s,
279+
"log_max_new"s,
280+
"log_max_recent"s,
281+
"log_to_file"s,
282+
"log_to_syslog"s,
283+
"err_to_syslog"s,
284+
"log_stderr_prefix"s,
285+
"log_to_stderr"s,
286+
"err_to_stderr"s,
287+
"log_to_graylog"s,
288+
"err_to_graylog"s,
289+
"log_graylog_host"s,
290+
"log_graylog_port"s,
291+
"log_to_journald"s,
292+
"err_to_journald"s,
293+
"log_coarse_timestamps"s,
294+
"fsid"s,
295+
"host"s
302296
};
303-
return KEYS;
304297
}
305298

306299
void handle_conf_change(const ConfigProxy& conf,

src/common/config_cacher.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@
3131
template <typename ValueT>
3232
class md_config_cacher_t : public md_config_obs_t {
3333
ConfigProxy& conf;
34-
const char* keys[2];
34+
const std::string option_name;
3535
std::atomic<ValueT> value_cache;
3636

37-
const char** get_tracked_conf_keys() const override {
38-
return const_cast<const char**>(keys);
37+
std::vector<std::string> get_tracked_keys() const noexcept override {
38+
return std::vector<std::string>{option_name};
3939
}
4040

4141
void handle_conf_change(const ConfigProxy& conf,
4242
const std::set<std::string>& changed) override {
43-
if (changed.contains(keys[0])) {
44-
value_cache.store(conf.get_val<ValueT>(keys[0]));
43+
if (changed.contains(option_name)) {
44+
value_cache.store(conf.get_val<ValueT>(option_name));
4545
}
4646
}
4747

4848
public:
4949
md_config_cacher_t(ConfigProxy& conf,
5050
const char* const option_name)
51-
: conf(conf),
52-
keys{option_name, nullptr} {
51+
: conf(conf)
52+
, option_name{option_name} {
5353
conf.add_observer(this);
5454
std::atomic_init(&value_cache,
55-
conf.get_val<ValueT>(keys[0]));
55+
conf.get_val<ValueT>(option_name));
5656
}
5757

5858
~md_config_cacher_t() {

src/common/config_obs.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define CEPH_CONFIG_OBS_H
1717

1818
#include <set>
19+
#include <vector>
1920
#include <string>
2021

2122
#include "common/config_fwd.h"
@@ -31,17 +32,32 @@ template<class ConfigProxy>
3132
class md_config_obs_impl {
3233
public:
3334
virtual ~md_config_obs_impl() {}
35+
3436
/** @brief Get a table of strings specifying the configuration keys in which the object is interested.
3537
* This is called when the object is subscribed to configuration changes with add_observer().
3638
* The returned table should not be freed until the observer is removed with remove_observer().
37-
* Note that it is not possible to change the set of tracked keys without re-subscribing. */
38-
virtual const char** get_tracked_conf_keys() const = 0;
39+
* Note that it is not possible to change the set of tracked keys without re-subscribing.
40+
*
41+
* DEPRECATED! Use get_tracked_keys() instead.
42+
*/
43+
virtual const char** get_tracked_conf_keys() const {
44+
return nullptr;
45+
}
46+
47+
/**
48+
* Returns a vector of strings specifying the configuration keys in which
49+
* the object is interested.
50+
* Note - the strings in the returned vector are 'moveable'. The caller
51+
* (ostensibly the observer manager) is expected to move them into its
52+
* map.
53+
*/
54+
virtual std::vector<std::string> get_tracked_keys() const noexcept {
55+
return {};
56+
}
57+
3958
/// React to a configuration change.
4059
virtual void handle_conf_change(const ConfigProxy& conf,
4160
const std::set <std::string> &changed) = 0;
42-
/// Unused for now
43-
virtual void handle_subsys_change(const ConfigProxy& conf,
44-
const std::set<int>& changed) { }
4561
};
4662
}
4763

src/common/config_obs_mgr.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ class ObserverMgr : public ConfigTracker {
6060
template<class ConfigObs>
6161
void ObserverMgr<ConfigObs>::add_observer(ConfigObs* observer)
6262
{
63-
const char **keys = observer->get_tracked_conf_keys();
6463
auto ptr = std::make_shared<ConfigObs*>(observer);
65-
for (const char ** k = keys; *k; ++k) {
66-
observers.emplace(*k, ptr);
64+
65+
for (auto&& k : observer->get_tracked_keys()) {
66+
observers.emplace(std::move(k), ptr);
67+
}
68+
69+
// legacy observer interface:
70+
if (const char** keys = observer->get_tracked_conf_keys(); keys) {
71+
for (const char** k = keys; *k; ++k) {
72+
observers.emplace(*k, ptr);
73+
}
6774
}
6875
}
6976

0 commit comments

Comments
 (0)