From: Joao Eduardo Luis Date: Tue, 15 Oct 2013 17:36:28 +0000 (+0100) Subject: mon: Monitor: reply to ping messages, letting them know we're alive X-Git-Tag: v0.72-rc1~22^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5e4652eb8c2c0243ae73376d5235344513be49ea;p=ceph.git mon: Monitor: reply to ping messages, letting them know we're alive Fixes: #5984 Signed-off-by: Joao Eduardo Luis --- diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 8ecd45b05e9d..cd541f6bf836 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -52,6 +52,7 @@ #include "messages/MTimeCheck.h" #include "messages/MMonHealth.h" +#include "messages/MPing.h" #include "common/strtol.h" #include "common/ceph_argparse.h" @@ -2591,6 +2592,10 @@ bool Monitor::_ms_dispatch(Message *m) // of assessing whether we should handle it or not. if (!src_is_mon && (m->get_type() != CEPH_MSG_AUTH && m->get_type() != CEPH_MSG_MON_GET_MAP)) { + if (m->get_type() == CEPH_MSG_PING) { + // let it go through and be dispatched immediately! + return dispatch(s, m, false); + } dout(1) << __func__ << " dropping stray message " << *m << " from " << m->get_source_inst() << dendl; return false; @@ -2803,6 +2808,10 @@ bool Monitor::dispatch(MonSession *s, Message *m, const bool src_is_mon) health_monitor->dispatch(static_cast(m)); break; + case CEPH_MSG_PING: + handle_ping(static_cast(m)); + break; + default: ret = false; } @@ -2810,6 +2819,32 @@ bool Monitor::dispatch(MonSession *s, Message *m, const bool src_is_mon) return ret; } +void Monitor::handle_ping(MPing *m) +{ + dout(10) << __func__ << " " << *m << dendl; + MPing *reply = new MPing; + entity_inst_t inst = m->get_source_inst(); + bufferlist payload; + Formatter *f = new JSONFormatter(true); + f->open_object_section("pong"); + + string health_str; + get_health(health_str, NULL, f); + { + stringstream ss; + _mon_status(f, ss); + } + + f->close_section(); + stringstream ss; + f->flush(ss); + ::encode(ss.str(), payload); + reply->set_payload(payload); + dout(10) << __func__ << " reply payload len " << reply->get_payload().length() << dendl; + messenger->send_message(reply, inst); + m->put(); +} + void Monitor::timecheck_start() { dout(10) << __func__ << dendl; diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 2c1c2cdeb19e..2c066f6e263e 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -46,6 +46,7 @@ #include "perfglue/heap_profiler.h" #include "messages/MMonCommand.h" +#include "messages/MPing.h" #include "mon/MonitorStore.h" #include "mon/MonitorDBStore.h" @@ -485,6 +486,10 @@ private: /** * @} */ + /** + * Handle ping messages from others. + */ + void handle_ping(MPing *m); Context *probe_timeout_event; // for probing