From: Radoslaw Zarzynski Date: Fri, 27 Mar 2020 13:55:36 +0000 (+0100) Subject: mgr: synchronize ClusterState's health and mon_status. X-Git-Tag: v14.2.10~137^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1f87c58e5d32c967a821032e0b98a34b7ec80e52;p=ceph.git mgr: synchronize ClusterState's health and mon_status. Fixes: https://tracker.ceph.com/issues/24995 Signed-off-by: Radoslaw Zarzynski (cherry picked from commit da362675da51de8b20a12e4cec479a77c7f5442b) --- diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index a554475dcdd5..ce1076534e33 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -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) { diff --git a/src/mgr/ClusterState.cc b/src/mgr/ClusterState.cc index 891bd562a51f..8502e570e854 100644 --- a/src/mgr/ClusterState.cc +++ b/src/mgr/ClusterState.cc @@ -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); } diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index 0298f62ec29a..a78d0687e4cf 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -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)...); } + + template + void with_health(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + std::forward(cb)(health_json, std::forward(args)...); + } + + template + void with_mon_status(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + std::forward(cb)(mon_status_json, std::forward(args)...); + } + void final_init(); void shutdown(); bool asok_command(std::string_view admin_command, const cmdmap_t& cmdmap,