]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: separate out module_config and store_cache
authorJohn Spray <john.spray@redhat.com>
Wed, 4 Apr 2018 13:19:57 +0000 (09:19 -0400)
committerJohn Spray <john.spray@redhat.com>
Mon, 23 Apr 2018 11:29:45 +0000 (07:29 -0400)
Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/ActivePyModules.cc
src/mgr/ActivePyModules.h
src/mgr/StandbyPyModules.h

index 4c6cb05443c7fa7e97e78d7f13b29e778fa39edb..5bc1fbdcc4602ee74a852110ea8f130a85bbeaae 100644 (file)
 #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;
index cdd5ab44d3752cb889d1f3cf843cb13bd925a6d2..da0029f517f0cb42ed054d872c979265be4cc4ac 100644 (file)
@@ -31,9 +31,9 @@ class health_check_map_t;
 
 class ActivePyModules
 {
-
   std::map<std::string, std::unique_ptr<ActivePyModule>> modules;
-  PyModuleConfig config_cache;
+  PyModuleConfig &module_config;
+  std::map<std::string, std::string> store_cache;
   DaemonStateIndex &daemon_state;
   ClusterState &cluster_state;
   MonClient &monc;
index b115cee13e4e40883a3a95f55fe745cc7760cc7c..fe2de8f279a75d4883c306c067fcd6acdf783c13 100644 (file)
@@ -26,8 +26,6 @@
 #include "mon/MgrMap.h"
 #include "mgr/PyModuleRunner.h"
 
-//typedef std::map<std::string, std::string> 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_)