]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add send_mon_message() helper 22228/head
authorSage Weil <sage@redhat.com>
Thu, 24 May 2018 18:37:28 +0000 (13:37 -0500)
committerSage Weil <sage@redhat.com>
Fri, 25 May 2018 22:54:53 +0000 (17:54 -0500)
Avoid a zillion calls to monmap->get_inst()

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/AuthMonitor.cc
src/mon/Elector.cc
src/mon/HealthMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/Paxos.cc

index 2d34a9b3b3135f7dde3ea7aebc87c1978e47b521..9880681ee233002b06443364fde1680c9dc84947 100644 (file)
@@ -540,7 +540,7 @@ bool AuthMonitor::prep_auth(MonOpRequestRef op, bool paxos_writable)
        int leader = mon->get_leader();
        MMonGlobalID *req = new MMonGlobalID();
        req->old_max_id = max_global_id;
-       mon->messenger->send_message(req, mon->monmap->get_inst(leader));
+       mon->send_mon_message(req, leader);
        wait_for_finished_proposal(op, new C_RetryMessage(this, op));
        return true;
       }
index da1664aa30d5757d96755ae5b0152b6075fb417a..da81e6fd63710394bfb37df2c9b9254c778de040 100644 (file)
@@ -105,7 +105,7 @@ void Elector::start()
     MMonElection *m =
       new MMonElection(MMonElection::OP_PROPOSE, epoch, mon->monmap);
     m->mon_features = ceph::features::mon::get_supported();
-    mon->messenger->send_message(m, mon->monmap->get_inst(i));
+    mon->send_mon_message(m, i);
   }
   
   reset_timer();
@@ -127,7 +127,7 @@ void Elector::defer(int who)
   m->mon_features = ceph::features::mon::get_supported();
   mon->collect_metadata(&m->metadata);
 
-  mon->messenger->send_message(m, mon->monmap->get_inst(who));
+  mon->send_mon_message(m, who);
   
   // set a timer
   reset_timer(1.0);  // give the leader some extra time to declare victory
@@ -220,7 +220,7 @@ void Elector::victory()
     m->quorum_features = cluster_features;
     m->mon_features = mon_features;
     m->sharing_bl = mon->get_local_commands_bl(mon_features);
-    mon->messenger->send_message(m, mon->monmap->get_inst(*p));
+    mon->send_mon_message(m, *p);
   }
 
   // tell monitor
index 8682983ab7865a2aeff3a7ffaac76da00d075b08..a6236acd14303d41c7c2a7daab4cc4b302246a8f 100644 (file)
@@ -285,8 +285,7 @@ bool HealthMonitor::check_member_health()
     changed = true;
   } else {
     // tell the leader
-    mon->messenger->send_message(new MMonHealthChecks(next),
-                                 mon->monmap->get_inst(mon->get_leader()));
+    mon->send_mon_message(new MMonHealthChecks(next), mon->get_leader());
   }
 
   return changed;
@@ -348,8 +347,7 @@ bool HealthMonitor::check_leader_health()
       if (tcstatus != HEALTH_OK) {
        warns.push_back(name);
        ostringstream tmp_ss;
-       tmp_ss << "mon." << name
-              << " " << tcss.str()
+       tmp_ss << "mon." << name << " " << tcss.str()
               << " (latency " << latency << "s)";
        details.push_back(tmp_ss.str());
       }
