From 1455904a29c81f2af24d41205ce6427fd05e75fb Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 23 Nov 2020 15:32:38 +0800 Subject: [PATCH] osd/OSDMonitor: use range-based loop when appropriate for better readability Signed-off-by: Kefu Chai --- src/mon/OSDMonitor.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index db71df05f19..67f30f2ae15 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -886,14 +886,14 @@ void OSDMonitor::update_from_paxos(bool *need_bootstrap) t = MonitorDBStore::TransactionRef(); tx_size = 0; } - for (const auto &osd_state : inc.new_state) { - if (osd_state.second & CEPH_OSD_UP) { + for (const auto [osd, state] : inc.new_state) { + if (state & CEPH_OSD_UP) { // could be marked up *or* down, but we're too lazy to check which - last_osd_report.erase(osd_state.first); + last_osd_report.erase(osd); } - if (osd_state.second & CEPH_OSD_OUT) { + if (state & CEPH_OSD_OUT) { // could be marked in *or* out, but we can safely drop it - osd_epochs.erase(osd_state.first); + osd_epochs.erase(osd); } } for (const auto [osd, weight] : inc.new_weight) { @@ -1070,19 +1070,20 @@ void OSDMonitor::start_mapping() void OSDMonitor::update_msgr_features() { - set types; - types.insert((int)entity_name_t::TYPE_OSD); - types.insert((int)entity_name_t::TYPE_CLIENT); - types.insert((int)entity_name_t::TYPE_MDS); - types.insert((int)entity_name_t::TYPE_MON); - for (set::iterator q = types.begin(); q != types.end(); ++q) { + const int types[] = { + entity_name_t::TYPE_OSD, + entity_name_t::TYPE_CLIENT, + entity_name_t::TYPE_MDS, + entity_name_t::TYPE_MON + }; + for (int type : types) { uint64_t mask; - uint64_t features = osdmap.get_features(*q, &mask); - if ((mon->messenger->get_policy(*q).features_required & mask) != features) { + uint64_t features = osdmap.get_features(type, &mask); + if ((mon->messenger->get_policy(type).features_required & mask) != features) { dout(0) << "crush map has features " << features << ", adjusting msgr requires" << dendl; - ceph::net::Policy p = mon->messenger->get_policy(*q); + ceph::net::Policy p = mon->messenger->get_policy(type); p.features_required = (p.features_required & ~mask) | features; - mon->messenger->set_policy(*q, p); + mon->messenger->set_policy(type, p); } } } -- 2.47.3