From 8ce30bc4cd2325bfbc238fd76952729cf4f7e0a6 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 27 Mar 2017 12:55:12 +0200 Subject: [PATCH] mgr: fix metadata handling from old MDS daemons 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 --- src/mgr/Mgr.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index 6be7216b2e4..d2504e4e943 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -70,6 +70,8 @@ class MetadataUpdate : public Context DaemonStateIndex &daemon_state; DaemonKey key; + std::map 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 << "\"}"; -- 2.47.3