From cf68ce511f31d3746ca1cb13a9d3b39c25bb06a8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 5 Jan 2018 14:55:12 -0600 Subject: [PATCH] mgr: have MgrStandby send mgr reports to active mgr (even self!) This allows the mgr daemons to register state with the active mgr just like the rest of the cluster, including perfcounters and current config. Signed-off-by: Sage Weil --- src/mgr/DaemonServer.cc | 28 ++++++++++++++++++++++++++++ src/mgr/DaemonServer.h | 1 + src/mgr/Mgr.cc | 1 + src/mgr/MgrStandby.cc | 32 ++++++++++++++++++++++---------- src/mgr/MgrStandby.h | 4 +++- 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index f57933deb04..0f1cafad7af 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1662,6 +1662,34 @@ void DaemonServer::got_service_map() } } +void DaemonServer::got_mgr_map() +{ + Mutex::Locker l(lock); + set have; + cluster_state.with_mgrmap([&](const MgrMap& mgrmap) { + if (mgrmap.active_name.size()) { + DaemonKey key("mgr", mgrmap.active_name); + have.insert(mgrmap.active_name); + if (!daemon_state.exists(key)) { + auto daemon = std::make_shared(daemon_state.types); + daemon->key = key; + daemon_state.insert(daemon); + dout(10) << "added missing " << key << dendl; + } + } + for (auto& i : mgrmap.standbys) { + DaemonKey key("mgr", i.second.name); + have.insert(i.second.name); + if (!daemon_state.exists(key)) { + auto daemon = std::make_shared(daemon_state.types); + daemon->key = key; + daemon_state.insert(daemon); + dout(10) << "added missing " << key << dendl; + } + } + }); + daemon_state.cull("mgr", have); +} const char** DaemonServer::get_tracked_conf_keys() const { diff --git a/src/mgr/DaemonServer.h b/src/mgr/DaemonServer.h index 9c0575461d2..6a01714c4f0 100644 --- a/src/mgr/DaemonServer.h +++ b/src/mgr/DaemonServer.h @@ -136,6 +136,7 @@ public: bool handle_command(MCommand *m); void send_report(); void got_service_map(); + void got_mgr_map(); void _send_configure(ConnectionRef c); diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index e2b73fdee64..0c901a6933e 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -593,6 +593,7 @@ bool Mgr::got_mgr_map(const MgrMap& m) } cluster_state.set_mgr_map(m); + server.got_mgr_map(); return false; } diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index 2172dbc5e5f..0cb1ab2ac4b 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -39,9 +39,16 @@ MgrStandby::MgrStandby(int argc, const char **argv) : Dispatcher(g_ceph_context), monc{g_ceph_context}, - client_messenger(Messenger::create_client_messenger(g_ceph_context, "mgr")), + client_messenger(Messenger::create( + g_ceph_context, + cct->_conf->get_val("ms_type"), + entity_name_t::MGR(), + "mgr", + getpid(), + 0)), objecter{g_ceph_context, client_messenger.get(), &monc, NULL, 0, 0}, client{client_messenger.get(), &monc, &objecter}, + mgrc(g_ceph_context, client_messenger.get()), log_client(g_ceph_context, client_messenger.get(), &monc.monmap, LogClient::NO_FLAGS), clog(log_client.create_channel(CLOG_CHANNEL_CLUSTER)), audit_clog(log_client.create_channel(CLOG_CHANNEL_AUDIT)), @@ -125,6 +132,9 @@ int MgrStandby::init() client_messenger->wait(); return r; } + mgrc.init(); + client_messenger->add_dispatcher_tail(&mgrc); + r = monc.authenticate(); if (r < 0) { derr << "Authentication failed, did you specify a mgr ID with a valid keyring?" << dendl; @@ -135,7 +145,7 @@ int MgrStandby::init() } client_t whoami = monc.get_global_id(); - client_messenger->set_myname(entity_name_t::CLIENT(whoami.v)); + client_messenger->set_myname(entity_name_t::MGR(whoami.v)); monc.set_log_client(&log_client); _update_log_config(); objecter.set_client_incarnation(0); @@ -241,6 +251,7 @@ void MgrStandby::shutdown() timer.shutdown(); // client uses monc and objecter client.shutdown(); + mgrc.shutdown(); // stop monc, so mon won't be able to instruct me to shutdown/activate after // the active_mgr is stopped monc.shutdown(); @@ -380,8 +391,6 @@ void MgrStandby::handle_mgr_map(MMgrMap* mmap) } } } - - mmap->put(); } bool MgrStandby::ms_dispatch(Message *m) @@ -391,16 +400,19 @@ bool MgrStandby::ms_dispatch(Message *m) if (m->get_type() == MSG_MGR_MAP) { handle_mgr_map(static_cast(m)); - return true; - } else if (active_mgr) { + } + bool handled = false; + if (active_mgr) { auto am = active_mgr; lock.Unlock(); - bool handled = am->ms_dispatch(m); + handled = am->ms_dispatch(m); lock.Lock(); - return handled; - } else { - return false; } + if (m->get_type() == MSG_MGR_MAP && !handled) { + m->put(); + handled = true; + } + return handled; } diff --git a/src/mgr/MgrStandby.h b/src/mgr/MgrStandby.h index a64fd7e9995..4d4cc364c31 100644 --- a/src/mgr/MgrStandby.h +++ b/src/mgr/MgrStandby.h @@ -24,7 +24,7 @@ #include "mon/MonClient.h" #include "osdc/Objecter.h" #include "PyModuleRegistry.h" - +#include "MgrClient.h" class MMgrMap; class Mgr; @@ -43,6 +43,8 @@ protected: Objecter objecter; Client client; + MgrClient mgrc; + LogClient log_client; LogChannelRef clog, audit_clog; -- 2.39.5