* Foundation. See file COPYING.
*/
+#include "osdc/Objecter.h"
#include "common/errno.h"
#include "mon/MonClient.h"
#include "include/stringify.h"
#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),
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);
}
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;
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();
// 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()
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;
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();
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);
switch (m->get_type()) {
case MSG_MGR_MAP:
- {
- auto mmap = static_cast<MMgrMap*>(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<MMgrMap*>(m));
break;
default:
return false;
}
}
+
+ m->put();
return true;
}