diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-10-15 18:36:28 +0100 |
---|---|---|
committer | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-10-16 01:42:46 +0100 |
commit | 99cdd5ac113a29f8a744497281e2caee46974a1c (patch) | |
tree | 8b0f75e2b229a7d6f0e5e28d94d6dfd68c8ac269 | |
parent | 6351dbd95f3d3329edf7f4fd94b380bdfa27911e (diff) | |
download | ceph-99cdd5ac113a29f8a744497281e2caee46974a1c.tar.gz |
mon: Monitor: reply to ping messages, letting them know we're alive
Fixes: #5984
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
-rw-r--r-- | src/mon/Monitor.cc | 35 | ||||
-rw-r--r-- | src/mon/Monitor.h | 5 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 8ecd45b05e9..cd541f6bf83 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<MMonHealth *>(m)); break; + case CEPH_MSG_PING: + handle_ping(static_cast<MPing*>(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 2c1c2cdeb19..2c066f6e263 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 |