]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: synchronize ClusterState's health and mon_status. 34245/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 27 Mar 2020 13:55:36 +0000 (14:55 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 27 Mar 2020 22:59:53 +0000 (23:59 +0100)
Fixes: https://tracker.ceph.com/issues/24995
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/mgr/ActivePyModules.cc
src/mgr/ClusterState.cc
src/mgr/ClusterState.h

index e243ba0612c8389aa4ef71a4a366f07e83a9f01a..3a2c6d60c024472a8db321fd27c46b635e99f0fd 100644 (file)
@@ -414,18 +414,19 @@ PyObject *ActivePyModules::get_python(const std::string &what)
         f.close_section();
     });
     return f.get();
-  } else if (what == "health" || what == "mon_status") {
-    bufferlist json;
-    if (what == "health") {
-      json = cluster_state.get_health();
-    } else if (what == "mon_status") {
-      json = cluster_state.get_mon_status();
-    } else {
-      ceph_abort();
-    }
-
-    PyEval_RestoreThread(tstate);
-    f.dump_string("json", json.to_str());
+  } else if (what == "health") {
+    cluster_state.with_health(
+        [&f, &tstate](const ceph::bufferlist &health_json) {
+      PyEval_RestoreThread(tstate);
+      f.dump_string("json", health_json.to_str());
+    });
+    return f.get();
+  } else if (what == "mon_status") {
+    cluster_state.with_mon_status(
+        [&f, &tstate](const ceph::bufferlist &mon_status_json) {
+      PyEval_RestoreThread(tstate);
+      f.dump_string("json", mon_status_json.to_str());
+    });
     return f.get();
   } else if (what == "mgr_map") {
     cluster_state.with_mgrmap([&f, &tstate](const MgrMap &mgr_map) {
index 54c016dd3469c1c032cc4666ed2925339dec5a4b..fc7d42cb073cf08b9f9c2da6373a43bb3ab74334 100644 (file)
@@ -62,6 +62,7 @@ void ClusterState::set_service_map(ServiceMap const &new_service_map)
 
 void ClusterState::load_digest(MMgrDigest *m)
 {
+  std::lock_guard l(lock);
   health_json = std::move(m->health_json);
   mon_status_json = std::move(m->mon_status_json);
 }
index 3b06808de86be162868c63f8aea5ca118fa911c3..e0ac3f31761f89fcf7559e4588098b6daf5fc409 100644 (file)
@@ -59,9 +59,6 @@ public:
 
   void update_delta_stats();
 
-  const bufferlist &get_health() const {return health_json;}
-  const bufferlist &get_mon_status() const {return mon_status_json;}
-
   ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap);
 
   void set_objecter(Objecter *objecter_);
@@ -139,6 +136,21 @@ public:
       pg_map,
       std::forward<Args>(args)...);
   }
+
+  template<typename Callback, typename...Args>
+  void with_health(Callback&& cb, Args&&...args) const
+  {
+    std::lock_guard l(lock);
+    std::forward<Callback>(cb)(health_json, std::forward<Args>(args)...);
+  }
+
+  template<typename Callback, typename...Args>
+  void with_mon_status(Callback&& cb, Args&&...args) const
+  {
+    std::lock_guard l(lock);
+    std::forward<Callback>(cb)(mon_status_json, std::forward<Args>(args)...);
+  }
+
   void final_init();
   void shutdown();
   bool asok_command(std::string_view admin_command,