Skip to content

Commit 8ac0470

Browse files
committed
common: fix md_config_cacher_t
In its get_tracked_conf_keys() member function, the cacher (in the existing code) initializes a static function-block variable ('keys'), and uses it for registering the observer. But the cacher is instantiated on the type of the configuration value. Thus, multiple cacher objects for which the configuration values are of the same type - share the static 'keys'. Only one of the observers is registered. Note that the code could have been simplified somewhat, if the signature of the get_tracked_conf_keys() function was changed to return 'const char* const *'. Fixes: https://tracker.ceph.com/issues/69236 Signed-off-by: Ronen Friedman <[email protected]>
1 parent 05ae3db commit 8ac0470

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/common/config_cacher.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,41 @@
1818
#include "common/config_obs.h"
1919
#include "common/config.h"
2020

21+
/**
22+
* A simple class to cache a single configuration value.
23+
* Points to note:
24+
* - as get_tracked_conf_keys() must return a pointer to a null-terminated
25+
* array of C-strings, 'keys' - an array - is used to hold the sole key
26+
* that this observer is interested in.
27+
* - the const cast should be removed once we change the
28+
* get_tracked_conf_keys() to return const char* const * (or something
29+
* similar).
30+
*/
2131
template <typename ValueT>
2232
class md_config_cacher_t : public md_config_obs_t {
2333
ConfigProxy& conf;
24-
const char* const option_name;
34+
const char* keys[2];
2535
std::atomic<ValueT> value_cache;
2636

2737
const char** get_tracked_conf_keys() const override {
28-
const static char* keys[] = { option_name, nullptr };
29-
return keys;
38+
return const_cast<const char**>(keys);
3039
}
3140

3241
void handle_conf_change(const ConfigProxy& conf,
3342
const std::set<std::string>& changed) override {
34-
if (changed.count(option_name)) {
35-
value_cache.store(conf.get_val<ValueT>(option_name));
43+
if (changed.count(keys[0])) {
44+
value_cache.store(conf.get_val<ValueT>(keys[0]));
3645
}
3746
}
3847

3948
public:
4049
md_config_cacher_t(ConfigProxy& conf,
4150
const char* const option_name)
4251
: conf(conf),
43-
option_name(option_name) {
52+
keys{option_name, nullptr} {
4453
conf.add_observer(this);
4554
std::atomic_init(&value_cache,
46-
conf.get_val<ValueT>(option_name));
55+
conf.get_val<ValueT>(keys[0]));
4756
}
4857

4958
~md_config_cacher_t() {

0 commit comments

Comments
 (0)