From 7797fcadda713382760a6b98ac347e88da3fb0a7 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Wed, 24 Jun 2015 17:51:56 +0100 Subject: [PATCH] mon: MonOpRequest: send_reply() belongs in the Monitor class Op Requests should have no business replying to messages. Besides, given the Monitor is currently the place to do this, because it is the one with access to all things that may be required to validate state (e.g., quorum features), permanently moving this code to the Monitor class also avoid having duplicate/very similar code in two distinct places. Signed-off-by: Joao Eduardo Luis --- src/mon/Makefile.am | 3 +-- src/mon/MonOpRequest.cc | 45 ----------------------------------------- src/mon/MonOpRequest.h | 2 -- src/mon/Monitor.cc | 43 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 50 deletions(-) delete mode 100644 src/mon/MonOpRequest.cc diff --git a/src/mon/Makefile.am b/src/mon/Makefile.am index 476acef779726..ee6542d42d51e 100644 --- a/src/mon/Makefile.am +++ b/src/mon/Makefile.am @@ -18,8 +18,7 @@ libmon_la_SOURCES = \ mon/Elector.cc \ mon/HealthMonitor.cc \ mon/DataHealthService.cc \ - mon/ConfigKeyService.cc \ - mon/MonOpRequest.cc + mon/ConfigKeyService.cc libmon_la_LIBADD = $(LIBAUTH) $(LIBCOMMON) $(LIBOS) $(LIBMON_TYPES) noinst_LTLIBRARIES += libmon.la diff --git a/src/mon/MonOpRequest.cc b/src/mon/MonOpRequest.cc deleted file mode 100644 index 90c41ac84cf8d..0000000000000 --- a/src/mon/MonOpRequest.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include "msg/Messenger.h" -#include "msg/Message.h" -#include "messages/MRoute.h" - -#include "mon/MonOpRequest.h" -#include "mon/Session.h" - -#define dout_subsys ceph_subsys_mon -#undef dout_prefix -#define dout_prefix _prefix(_dout, this) -static ostream& _prefix(std::ostream *_dout, const MonOpRequest *op) { - *_dout << "optracker foo "; - return *_dout; -} - -void MonOpRequest::send_reply(Message *reply) -{ - if (!session) { - dout(2) << "send_reply no session, dropping reply " << *reply - << " to " << request << " " << *request << dendl; - reply->put(); - mark_event("reply: no session"); - return; - } - - if (!session->con && !session->proxy_con) { - dout(2) << "send_reply no connection, dropping reply " << *reply - << " to " << request << " " << *request << dendl; - reply->put(); - mark_event("reply: no connection"); - return; - } - - if (session->proxy_con) { - dout(15) << "send_reply routing reply to " << con->get_peer_addr() - << " via " << session->proxy_con->get_peer_addr() - << " for request " << *request << dendl; - session->proxy_con->send_message(new MRoute(session->proxy_tid, reply)); - mark_event("reply: send routed request"); - } else { - session->con->send_message(reply); - mark_event("reply: send"); - } -} diff --git a/src/mon/MonOpRequest.h b/src/mon/MonOpRequest.h index 0c59909ca7c16..329607c53c436 100644 --- a/src/mon/MonOpRequest.h +++ b/src/mon/MonOpRequest.h @@ -142,8 +142,6 @@ public: typedef ceph::shared_ptr Ref; - void send_reply(Message *reply); - void _dump(utime_t now, Formatter *f) const { { f->open_array_section("events"); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 2899564d19639..4796f1c39d43b 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -3178,8 +3178,49 @@ void Monitor::try_send_message(Message *m, const entity_inst_t& to) void Monitor::send_reply(MonOpRequestRef op, Message *reply) { + op->mark_event(__func__); + + MonSession *session = op->get_session(); + Message *req = op->get_req(); + ConnectionRef con = op->get_connection(); + dout(2) << __func__ << " " << op << " " << *reply << dendl; - op->send_reply(reply); + + if (!con) { + dout(2) << "send_reply no connection, dropping reply " << *reply + << " to " << req << " " << *req << dendl; + reply->put(); + op->mark_event("reply: no connection"); + return; + } + + if (!session) { + dout(2) << "send_reply no session, dropping reply " << *reply + << " to " << req << " " << *req << dendl; + reply->put(); + op->mark_event("reply: no session"); + return; + } + + if (!session->con && !session->proxy_con) { + dout(2) << "send_reply no connection, dropping reply " << *reply + << " to " << req << " " << *req << dendl; + reply->put(); + op->mark_event("reply: no connection"); + return; + } + + if (session->proxy_con) { + dout(15) << "send_reply routing reply to " << con->get_peer_addr() + << " via " << session->proxy_con->get_peer_addr() + << " for request " << *req << dendl; + session->proxy_con->send_message(new MRoute(session->proxy_tid, reply)); + op->mark_event("reply: send routed request"); + } else { + session->con->send_message(reply); + op->mark_event("reply: send"); + } + session->put(); } -- 2.39.5