From 61dd4f03e6e15d59951ff69d95807a3026f5b9c4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 22 Nov 2010 22:41:42 -0800 Subject: [PATCH] mon: simplify send_reply code No need to specify destination in send_reply, as we always have the request for reference. Simplify MRoute constructors (keep the ones we use) for tid and bcast best-effort case. Do NOT do a best-effort forward of a reply with a tid specified if the tid is not in the routed-request map. Signed-off-by: Sage Weil --- src/messages/MRoute.h | 16 ++++++++++------ src/mon/Monitor.cc | 36 ++++++++++++++++++++---------------- src/mon/Monitor.h | 5 +---- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/messages/MRoute.h b/src/messages/MRoute.h index b35153119a0f2..076b8f996700c 100644 --- a/src/messages/MRoute.h +++ b/src/messages/MRoute.h @@ -26,10 +26,10 @@ struct MRoute : public Message { entity_inst_t dest; MRoute() : Message(MSG_ROUTE), msg(NULL) {} - MRoute(uint64_t t, Message *m, entity_inst_t i) : - Message(MSG_ROUTE), session_mon_tid(t), msg(m), dest(i) {} - MRoute(uint64_t t, bufferlist bl, entity_inst_t i) : - Message(MSG_ROUTE), session_mon_tid(t), dest(i) { + MRoute(uint64_t t, Message *m) : + Message(MSG_ROUTE), session_mon_tid(t), msg(m) {} + MRoute(bufferlist bl, entity_inst_t i) : + Message(MSG_ROUTE), session_mon_tid(0), dest(i) { bufferlist::iterator p = bl.begin(); msg = decode_message(p); } @@ -54,9 +54,13 @@ public: const char *get_type_name() { return "route"; } void print(ostream& o) { if (msg) - o << "route(" << *msg << " to " << dest << ")"; + o << "route(" << *msg; else - o << "route(??? to " << dest << ")"; + o << "route(???"; + if (session_mon_tid) + o << " tid " << session_mon_tid << ")"; + else + o << " to " << dest << ")"; } }; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 5d7ecd2fa28d4..dbaad25963378 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -451,24 +451,24 @@ void Monitor::try_send_message(Message *m, entity_inst_t to) for (int i=0; i<(int)monmap->size(); i++) { if (i != rank) - messenger->send_message(new MRoute(0, bl, to), - monmap->get_inst(i)); + messenger->send_message(new MRoute(bl, to), monmap->get_inst(i)); } } -void Monitor::send_reply(PaxosServiceMessage *req, Message *reply, entity_inst_t to) +void Monitor::send_reply(PaxosServiceMessage *req, Message *reply) { MonSession *session = (MonSession*)req->get_connection()->get_priv(); if (!session) { dout(2) << "send_reply no session, dropping reply " << *reply - << " to " << req << " " << *req << " for " << to << dendl; + << " to " << req << " " << *req << dendl; reply->put(); return; } if (session->proxy_con) { - dout(15) << "send_reply routing reply to " << to << " via mon" << req->session_mon + dout(15) << "send_reply routing reply to " << req->get_connection()->get_peer_addr() + << " via mon" << req->session_mon << " for request " << *req << dendl; - messenger->send_message(new MRoute(session->proxy_tid, reply, to), + messenger->send_message(new MRoute(session->proxy_tid, reply), session->proxy_con); } else { messenger->send_message(reply, session->con); @@ -490,21 +490,25 @@ void Monitor::handle_route(MRoute *m) dout(10) << "handle_route " << *m->msg << " to " << m->dest << dendl; // look it up - if (routed_requests.count(m->session_mon_tid)) { - RoutedRequest *rr = routed_requests[m->session_mon_tid]; - messenger->send_message(m->msg, rr->session->inst); - m->msg = NULL; - routed_requests.erase(m->session_mon_tid); - rr->session->routed_request_tids.insert(rr->tid); - delete rr; + if (m->session_mon_tid) { + if (routed_requests.count(m->session_mon_tid)) { + RoutedRequest *rr = routed_requests[m->session_mon_tid]; + messenger->send_message(m->msg, rr->session->inst); + m->msg = NULL; + routed_requests.erase(m->session_mon_tid); + rr->session->routed_request_tids.insert(rr->tid); + delete rr; + } else { + dout(10) << " don't have routed request tid " << m->session_mon_tid << dendl; + } } else { - dout(10) << " don't have routed request tid " << m->session_mon_tid - << ", trying to send anyway" << dendl; + dout(10) << " not a routed request, trying to send anyway" << dendl; messenger->lazy_send_message(m->msg, m->dest); m->msg = NULL; } m->put(); - if (session) session->put(); + if (session) + session->put(); } void Monitor::resend_routed_requests() diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 60d5f2aa22b27..0c1b1c5e11c95 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -175,10 +175,7 @@ public: void forward_request_leader(PaxosServiceMessage *req); void handle_forward(MForward *m); void try_send_message(Message *m, entity_inst_t to); - void send_reply(PaxosServiceMessage *req, Message *reply, entity_inst_t to); - void send_reply(PaxosServiceMessage *req, Message *reply) { - send_reply(req, reply, req->get_orig_source_inst()); - } + void send_reply(PaxosServiceMessage *req, Message *reply); void resend_routed_requests(); void remove_session(MonSession *s); -- 2.39.5