From: John Spray Date: Sat, 16 Jul 2016 21:04:39 +0000 (+0100) Subject: mgr: enable active daemon to return to standby X-Git-Tag: v11.0.1~60^2~41 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fd537bc696d65ce3baec88ecf5a825f7eaaaf484;p=ceph.git mgr: enable active daemon to return to standby Rather than respawn a whole process, just fall back to being a standby. Signed-off-by: John Spray --- diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index bcc27855296..c458c7d9cb8 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -11,6 +11,7 @@ * Foundation. See file COPYING. */ +#include "osdc/Objecter.h" #include "common/errno.h" #include "mon/MonClient.h" #include "include/stringify.h" @@ -33,9 +34,9 @@ #define dout_prefix *_dout << "mgr " << __func__ << " " -Mgr::Mgr(MonClient *monc_, Messenger *clientm_) : +Mgr::Mgr(MonClient *monc_, Messenger *clientm_, Objecter *objecter_) : monc(monc_), - objecter(NULL), + objecter(objecter_), client_messenger(clientm_), lock("Mgr::lock"), timer(g_ceph_context, lock), @@ -47,16 +48,12 @@ Mgr::Mgr(MonClient *monc_, Messenger *clientm_) : initialized(false), initializing(false) { - // Using Objecter to handle incremental decode of OSDMap - objecter = new Objecter(g_ceph_context, client_messenger, monc, NULL, 0, 0); - cluster_state.set_objecter(objecter); } Mgr::~Mgr() { - delete objecter; assert(waiting_for_fs_map == nullptr); } @@ -139,12 +136,6 @@ void Mgr::init() assert(initializing); assert(!initialized); - objecter->set_client_incarnation(0); - objecter->init(); - - // Dispatcher before starting objecter - client_messenger->add_dispatcher_head(objecter); - // Start communicating with daemons to learn statistics etc server.init(monc->get_global_id(), client_messenger->get_myaddr()); dout(4) << "Initialized server at " << server.get_myaddr() << dendl; @@ -161,7 +152,6 @@ void Mgr::init() load_config(); // Start Objecter and wait for OSD map - objecter->start(); lock.Unlock(); // Drop lock because OSDMap dispatch calls into my ms_dispatch objecter->wait_for_osd_map(); lock.Lock(); @@ -330,8 +320,6 @@ void Mgr::shutdown() // Then stop the finisher to ensure its enqueued contexts aren't going // to touch references to the things we're about to tear down finisher.stop(); - - objecter->shutdown(); } void Mgr::handle_osd_map() diff --git a/src/mgr/Mgr.h b/src/mgr/Mgr.h index 825edf15333..ffe1d1460c9 100644 --- a/src/mgr/Mgr.h +++ b/src/mgr/Mgr.h @@ -23,7 +23,6 @@ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE -#include "osdc/Objecter.h" #include "mds/FSMap.h" #include "messages/MFSMap.h" #include "msg/Messenger.h" @@ -39,6 +38,7 @@ class MCommand; class MMgrDigest; +class Objecter; class MgrPyModule; @@ -69,7 +69,7 @@ protected: bool initializing; public: - Mgr(MonClient *monc_, Messenger *clientm_); + Mgr(MonClient *monc_, Messenger *clientm_, Objecter *objecter_); ~Mgr(); bool is_initialized() const {return initialized;} diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index 896fb166f74..0cb0cd01c1c 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -38,11 +38,13 @@ MgrStandby::MgrStandby() : active_mgr(nullptr) { client_messenger = Messenger::create_client_messenger(g_ceph_context, "mgr"); + objecter = new Objecter(g_ceph_context, client_messenger, monc, NULL, 0, 0); } MgrStandby::~MgrStandby() { + delete objecter; delete monc; delete client_messenger; delete active_mgr; @@ -82,6 +84,11 @@ int MgrStandby::init() client_t whoami = monc->get_global_id(); client_messenger->set_myname(entity_name_t::CLIENT(whoami.v)); + objecter->set_client_incarnation(0); + objecter->init(); + client_messenger->add_dispatcher_head(objecter); + objecter->start(); + timer.init(); send_beacon(); @@ -127,12 +134,40 @@ void MgrStandby::shutdown() active_mgr->shutdown(); } + objecter->shutdown(); + timer.shutdown(); monc->shutdown(); client_messenger->shutdown(); } +void MgrStandby::handle_mgr_map(MMgrMap* mmap) +{ + auto map = mmap->get_map(); + dout(4) << "received map epoch " << map.get_epoch() << dendl; + const bool active_in_map = map.active_gid == monc->get_global_id(); + dout(4) << "active in map: " << active_in_map + << " active is " << map.active_gid << dendl; + if (active_in_map) { + if (active_mgr == nullptr) { + dout(1) << "Activating!" << dendl; + active_mgr = new Mgr(monc, client_messenger, objecter); + active_mgr->background_init(); + dout(1) << "I am now active" << dendl; + } else { + dout(10) << "I was already active" << dendl; + } + } else { + if (active_mgr != nullptr) { + derr << "I was active but no longer am" << dendl; + active_mgr->shutdown(); + delete active_mgr; + active_mgr = nullptr; + } + } +} + bool MgrStandby::ms_dispatch(Message *m) { Mutex::Locker l(lock); @@ -140,31 +175,7 @@ bool MgrStandby::ms_dispatch(Message *m) switch (m->get_type()) { case MSG_MGR_MAP: - { - auto mmap = static_cast(m); - auto map = mmap->get_map(); - dout(4) << "received map epoch " << map.get_epoch() << dendl; - const bool active_in_map = map.active_gid == monc->get_global_id(); - dout(4) << "active in map: " << active_in_map - << " active is " << map.active_gid << dendl; - if (active_in_map) { - if (active_mgr == nullptr) { - dout(1) << "Activating!" << dendl; - active_mgr = new Mgr(monc, client_messenger); - active_mgr->background_init(); - dout(1) << "I am now active" << dendl; - } else { - dout(10) << "I was already active" << dendl; - } - } else { - if (active_mgr != nullptr) { - derr << "I was active but no longer am" << dendl; - shutdown(); - // FIXME: should politely go back to standby (or respawn - // process) instead of stopping entirely. - } - } - } + handle_mgr_map(static_cast(m)); break; default: @@ -174,6 +185,8 @@ bool MgrStandby::ms_dispatch(Message *m) return false; } } + + m->put(); return true; } diff --git a/src/mgr/MgrStandby.h b/src/mgr/MgrStandby.h index ccb44d74b71..4c46a0730ee 100644 --- a/src/mgr/MgrStandby.h +++ b/src/mgr/MgrStandby.h @@ -25,11 +25,13 @@ #include "DaemonState.h" #include "ClusterState.h" +class MMgrMap; class Mgr; class MgrStandby : public Dispatcher { protected: MonClient *monc; + Objecter *objecter; Messenger *client_messenger; Mutex lock; @@ -39,6 +41,8 @@ protected: std::string state_str(); + void handle_mgr_map(MMgrMap *m); + public: MgrStandby(); ~MgrStandby();