From f9a4ca07acecd15986cbce61a6e118a6cb05af29 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 8 Sep 2017 11:33:02 -0400 Subject: [PATCH] mgr: fix py calls for dne service perf counters Fixes: http://tracker.ceph.com/issues/21253 Signed-off-by: John Spray --- src/mgr/DaemonState.cc | 7 ++++++- src/mgr/PyModules.cc | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 93fe130190e..f304b18c6fc 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -85,7 +85,12 @@ DaemonStatePtr DaemonStateIndex::get(const DaemonKey &key) { Mutex::Locker l(lock); - return all.at(key); + auto iter = all.find(key); + if (iter != all.end()) { + return iter->second; + } else { + return nullptr; + } } void DaemonStateIndex::cull(const std::string& svc_name, diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index d8b7b01cc62..5fa6df9cf7a 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -679,9 +679,8 @@ PyObject* PyModules::get_counter_python( f.open_array_section(path.c_str()); auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id)); - - Mutex::Locker l2(metadata->lock); if (metadata) { + Mutex::Locker l2(metadata->lock); if (metadata->perf_counters.instances.count(path)) { auto counter_instance = metadata->perf_counters.instances.at(path); const auto &data = counter_instance.get_data(); @@ -726,8 +725,9 @@ PyObject* PyModules::get_perf_schema_python( } else { auto key = DaemonKey(svc_type, svc_id); // so that the below can be a loop in all cases - if (daemon_state.exists(key)) { - states[key] = daemon_state.get(key); + auto got = daemon_state.get(key); + if (got != nullptr) { + states[key] = got; } }