From: Kefu Chai Date: Thu, 4 May 2017 07:39:55 +0000 (+0800) Subject: mgr: do not use pointers for MgrStandby members X-Git-Tag: v12.0.3~52^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=260fea0f59d2e1bf69c913ee1bfbe834a8884d96;p=ceph.git mgr: do not use pointers for MgrStandby members it's simpler and easier to manage the life cycle of them this way. Signed-off-by: Kefu Chai --- diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index ea7055b5bfc2..99eb74db9378 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -14,9 +14,6 @@ #include #include "common/errno.h" -#include "mon/MonClient.h" -#include "osdc/Objecter.h" -#include "client/Client.h" #include "include/stringify.h" #include "global/global_context.h" @@ -38,11 +35,11 @@ MgrStandby::MgrStandby() : Dispatcher(g_ceph_context), - monc(new MonClient(g_ceph_context)), + monc{g_ceph_context}, client_messenger(Messenger::create_client_messenger(g_ceph_context, "mgr")), - objecter(new Objecter(g_ceph_context, client_messenger, monc, NULL, 0, 0)), - client(new Client(client_messenger, monc, objecter)), - log_client(g_ceph_context, client_messenger, &monc->monmap, LogClient::NO_FLAGS), + objecter{g_ceph_context, client_messenger.get(), &monc, NULL, 0, 0}, + client{client_messenger.get(), &monc, &objecter}, + 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)), lock("MgrStandby::lock"), @@ -51,13 +48,7 @@ MgrStandby::MgrStandby() : { } - -MgrStandby::~MgrStandby() -{ - delete objecter; - delete monc; - delete client_messenger; -} +MgrStandby::~MgrStandby() = default; const char** MgrStandby::get_tracked_conf_keys() const { @@ -101,51 +92,48 @@ int MgrStandby::init() // Initialize Messenger client_messenger->add_dispatcher_tail(this); - client_messenger->add_dispatcher_head(objecter); - client_messenger->add_dispatcher_tail(client.get()); + client_messenger->add_dispatcher_head(&objecter); + client_messenger->add_dispatcher_tail(&client); client_messenger->start(); // Initialize MonClient - if (monc->build_initial_monmap() < 0) { + if (monc.build_initial_monmap() < 0) { client_messenger->shutdown(); client_messenger->wait(); return -1; } - monc->sub_want("mgrmap", 0, 0); + monc.sub_want("mgrmap", 0, 0); - monc->set_want_keys(CEPH_ENTITY_TYPE_MON|CEPH_ENTITY_TYPE_OSD + monc.set_want_keys(CEPH_ENTITY_TYPE_MON|CEPH_ENTITY_TYPE_OSD |CEPH_ENTITY_TYPE_MDS|CEPH_ENTITY_TYPE_MGR); - monc->set_messenger(client_messenger); - int r = monc->init(); + monc.set_messenger(client_messenger.get()); + int r = monc.init(); if (r < 0) { - monc->shutdown(); + monc.shutdown(); client_messenger->shutdown(); client_messenger->wait(); return r; } - r = monc->authenticate(); + r = monc.authenticate(); if (r < 0) { derr << "Authentication failed, did you specify a mgr ID with a valid keyring?" << dendl; - monc->shutdown(); + monc.shutdown(); client_messenger->shutdown(); client_messenger->wait(); return r; } - client_t whoami = monc->get_global_id(); + client_t whoami = monc.get_global_id(); client_messenger->set_myname(entity_name_t::CLIENT(whoami.v)); - - monc->set_log_client(&log_client); + monc.set_log_client(&log_client); _update_log_config(); - - objecter->set_client_incarnation(0); - objecter->init(); - objecter->start(); - - client->init(); - + objecter.set_client_incarnation(0); + objecter.init(); + objecter.start(); + client.init(); timer.init(); + send_beacon(); dout(4) << "Complete." << dendl; @@ -156,17 +144,17 @@ void MgrStandby::send_beacon() { assert(lock.is_locked_by_me()); dout(1) << state_str() << dendl; - dout(10) << "sending beacon as gid " << monc->get_global_id() << dendl; + dout(10) << "sending beacon as gid " << monc.get_global_id() << dendl; bool available = active_mgr != nullptr && active_mgr->is_initialized(); auto addr = available ? active_mgr->get_server_addr() : entity_addr_t(); - MMgrBeacon *m = new MMgrBeacon(monc->get_fsid(), - monc->get_global_id(), + MMgrBeacon *m = new MMgrBeacon(monc.get_fsid(), + monc.get_global_id(), g_conf->name.get_id(), addr, available); - monc->send_mon_message(m); + monc.send_mon_message(m); timer.add_event_after(g_conf->mgr_beacon_period, new FunctionContext( [this](int r){ send_beacon(); @@ -190,14 +178,10 @@ void MgrStandby::shutdown() if (active_mgr) { active_mgr->shutdown(); } - - client->shutdown(); - - objecter->shutdown(); - + client.shutdown(); + objecter.shutdown(); timer.shutdown(); - - monc->shutdown(); + monc.shutdown(); client_messenger->shutdown(); } @@ -232,14 +216,14 @@ 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(); + 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) { dout(1) << "Activating!" << dendl; - active_mgr.reset(new Mgr(monc, client_messenger, objecter, - client.get(), clog, audit_clog)); + active_mgr.reset(new Mgr(&monc, client_messenger.get(), &objecter, + &client, clog, audit_clog)); active_mgr->background_init(); dout(1) << "I am now active" << dendl; } else { @@ -287,11 +271,11 @@ bool MgrStandby::ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, return true; if (force_new) { - if (monc->wait_auth_rotating(10) < 0) + if (monc.wait_auth_rotating(10) < 0) return false; } - *authorizer = monc->build_authorizer(dest_type); + *authorizer = monc.build_authorizer(dest_type); return *authorizer != NULL; } @@ -302,7 +286,7 @@ bool MgrStandby::ms_handle_refused(Connection *con) } // A reference for use by the signal handler -MgrStandby *signal_mgr = nullptr; +static MgrStandby *signal_mgr = nullptr; static void handle_mgr_signal(int signum) { diff --git a/src/mgr/MgrStandby.h b/src/mgr/MgrStandby.h index 0eaf11c1016f..d33c633dc424 100644 --- a/src/mgr/MgrStandby.h +++ b/src/mgr/MgrStandby.h @@ -20,15 +20,16 @@ #include "common/Timer.h" #include "common/LogClient.h" +#include "client/Client.h" +#include "mon/MonClient.h" +#include "osdc/Objecter.h" + #include "DaemonServer.h" #include "PyModules.h" #include "DaemonState.h" #include "ClusterState.h" -class Objecter; -class Client; - class MMgrMap; class Mgr; @@ -41,10 +42,10 @@ public: const std::set &changed) override; protected: - MonClient *monc; - Messenger *client_messenger; - Objecter *objecter; - std::unique_ptr client; + MonClient monc; + std::unique_ptr client_messenger; + Objecter objecter; + Client client; LogClient log_client; LogChannelRef clog, audit_clog;