]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: index daemon state by string service type
authorSage Weil <sage@redhat.com>
Thu, 22 Jun 2017 18:19:17 +0000 (14:19 -0400)
committerSage Weil <sage@redhat.com>
Sun, 9 Jul 2017 02:30:27 +0000 (22:30 -0400)
If we use a string we can allow for other service names like
'rgw' and 'rbd-mirror' and 'iscsigw' and so on.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/DaemonServer.cc
src/mgr/DaemonState.cc
src/mgr/DaemonState.h
src/mgr/Mgr.cc
src/mgr/PyModules.cc
src/mgr/PyModules.h
src/mgr/PyState.cc
src/pybind/mgr/mgr_module.py

index e6b3100f09d88a0d8ce9ff4a2b0119ef102e997d..b2e40b41659ee9af395830d0c4da6f079f0f92e3 100644 (file)
@@ -262,7 +262,7 @@ void DaemonServer::shutdown()
 bool DaemonServer::handle_open(MMgrOpen *m)
 {
   uint32_t type = m->get_connection()->get_peer_type();
-  DaemonKey key(type, m->daemon_name);
+  DaemonKey key(ceph_entity_type_name(type), m->daemon_name);
 
   dout(4) << "from " << m->get_connection() << " name "
           << ceph_entity_type_name(type) << "." << m->daemon_name << dendl;
@@ -288,7 +288,7 @@ bool DaemonServer::handle_open(MMgrOpen *m)
 bool DaemonServer::handle_report(MMgrReport *m)
 {
   uint32_t type = m->get_connection()->get_peer_type();
-  DaemonKey key(type, m->daemon_name);
+  DaemonKey key(ceph_entity_type_name(type), m->daemon_name);
 
   dout(4) << "from " << m->get_connection() << " name "
           << ceph_entity_type_name(type) << "." << m->daemon_name << dendl;
index 290fde6513453ebccdc2e1df74ecf17447128120..2c7f52f30fa75cae056d694c819c49661fa4d6c9 100644 (file)
@@ -46,14 +46,15 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk)
   all.erase(to_erase);
 }
 
-DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
+DaemonStateCollection DaemonStateIndex::get_by_service(
+  const std::string& svc) const
 {
   Mutex::Locker l(lock);
 
   DaemonStateCollection result;
 
   for (const auto &i : all) {
-    if (i.first.first == type) {
+    if (i.first.first == svc) {
       result[i.first] = i.second;
     }
   }
@@ -86,17 +87,17 @@ DaemonStatePtr DaemonStateIndex::get(const DaemonKey &key)
   return all.at(key);
 }
 
-void DaemonStateIndex::cull(entity_type_t daemon_type,
+void DaemonStateIndex::cull(const std::string& svc_name,
                            const std::set<std::string>& names_exist)
 {
   std::vector<string> victims;
 
   Mutex::Locker l(lock);
-  auto begin = all.lower_bound({daemon_type, ""});
+  auto begin = all.lower_bound({svc_name, ""});
   auto end = all.end();
   for (auto &i = begin; i != end; ++i) {
     const auto& daemon_key = i->first;
-    if (daemon_key.first != daemon_type)
+    if (daemon_key.first != svc_name)
       break;
     if (names_exist.count(daemon_key.second) == 0) {
       victims.push_back(daemon_key.second);
@@ -105,7 +106,7 @@ void DaemonStateIndex::cull(entity_type_t daemon_type,
 
   for (auto &i : victims) {
     dout(4) << "Removing data for " << i << dendl;
-    _erase({daemon_type, i});
+    _erase({svc_name, i});
   }
 }
 
index 91160d7f082cd41b7dc56a24715866f9639f0a67..bad83bb8fec7787c594a69884778172e2f8b1887 100644 (file)
@@ -29,7 +29,7 @@
 
 
 // Unique reference to a daemon within a cluster
-typedef std::pair<entity_type_t, std::string> DaemonKey;
+typedef std::pair<std::string, std::string> DaemonKey;
 
 // An instance of a performance counter type, within
 // a particular daemon.
@@ -146,7 +146,7 @@ class DaemonStateIndex
   bool exists(const DaemonKey &key) const;
   DaemonStatePtr get(const DaemonKey &key);
   DaemonStateCollection get_by_server(const std::string &hostname) const;
-  DaemonStateCollection get_by_type(uint8_t type) const;
+  DaemonStateCollection get_by_service(const std::string &svc_name) const;
 
   const DaemonStateCollection &get_all() const {return all;}
   const std::map<std::string, DaemonStateCollection> &get_all_servers() const
@@ -164,7 +164,8 @@ class DaemonStateIndex
    * a cluster map and want to ensure that anything absent in the map
    * is also absent in this class.
    */
-  void cull(entity_type_t daemon_type, const std::set<std::string>& names_exist);
+  void cull(const std::string& svc_name,
+           const std::set<std::string>& names_exist);
 };
 
 #endif
index ffc8e008ab025de23357ae0c1e49fc0b1612c27c..e5ed5eedaa9e3d0480d27937ffe722ceb1e8ce09 100644 (file)
@@ -93,14 +93,13 @@ public:
   {
     daemon_state.clear_updating(key);
     if (r == 0) {
-      if (key.first == CEPH_ENTITY_TYPE_MDS) {
+      if (key.first == "mds") {
         json_spirit::mValue json_result;
         bool read_ok = json_spirit::read(
             outbl.to_str(), json_result);
         if (!read_ok) {
           dout(1) << "mon returned invalid JSON for "
-                  << ceph_entity_type_name(key.first)
-                  << "." << key.second << dendl;
+                  << key.first << "." << key.second << dendl;
           return;
         }
 
@@ -134,14 +133,14 @@ public:
 
           daemon_state.insert(state);
         }
-      } else if (key.first == CEPH_ENTITY_TYPE_OSD) {
+      } else if (key.first == "osd") {
       } else {
         ceph_abort();
       }
     } else {
       dout(1) << "mon failed to return metadata for "
-              << ceph_entity_type_name(key.first)
-              << "." << key.second << ": " << cpp_strerror(r) << dendl;
+              << key.first << "." << key.second << ": "
+             << cpp_strerror(r) << dendl;
     }
   }
 };
@@ -260,7 +259,7 @@ void Mgr::load_all_metadata()
     }
 
     DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
-    dm->key = DaemonKey(CEPH_ENTITY_TYPE_MDS,
+    dm->key = DaemonKey("mds",
                         daemon_meta.at("name").get_str());
     dm->hostname = daemon_meta.at("hostname").get_str();
 
@@ -282,7 +281,7 @@ void Mgr::load_all_metadata()
     }
 
     DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
-    dm->key = DaemonKey(CEPH_ENTITY_TYPE_MON,
+    dm->key = DaemonKey("mon",
                         daemon_meta.at("name").get_str());
     dm->hostname = daemon_meta.at("hostname").get_str();
 
@@ -305,7 +304,7 @@ void Mgr::load_all_metadata()
     dout(4) << osd_metadata.at("hostname").get_str() << dendl;
 
     DaemonStatePtr dm = std::make_shared<DaemonState>(daemon_state.types);
-    dm->key = DaemonKey(CEPH_ENTITY_TYPE_OSD,
+    dm->key = DaemonKey("osd",
                         stringify(osd_metadata.at("id").get_int()));
     dm->hostname = osd_metadata.at("hostname").get_str();
 
@@ -401,7 +400,7 @@ void Mgr::handle_osd_map()
 
       // Consider whether to update the daemon metadata (new/restarted daemon)
       bool update_meta = false;
-      const auto k = DaemonKey(CEPH_ENTITY_TYPE_OSD, stringify(osd_id));
+      const auto k = DaemonKey("osd", stringify(osd_id));
       if (daemon_state.is_updating(k)) {
         continue;
       }
@@ -446,7 +445,7 @@ void Mgr::handle_osd_map()
   });
 
   // TODO: same culling for MonMap
-  daemon_state.cull(CEPH_ENTITY_TYPE_OSD, names_exist);
+  daemon_state.cull("osd", names_exist);
 }
 
 void Mgr::handle_log(MLog *m)
@@ -525,7 +524,7 @@ void Mgr::handle_fs_map(MFSMap* m)
     // Remember which MDS exists so that we can cull any that don't
     names_exist.insert(info.name);
 
-    const auto k = DaemonKey(CEPH_ENTITY_TYPE_MDS, info.name);
+    const auto k = DaemonKey("mds", info.name);
     if (daemon_state.is_updating(k)) {
       continue;
     }
@@ -565,7 +564,7 @@ void Mgr::handle_fs_map(MFSMap* m)
           {}, &c->outbl, &c->outs, c);
     }
   }
