]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Monitor: reply to ping messages, letting them know we're alive
authorJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 15 Oct 2013 17:36:28 +0000 (18:36 +0100)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 23 Oct 2013 01:52:01 +0000 (02:52 +0100)
Fixes: #5984
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 8ecd45b05e9d68b820550fec2bddc729f9376485..cd541f6bf836062d91073ee3b5c1b965a8038aa3 100644 (file)
@@ -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;
index 2c1c2cdeb19eb41d43122698cb36e9170c1ddf98..2c066f6e263e4383a175e4b644fedc7be6f1c421 100644 (file)
@@ -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