From 232757f45ea8d8865962e82065b9b57fe6aa6819 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 22 Aug 2014 01:17:55 +0100 Subject: [PATCH] mds: promote Beacon to be a Dispatcher This allows it to handle its own MSG_MDS_BEACON messages from the mon, outside of mds_lock. This is less important than the sending of beacons being outside the lock, but still nice to have and gets all the beacon messaging in one place. Signed-off-by: John Spray --- src/mds/Beacon.cc | 20 ++++++++++++++++---- src/mds/Beacon.h | 12 ++++++++++-- src/mds/MDS.cc | 21 ++++++++++++++++++--- src/mds/MDS.h | 6 +----- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/mds/Beacon.cc b/src/mds/Beacon.cc index e19ec3faa1569..667a7d7f2f5ee 100644 --- a/src/mds/Beacon.cc +++ b/src/mds/Beacon.cc @@ -24,8 +24,8 @@ #define dout_prefix *_dout << "mds.beacon." << name << ' ' -Beacon::Beacon(MonClient *monc_, std::string name_) : - lock("Beacon"), monc(monc_), timer(g_ceph_context, lock), name(name_) +Beacon::Beacon(CephContext *cct_, MonClient *monc_, std::string name_) : + Dispatcher(cct_), lock("Beacon"), monc(monc_), timer(g_ceph_context, lock), name(name_) { last_seq = 0; sender = NULL; @@ -69,6 +69,20 @@ void Beacon::shutdown() } +bool Beacon::ms_dispatch(Message *m) +{ + if (m->get_type() == MSG_MDS_BEACON) { + if (m->get_connection()->get_peer_type() == CEPH_ENTITY_TYPE_MON) { + handle_mds_beacon(static_cast(m)); + } + } + + // Let message fall through to MDS so that we get the execution of + // his finished_queue and waiting_for_nolaggy stuff. + return false; +} + + /** * Update lagginess state based on response from remote MDSMonitor * @@ -106,8 +120,6 @@ void Beacon::handle_mds_beacon(MMDSBeacon *m) dout(10) << "handle_mds_beacon " << ceph_mds_state_name(m->get_state()) << " seq " << m->get_seq() << " dne" << dendl; } - - m->put(); } diff --git a/src/mds/Beacon.h b/src/mds/Beacon.h index deaeab0243f9d..50d17dfd1c8f1 100644 --- a/src/mds/Beacon.h +++ b/src/mds/Beacon.h @@ -19,9 +19,11 @@ #include "include/types.h" #include "include/Context.h" #include "common/Mutex.h" +#include "msg/Dispatcher.h" class MonClient; class MMDSBeacon; +class Message; /** @@ -33,8 +35,9 @@ class MMDSBeacon; * we keep copies of the data needed to generate beacon messages. The MDS is * responsible for calling Beacon::notify_* when things change. */ -class Beacon +class Beacon : public Dispatcher { + //CephContext *cct; mutable Mutex lock; MonClient* monc; SafeTimer timer; @@ -71,12 +74,17 @@ class Beacon void _send(); public: - Beacon(MonClient *monc_, std::string name); + Beacon(CephContext *cct_, MonClient *monc_, std::string name); ~Beacon(); void init(MDSMap const *mdsmap, MDSMap::DaemonState want_state_, int standby_rank_, std::string const &standby_name_); void shutdown(); + bool ms_dispatch(Message *m); + void ms_handle_connect(Connection *c) {} + bool ms_handle_reset(Connection *c) {return false;} + void ms_handle_remote_reset(Connection *c) {} + void notify_mdsmap(MDSMap const *mdsmap); void notify_want_state(MDSMap::DaemonState const newstate); diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 96edc89add84a..3d832b8151d9a 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -83,7 +83,7 @@ MDS::MDS(const std::string &n, Messenger *m, MonClient *mc) : Dispatcher(m->cct), mds_lock("MDS::mds_lock"), timer(m->cct, mds_lock), - beacon(mc, n), + beacon(m->cct, mc, n), authorize_handler_cluster_registry(new AuthAuthorizeHandlerRegistry(m->cct, m->cct->_conf->auth_supported.length() ? m->cct->_conf->auth_supported : @@ -569,6 +569,7 @@ int MDS::init(MDSMap::DaemonState wanted_state) objecter->init(); messenger->add_dispatcher_tail(objecter); + messenger->add_dispatcher_tail(&beacon); messenger->add_dispatcher_tail(this); // get monmap @@ -1851,9 +1852,12 @@ bool MDS::handle_core_message(Message *m) break; case MSG_MDS_BEACON: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON); - beacon.handle_mds_beacon(static_cast(m)); + // no-op, Beacon handles this on our behalf but we listen for the + // message to get the side effect of handling finished_queue and + // waiting_for_nolaggy at end of MDS dispatch. + m->put(); break; - + // misc case MSG_MON_COMMAND: ALLOW_MESSAGES_FROM(CEPH_ENTITY_TYPE_MON); @@ -2299,3 +2303,14 @@ void MDS::ms_handle_accept(Connection *con) s->put(); } } + +void MDS::set_want_state(MDSMap::DaemonState newstate) +{ + if (want_state != newstate) { + dout(10) << __func__ << " " + << ceph_mds_state_name(want_state) << " -> " + << ceph_mds_state_name(newstate) << dendl; + want_state = newstate; + beacon.notify_want_state(newstate); + } +} diff --git a/src/mds/MDS.h b/src/mds/MDS.h index 3f5c2514d70ea..a69885d47433e 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -146,11 +146,7 @@ class MDS : public Dispatcher, public md_config_obs_t { private: Beacon beacon; - void set_want_state(MDSMap::DaemonState newstate) - { - want_state = newstate; - beacon.notify_want_state(newstate); - } + void set_want_state(MDSMap::DaemonState newstate); public: utime_t get_laggy_until() {return beacon.get_laggy_until();} -- 2.39.5