]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: synchronize ClusterState's health and mon_status. 34326/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 27 Mar 2020 13:55:36 +0000 (14:55 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 31 Mar 2020 18:02:26 +0000 (20:02 +0200)
Fixes: https://tracker.ceph.com/issues/24995
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
(cherry picked from commit da362675da51de8b20a12e4cec479a77c7f5442b)

src/mgr/ActivePyModules.cc
src/mgr/ClusterState.cc
src/mgr/ClusterState.h

index a554475dcdd53f5bf948a8b4669517100673e59d..ce1076534e333d748581c0445b6b29afdc26e2ab 100644 (file)
@@ -379,18 +379,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 891bd562a51fadae638af1ccc2ffafb49a09a042..8502e570e854cf18adffb0362cb10b843a396e93 100644 (file)
@@ -63,6 +63,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 0298f62ec29acbf0239c2506c5d2cad5e5b31be0..a78d0687e4cfc06cbcef718e12f15d2e2c0bccd9 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, const cmdmap_t& cmdmap,