index 5e8604c71a99e090935a2e0abccd79296c271bef..6da94fce086c28dae5172c026a53e4608f5889d7 100644 (file)
@@ -1051,8 +1051,9 @@ void Monitor::bootstrap()
   dout(10) << "probing other monitors" << dendl;
   for (unsigned i = 0; i < monmap->size(); i++) {
     if ((int)i != rank)
-      messenger->send_message(new MMonProbe(monmap->fsid, MMonProbe::OP_PROBE, name, has_ever_joined),
-                             monmap->get_inst(i));
+      send_mon_message(
+       new MMonProbe(monmap->fsid, MMonProbe::OP_PROBE, name, has_ever_joined),
+       i);
   }
   for (set<entity_addr_t>::iterator p = extra_probe_peers.begin();
        p != extra_probe_peers.end();
@@ -1061,7 +1062,9 @@ void Monitor::bootstrap()
       entity_inst_t i;
       i.name = entity_name_t::MON(-1);
       i.addr = *p;
-      messenger->send_message(new MMonProbe(monmap->fsid, MMonProbe::OP_PROBE, name, has_ever_joined), i);
+      messenger->send_message(
+       new MMonProbe(monmap->fsid, MMonProbe::OP_PROBE, name, has_ever_joined),
+       i);
     }
   }
 }
@@ -1865,8 +1868,9 @@ void Monitor::handle_probe_reply(MonOpRequestRef op)
       start_election();
     } else {
       dout(10) << " ready to join, but i'm not in the monmap or my addr is blank, trying to join" << dendl;
-      messenger->send_message(new MMonJoin(monmap->fsid, name, messenger->get_myaddr()),
-                              monmap->get_inst(*m->quorum.begin()));
+      send_mon_message(
+       new MMonJoin(monmap->fsid, name, messenger->get_myaddr()),
+       *m->quorum.begin());
     }
   } else {
     if (monmap->contains(m->name)) {
@@ -2110,8 +2114,9 @@ void Monitor::finish_election()
   string cur_name = monmap->get_name(messenger->get_myaddr());
   if (cur_name != name) {
     dout(10) << " renaming myself from " << cur_name << " -> " << name << dendl;
-    messenger->send_message(new MMonJoin(monmap->fsid, name, messenger->get_myaddr()),
-                           monmap->get_inst(*quorum.begin()));
+    send_mon_message(
+      new MMonJoin(monmap->fsid, name, messenger->get_myaddr()),
+      *quorum.begin());
   }
 }
 
@@ -3674,7 +3679,7 @@ void Monitor::forward_request_leader(MonOpRequestRef op)
     } else if (req->get_source().is_mon()) {
       forward->entity_name.set_type(CEPH_ENTITY_TYPE_MON);
     }
-    messenger->send_message(forward, monmap->get_inst(mon));
+    send_mon_message(forward, mon);
     op->mark_forwarded();
     assert(op->get_req()->get_type() != 0);
   } else {
@@ -3775,7 +3780,7 @@ void Monitor::try_send_message(Message *m, const entity_inst_t& to)
 
   for (int i=0; i<(int)monmap->size(); i++) {
     if (i != rank)
-      messenger->send_message(new MRoute(bl, to), monmap->get_inst(i));
+      send_mon_message(new MRoute(bl, to), i);
   }
 }
 
@@ -3913,7 +3918,7 @@ void Monitor::resend_routed_requests()
       req->put();  // forward takes its own ref; drop ours.
       forward->client = rr->client_inst;
       forward->set_priority(req->get_priority());
