From 7ded532753ae447249a22d8498313cbd58dc5752 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 24 May 2018 13:37:28 -0500 Subject: [PATCH] mon: add send_mon_message() helper Avoid a zillion calls to monmap->get_inst() Signed-off-by: Sage Weil --- src/mon/AuthMonitor.cc | 2 +- src/mon/Elector.cc | 6 +++--- src/mon/HealthMonitor.cc | 6 ++---- src/mon/Monitor.cc | 41 +++++++++++++++++++++++----------------- src/mon/Monitor.h | 2 ++ src/mon/Paxos.cc | 10 +++++----- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index 2d34a9b3b31..9880681ee23 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -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; } diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index da1664aa30d..da81e6fd637 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -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 diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index 8682983ab78..a6236acd143 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -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()); } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 5e8604c71a9..6da94fce086 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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::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(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 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 diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 7d810926f9c..b1478d6dee7 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -812,6 +812,8 @@ public: void send_command(const entity_inst_t& inst, const vector& com); + void send_mon_message(Message *m, int rank); + public: struct C_Command : public C_MonOp { Monitor *mon; diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc index c90732458db..8003bc5ed47 100644 --- a/src/mon/Paxos.cc +++ b/src/mon/Paxos.cc @@ -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. -- 2.39.5