-  daemon_state.cull(CEPH_ENTITY_TYPE_MDS, names_exist);
+  daemon_state.cull("mds", names_exist);
 }
 
 bool Mgr::got_mgr_map(const MgrMap& m)
index 96b2698e3c39f8a7208eb1586c171685b49e9aa7..e561c9e481a338954038fc8c0b54854d1a0ec179 100644 (file)
@@ -58,7 +58,7 @@ void PyModules::dump_server(const std::string &hostname,
 
   for (const auto &i : dmc) {
     const auto &key = i.first;
-    const std::string str_type = ceph_entity_type_name(key.first);
+    const std::string &str_type = key.first;
     const std::string &svc_name = key.second;
 
     // TODO: pick the highest version, and make sure that
@@ -116,10 +116,12 @@ PyObject *PyModules::list_servers_python()
   return f.get();
 }
 
-PyObject *PyModules::get_metadata_python(std::string const &handle,
-    entity_type_t svc_type, const std::string &svc_id)
+PyObject *PyModules::get_metadata_python(
+  std::string const &handle,
+  const std::string &svc_name,
+  const std::string &svc_id)
 {
-  auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id));
+  auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id));
   PyFormatter f;
   f.dump_string("hostname", metadata->hostname);
   for (const auto &i : metadata->metadata) {
@@ -175,7 +177,7 @@ PyObject *PyModules::get_python(const std::string &what)
     return f.get();
   } else if (what == "osd_metadata") {
     PyFormatter f;
-    auto dmc = daemon_state.get_by_type(CEPH_ENTITY_TYPE_OSD);
+    auto dmc = daemon_state.get_by_service("osd");
     for (const auto &i : dmc) {
       f.open_object_section(i.first.second.c_str());
       f.dump_string("hostname", i.second->hostname);
@@ -617,7 +619,7 @@ void PyModules::log(const std::string &handle,
 
 PyObject* PyModules::get_counter_python(
     const std::string &handle,
-    entity_type_t svc_type,
+    const std::string &svc_name,
     const std::string &svc_id,
     const std::string &path)
 {
@@ -628,7 +630,7 @@ PyObject* PyModules::get_counter_python(
   PyFormatter f;
   f.open_array_section(path.c_str());
 
-  auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id));
+  auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id));
 
   // FIXME: this is unsafe, I need to either be inside DaemonStateIndex's
   // lock or put a lock on individual DaemonStates
@@ -645,8 +647,7 @@ PyObject* PyModules::get_counter_python(
       }
     } else {
       dout(4) << "Missing counter: '" << path << "' ("
-              << ceph_entity_type_name(svc_type) << "."
-              << svc_id << ")" << dendl;
+              << svc_name << "." << svc_id << ")" << dendl;
       dout(20) << "Paths are:" << dendl;
       for (const auto &i : metadata->perf_counters.instances) {
         dout(20) << i.first << dendl;
@@ -654,8 +655,7 @@ PyObject* PyModules::get_counter_python(
     }
   } else {
     dout(4) << "No daemon state for "
-              << ceph_entity_type_name(svc_type) << "."
-              << svc_id << ")" << dendl;
+              << svc_name << "." << svc_id << ")" << dendl;
   }
   f.close_section();
   return f.get();
index 93cbd5be8518a1a360a186ebe0b441a47a684ce5..80f8813d5ee0c502efe46172dc6b226da766c963 100644 (file)
@@ -64,11 +64,14 @@ public:
   PyObject *get_python(const std::string &what);
   PyObject *get_server_python(const std::string &hostname);
   PyObject *list_servers_python();
-  PyObject *get_metadata_python(std::string const &handle,
-      entity_type_t svc_type, const std::string &svc_id);
-  PyObject *get_counter_python(std::string const &handle,
-      entity_type_t svc_type, const std::string &svc_id,
-      const std::string &path);
+  PyObject *get_metadata_python(
+    std::string const &handle,
+    const std::string &svc_name, const std::string &svc_id);
+  PyObject *get_counter_python(
+    std::string const &handle,
+    const std::string &svc_name,
+    const std::string &svc_id,
+    const std::string &path);
   PyObject *get_context();
 
   std::map<std::string, std::string> config_cache;
index 963526fc519d7c457f5f37f845942034d64368f6..dbde1e2252867bd088d36809c6fe56422735de42 100644 (file)
@@ -266,37 +266,16 @@ ceph_config_set(PyObject *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
-static entity_type_t svc_type_from_str(const std::string &type_str)
-{
-  if (type_str == std::string("mds")) {
-    return CEPH_ENTITY_TYPE_MDS;
-  } else if (type_str == std::string("osd")) {
-    return CEPH_ENTITY_TYPE_OSD;
-  } else if (type_str == std::string("mon")) {
-    return CEPH_ENTITY_TYPE_MON;
-  } else {
-    return CEPH_ENTITY_TYPE_ANY;
-  }
-}
-
 static PyObject*
 get_metadata(PyObject *self, PyObject *args)
 {
   char *handle = nullptr;
-  char *type_str = NULL;
+  char *svc_name = NULL;
   char *svc_id = NULL;
-  if (!PyArg_ParseTuple(args, "sss:get_metadata", &handle, &type_str, &svc_id)) {
-    return nullptr;
-  }
-
-  entity_type_t svc_type = svc_type_from_str(type_str);
-  if (svc_type == CEPH_ENTITY_TYPE_ANY) {
-    // FIXME: form a proper exception
+  if (!PyArg_ParseTuple(args, "sss:get_metadata", &handle, &svc_name, &svc_id)) {
     return nullptr;
   }
-
-
-  return global_handle->get_metadata_python(handle, svc_type, svc_id);
+  return global_handle->get_metadata_python(handle, svc_name, svc_id);
 }
 
 static PyObject*
@@ -330,22 +309,15 @@ static PyObject*
 get_counter(PyObject *self, PyObject *args)
 {
   char *handle = nullptr;
-  char *type_str = nullptr;
+  char *svc_name = nullptr;
   char *svc_id = nullptr;
   char *counter_path = nullptr;
-  if (!PyArg_ParseTuple(args, "ssss:get_counter", &handle, &type_str,
+  if (!PyArg_ParseTuple(args, "ssss:get_counter", &handle, &svc_name,
                                                   &svc_id, &counter_path)) {
     return nullptr;
   }
-
-  entity_type_t svc_type = svc_type_from_str(type_str);
-  if (svc_type == CEPH_ENTITY_TYPE_ANY) {
-    // FIXME: form a proper exception
-    return nullptr;
-  }
-
   return global_handle->get_counter_python(
-      handle, svc_type, svc_id, counter_path);
+      handle, svc_name, svc_id, counter_path);
 }
 
 PyMethodDef CephStateMethods[] = {
index 2e4ba6b142c9c68ee4d4ad2dd40bf244a08aae2d..8d5b0f9de6f5b818ea66584575376a9163660726 100644 (file)
@@ -134,7 +134,7 @@ class MgrModule(object):
         """
         Fetch the metadata for a particular service.
 
-        :param svc_type: one of 'mds', 'osd', 'mon'
+        :param svc_type: string (e.g., 'mds', 'osd', 'mon')
         :param svc_id: string
         :return: dict
         """