]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: fix metadata handling from old MDS daemons 14161/head
authorJohn Spray <john.spray@redhat.com>
Mon, 27 Mar 2017 10:55:12 +0000 (12:55 +0200)
committerJohn Spray <john.spray@redhat.com>
Thu, 20 Apr 2017 15:41:15 +0000 (16:41 +0100)
In abde684 we started always fetching metadata on fsmap changes
for legacy daemons (i.e. those without addr fields) -- this works
but is very inefficient.

By injecting an 'addr' field based on the address in
the FSMap, if the field is missing, we can reload
metadata only on daemon restarts.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/Mgr.cc

index 6be7216b2e4046fbcbdeaa1e5643537ce28318de..d2504e4e943da860e0c5c70dced03ff8fd6bbabc 100644 (file)
@@ -70,6 +70,8 @@ class MetadataUpdate : public Context
   DaemonStateIndex &daemon_state;
   DaemonKey key;
 
+  std::map<std::string, std::string> defaults;
+
 public:
   bufferlist outbl;
   std::string outs;
@@ -77,6 +79,11 @@ public:
   MetadataUpdate(DaemonStateIndex &daemon_state_, const DaemonKey &key_)
     : daemon_state(daemon_state_), key(key_) {}
 
+  void set_default(const std::string &k, const std::string &v)
+  {
+    defaults[k] = v;
+  }
+
   void finish(int r) override
   {
     daemon_state.clear_updating(key);
@@ -94,6 +101,13 @@ public:
 
         json_spirit::mObject daemon_meta = json_result.get_obj();
 
+        // Apply any defaults
+        for (const auto &i : defaults) {
+          if (daemon_meta.find(i.first) == daemon_meta.end()) {
+            daemon_meta[i.first] = i.second;
+          }
+        }
+
         DaemonStatePtr state;
         if (daemon_state.exists(key)) {
           state = daemon_state.get(key);
@@ -508,9 +522,6 @@ void Mgr::handle_fs_map(MFSMap* m)
     bool update = false;
     if (daemon_state.exists(k)) {
       auto metadata = daemon_state.get(k);
-      // FIXME: nothing stopping old daemons being here, they won't have
-      // addr: need to handle case of pre-ceph-mgr daemons that don't have
-      // the fields we expect
       if (metadata->metadata.empty() ||
          metadata->metadata.count("addr") == 0) {
         update = true;
@@ -530,6 +541,11 @@ void Mgr::handle_fs_map(MFSMap* m)
     if (update) {
       daemon_state.notify_updating(k);
       auto c = new MetadataUpdate(daemon_state, k);
+
+      // Older MDS daemons don't have addr in the metadata, so
+      // fake it if the returned metadata doesn't have the field.
+      c->set_default("addr", stringify(info.addr));
+
       std::ostringstream cmd;
       cmd << "{\"prefix\": \"mds metadata\", \"who\": \""
           << info.name << "\"}";