From: John Spray Date: Wed, 4 Apr 2018 13:19:57 +0000 (-0400) Subject: mgr: separate out module_config and store_cache X-Git-Tag: v13.1.0~143^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=306e4854b5bef5ac1000d80eafaa942cc3f8868e;p=ceph.git mgr: separate out module_config and store_cache Signed-off-by: John Spray --- diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 4c6cb05443c7f..5bc1fbdcc4602 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -35,20 +35,14 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " -ActivePyModules::ActivePyModules(PyModuleConfig &module_config, +ActivePyModules::ActivePyModules(PyModuleConfig &module_config_, DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, LogChannelRef clog_, Objecter &objecter_, Client &client_, Finisher &f) - : config_cache(module_config), daemon_state(ds), cluster_state(cs), + : module_config(module_config_), daemon_state(ds), cluster_state(cs), monc(mc), clog(clog_), objecter(objecter_), client(client_), finisher(f), lock("ActivePyModules") { - for(auto &i: config_cache.config) { - auto last_slash = i.first.rfind('/'); - const std::string module_name = i.first.substr(4, i.first.substr(4).find('/')); - const std::string key = i.first.substr(last_slash + 1); - set_config(module_name, key, i.second); - } } ActivePyModules::~ActivePyModules() = default; @@ -437,11 +431,8 @@ bool ActivePyModules::get_store(const std::string &module_name, dout(4) << __func__ << "key: " << global_key << dendl; - - Mutex::Locker lock(config_cache.lock); - - if (config_cache.config.count(global_key)) { - *val = config_cache.config.at(global_key); + if (store_cache.count(global_key)) { + *val = store_cache.at(global_key); return true; } else { return false; @@ -461,10 +452,10 @@ bool ActivePyModules::get_config(const std::string &module_name, dout(4) << __func__ << " key: " << global_key << dendl; - Mutex::Locker lock(config_cache.lock); + Mutex::Locker lock(module_config.lock); - if (config_cache.config.count(global_key)) { - *val = config_cache.config.at(global_key); + if (module_config.config.count(global_key)) { + *val = module_config.config.at(global_key); return true; } else { return false; @@ -485,10 +476,10 @@ PyObject *ActivePyModules::get_config_prefix(const std::string &module_name, PyFormatter f; - Mutex::Locker lock(config_cache.lock); + Mutex::Locker lock(module_config.lock); - for (auto p = config_cache.config.lower_bound(global_prefix); - p != config_cache.config.end() && p->first.find(global_prefix) == 0; + for (auto p = module_config.config.lower_bound(global_prefix); + p != module_config.config.end() && p->first.find(global_prefix) == 0; ++p) { f.dump_string(p->first.c_str() + base_prefix.size(), p->second); } @@ -507,12 +498,10 @@ void ActivePyModules::set_store(const std::string &module_name, Mutex::Locker l(lock); PyEval_RestoreThread(tstate); - Mutex::Locker lock(config_cache.lock); - if (val) { - config_cache.config[global_key] = *val; + store_cache[global_key] = *val; } else { - config_cache.config.erase(global_key); + store_cache.erase(global_key); } std::ostringstream cmd_json; @@ -554,12 +543,12 @@ void ActivePyModules::set_config(const std::string &module_name, Mutex::Locker l(lock); PyEval_RestoreThread(tstate); - Mutex::Locker lock(config_cache.lock); + Mutex::Locker lock(module_config.lock); if (val) { - config_cache.config[global_key] = *val; + module_config.config[global_key] = *val; } else { - config_cache.config.erase(global_key); + module_config.config.erase(global_key); } std::ostringstream cmd_json; diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index cdd5ab44d3752..da0029f517f0c 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -31,9 +31,9 @@ class health_check_map_t; class ActivePyModules { - std::map> modules; - PyModuleConfig config_cache; + PyModuleConfig &module_config; + std::map store_cache; DaemonStateIndex &daemon_state; ClusterState &cluster_state; MonClient &monc; diff --git a/src/mgr/StandbyPyModules.h b/src/mgr/StandbyPyModules.h index b115cee13e4e4..fe2de8f279a75 100644 --- a/src/mgr/StandbyPyModules.h +++ b/src/mgr/StandbyPyModules.h @@ -26,8 +26,6 @@ #include "mon/MgrMap.h" #include "mgr/PyModuleRunner.h" -//typedef std::map PyModuleConfig; - /** * State that is read by all modules running in standby mode */ @@ -36,13 +34,10 @@ class StandbyPyModuleState mutable Mutex lock{"StandbyPyModuleState::lock"}; MgrMap mgr_map; - //PyModuleConfig config_cache; - - + PyModuleConfig &module_config; public: - PyModuleConfig &module_config; StandbyPyModuleState(PyModuleConfig &module_config_) : module_config(module_config_)