]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/ServiceMap: use plain gid
authorKefu Chai <kchai@redhat.com>
Sun, 25 Aug 2019 06:53:20 +0000 (14:53 +0800)
committerVenky Shankar <vshankar@redhat.com>
Thu, 26 Mar 2020 02:44:12 +0000 (22:44 -0400)
* partially revert 5c25a018. which is not backward compatible.
* change `ServiceMap::get_daemon()` so it returns a
  `pair<Daemon*,bool>`.

git is an `optional<uint64_t>`, so we cannot dump it without checking.

Fixes: http://tracker.ceph.com/issues/41424
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 3e65551d0ab4acafaf4012601987b3391b2411ed)

src/mgr/DaemonServer.cc
src/mgr/ServiceMap.cc
src/mgr/ServiceMap.h

index 61a0950391be6e23ab8e8747fcb4d1ec639c5746..7595f47c8d806992f4c3def4ea881dece001865f 100644 (file)
@@ -469,9 +469,9 @@ bool DaemonServer::handle_open(MMgrOpen *m)
       daemon->service_status = m->daemon_status;
 
       utime_t now = ceph_clock_now();
-      auto d = pending_service_map.get_daemon(m->service_name,
-                                             m->daemon_name);
-      if (!d->gid || d->gid != (uint64_t)m->get_source().num()) {
+      auto [d, added] = pending_service_map.get_daemon(m->service_name,
+                                                      m->daemon_name);
+      if (added || d->gid != (uint64_t)m->get_source().num()) {
        dout(10) << "registering " << key << " in pending_service_map" << dendl;
        d->gid = m->get_source().num();
        d->addr = m->get_source_addr();
@@ -645,12 +645,13 @@ bool DaemonServer::handle_report(MMgrReport *m)
           daemon->service_status = *m->daemon_status;
         }
         if (m->task_status && !map_compare(daemon->task_status, *m->task_status)) {
-          auto d = pending_service_map.get_daemon(m->service_name, m->daemon_name);
-          if (d->gid) {
+          auto [d, added] = pending_service_map.get_daemon(m->service_name,
+                                                          m->daemon_name);
+         if (!added) {
             daemon->task_status = *m->task_status;
             d->task_status = *m->task_status;
             pending_service_map_dirty = pending_service_map.epoch;
-          }
+         }
         }
         daemon->last_service_beacon = now;
       } else if (m->daemon_status) {
index eca0370095585c191b639c1e0e4f83cfc15294e6..054e3a99d67f32ffeecee18cb97efec8ddea6bc2 100644 (file)
@@ -37,7 +37,7 @@ void ServiceMap::Daemon::dump(Formatter *f) const
 {
   f->dump_unsigned("start_epoch", start_epoch);
   f->dump_stream("start_stamp") << start_stamp;
-  f->dump_unsigned("gid", *gid);
+  f->dump_unsigned("gid", gid);
   f->dump_string("addr", addr.get_legacy_str());
   f->open_object_section("metadata");
   for (auto& p : metadata) {
index 3d226dd5454bbcdb9bac086ca82382ed4834e642..f634e18c8203cd4b7b5d4ca7ce8b380320b51e35 100644 (file)
 #include "include/buffer.h"
 #include "msg/msg_types.h"
 
-#include <boost/optional.hpp>
-
 namespace ceph {
   class Formatter;
 }
 
 struct ServiceMap {
   struct Daemon {
-    boost::optional<uint64_t> gid;
+    uint64_t gid = 0;
     entity_addr_t addr;
     epoch_t start_epoch = 0;   ///< epoch first registered
     utime_t start_stamp;       ///< timestamp daemon started/registered
@@ -117,9 +115,11 @@ struct ServiceMap {
   void dump(Formatter *f) const;
   static void generate_test_instances(std::list<ServiceMap*>& ls);
 
-  Daemon* get_daemon(const std::string& service,
-                    const std::string& daemon) {
-    return &services[service].daemons[daemon];
+  std::pair<Daemon*,bool> get_daemon(const std::string& service,
+                                    const std::string& daemon) {
+    auto& s = services[service];
+    auto [d, added] = s.daemons.try_emplace(daemon);
+    return {&d->second, added};
   }
 
   bool rm_daemon(const std::string& service,