-      messenger->send_message(forward, monmap->get_inst(mon));
+      send_mon_message(forward, mon);
     }
   }
   if (mon == rank) {
@@ -3965,6 +3970,11 @@ void Monitor::send_command(const entity_inst_t& inst,
   try_send_message(c, inst);
 }
 
+void Monitor::send_mon_message(Message *m, int rank)
+{
+  messenger->send_message(m, monmap->get_inst(rank));
+}
+
 void Monitor::waitlist_or_zap_client(MonOpRequestRef op)
 {
   /**
@@ -4345,7 +4355,6 @@ void Monitor::handle_ping(MonOpRequestRef op)
   MPing *m = static_cast<MPing*>(op->get_req());
   dout(10) << __func__ << " " << *m << dendl;
   MPing *reply = new MPing;
-  entity_inst_t inst = m->get_source_inst();
   bufferlist payload;
   boost::scoped_ptr<Formatter> f(new JSONFormatter(true));
   f->open_object_section("pong");
@@ -4362,7 +4371,7 @@ void Monitor::handle_ping(MonOpRequestRef op)
   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->get_connection()->send_message(reply);
 }
 
 void Monitor::timecheck_start()
@@ -4562,8 +4571,7 @@ void Monitor::timecheck_report()
     }
     do_output = false;
     dout(10) << __func__ << " send report to mon." << *q << dendl;
-    entity_inst_t inst = monmap->get_inst(*q);
-    messenger->send_message(m, inst);
+    send_mon_message(m, *q);
   }
 }
 
@@ -4590,14 +4598,13 @@ void Monitor::timecheck()
     if (monmap->get_name(*it) == name)
       continue;
 
-    entity_inst_t inst = monmap->get_inst(*it);
     utime_t curr_time = ceph_clock_now();
     timecheck_waiting[*it] = curr_time;
     MTimeCheck2 *m = new MTimeCheck2(MTimeCheck2::OP_PING);
     m->epoch = get_epoch();
     m->round = timecheck_round;
     dout(10) << __func__ << " send " << *m << " to mon." << *it << dendl;
-    messenger->send_message(m, inst);
+    send_mon_message(m, *it);
   }
 }
 
@@ -5118,7 +5125,7 @@ int Monitor::scrub()
     MMonScrub *r = new MMonScrub(MMonScrub::OP_SCRUB, scrub_version,
                                  num_keys);
     r->key = scrub_state->last_key;
-    messenger->send_message(r, monmap->get_inst(*p));
+    send_mon_message(r, *p);
   }
 
   // scrub my keys
index 7d810926f9cb27f1f148a06d3e5a3e668952224c..b1478d6dee79955a90aee7f33f57148faf6d4634 100644 (file)
@@ -812,6 +812,8 @@ public:
   void send_command(const entity_inst_t& inst,
                    const vector<string>& com);
 
+  void send_mon_message(Message *m, int rank);
+
 public:
   struct C_Command : public C_MonOp {
     Monitor *mon;
index c90732458dbf9968dead405e70c163b05573418e..8003bc5ed470b0cf85ce71c51918ee5fe551e451 100644 (file)
@@ -196,7 +196,7 @@ void Paxos::collect(version_t oldpn)
     collect->last_committed = last_committed;
     collect->first_committed = first_committed;
     collect->pn = accepted_pn;
-    mon->messenger->send_message(collect, mon->monmap->get_inst(*p));
+    mon->send_mon_message(collect, *p);
   }
 
   // set timeout event
@@ -516,7 +516,7 @@ void Paxos::handle_last(MonOpRequestRef op)
                                        MMonPaxos::OP_COMMIT,
                                        ceph_clock_now());
       share_state(commit, peer_first_committed[p->first], p->second);
-      mon->messenger->send_message(commit, mon->monmap->get_inst(p->first));
+      mon->send_mon_message(commit, p->first);
     }
   }
 
@@ -688,7 +688,7 @@ void Paxos::begin(bufferlist& v)
     begin->last_committed = last_committed;
     begin->pn = accepted_pn;
     
-    mon->messenger->send_message(begin, mon->monmap->get_inst(*p));
+    mon->send_mon_message(begin, *p);
   }
 
   // set timeout event
@@ -914,7 +914,7 @@ void Paxos::commit_finish()
     commit->pn = accepted_pn;
     commit->last_committed = last_committed;
 
-    mon->messenger->send_message(commit, mon->monmap->get_inst(*p));
+    mon->send_mon_message(commit, *p);
   }
 
   assert(g_conf->paxos_kill_at != 9);
@@ -987,7 +987,7 @@ void Paxos::extend_lease()
     lease->last_committed = last_committed;
     lease->lease_timestamp = lease_expire;
     lease->first_committed = first_committed;
-    mon->messenger->send_message(lease, mon->monmap->get_inst(*p));
+    mon->send_mon_message(lease, *p);
   }
 
   // set timeout event.