int OSDMap::Incremental::get_net_marked_out(const OSDMap *previous) const
{
int n = 0;
- for (map<int32_t,uint32_t>::const_iterator p = new_weight.begin();
- p != new_weight.end();
- ++p) {
- if (p->second == CEPH_OSD_OUT && !previous->is_out(p->first))
+ for (const auto &elem : new_weight) {
+ if (elem.second == CEPH_OSD_OUT && !previous->is_out(elem.first))
n++; // marked out
- else if (p->second != CEPH_OSD_OUT && previous->is_out(p->first))
+ else if (elem.second != CEPH_OSD_OUT && previous->is_out(elem.first))
n--; // marked in
}
return n;
int OSDMap::Incremental::get_net_marked_down(const OSDMap *previous) const
{
int n = 0;
- for (map<int32_t,uint8_t>::const_iterator p = new_state.begin();
- p != new_state.end();
- ++p) {
- if (p->second & CEPH_OSD_UP) {
- if (previous->is_up(p->first))
+ for (const auto &elem : new_state) {
+ if (elem.second & CEPH_OSD_UP) {
+ if (previous->is_up(elem.first))
n++; // marked down
else
n--; // marked up
int OSDMap::Incremental::identify_osd(uuid_d u) const
{
- for (map<int32_t,uuid_d>::const_iterator p = new_uuid.begin();
- p != new_uuid.end();
- ++p)
- if (p->second == u)
- return p->first;
+ for (const auto &elem : new_uuid)
+ if (elem.second == u)
+ return elem.first;
return -1;
}
const OSDMap& osdmap)
{
assert(epoch == osdmap.get_epoch() + 1);
- for (map<int64_t,pg_pool_t>::iterator p = new_pools.begin();
- p != new_pools.end(); ++p) {
- if (!p->second.tiers.empty()) {
- pg_pool_t& base = p->second;
- for (set<uint64_t>::const_iterator q = base.tiers.begin();
- q != base.tiers.end();
- ++q) {
- map<int64_t,pg_pool_t>::iterator r = new_pools.find(*q);
+
+ for (auto &elemm : new_pools) {
+ if (!elemm.second.tiers.empty()) {
+ pg_pool_t& base = elemm.second;
+
+ for (const auto &elems : base.tiers) {
+ const auto &r = new_pools.find(elems);
pg_pool_t *tier = 0;
if (r == new_pools.end()) {
- const pg_pool_t *orig = osdmap.get_pg_pool(*q);
+ const pg_pool_t *orig = osdmap.get_pg_pool(elems);
if (!orig) {
- lderr(cct) << __func__ << " no pool " << *q << dendl;
+ lderr(cct) << __func__ << " no pool " << elems << dendl;
return -EIO;
}
- tier = get_new_pool(*q, orig);
+ tier = get_new_pool(elems, orig);
} else {
tier = &r->second;
}
- if (tier->tier_of != p->first) {
- lderr(cct) << __func__ << " " << r->first << " tier_of != " << p->first << dendl;
+ if (tier->tier_of != elemm.first) {
+ lderr(cct) << __func__ << " " << r->first << " tier_of != " << elemm.first << dendl;
return -EIO;
}
- ldout(cct, 10) << __func__ << " from " << p->first << " to "
- << *q << dendl;
+ ldout(cct, 10) << __func__ << " from " << elemm.first << " to "
+ << elems << dendl;
tier->snap_seq = base.snap_seq;
tier->snap_epoch = base.snap_epoch;
tier->snaps = base.snaps;
list<int> children;
crush->get_children(id, &children);
- for (list<int>::iterator p = children.begin(); p != children.end(); ++p) {
- if (!subtree_is_down(*p, down_cache)) {
+ for (const auto &elem : children) {
+ if (!subtree_is_down(elem, down_cache)) {
return false;
}
}
// for ::encode(new_pools, bl);
__u32 n = new_pools.size();
::encode(n, bl);
- for (map<int64_t,pg_pool_t>::const_iterator p = new_pools.begin();
- p != new_pools.end();
- ++p) {
- n = p->first;
+ for (const auto &elem : new_pools) {
+ n = elem.first;
::encode(n, bl);
- ::encode(p->second, bl, 0);
+ ::encode(elem.second, bl, 0);
}
// for ::encode(new_pool_names, bl);
n = new_pool_names.size();
::encode(n, bl);
- for (map<int64_t, string>::const_iterator p = new_pool_names.begin(); p != new_pool_names.end(); ++p) {
- n = p->first;
+
+ for (const auto &elem : new_pool_names) {
+ n = elem.first;
::encode(n, bl);
- ::encode(p->second, bl);
+ ::encode(elem.second, bl);
}
// for ::encode(old_pools, bl);
n = old_pools.size();
::encode(n, bl);
- for (set<int64_t>::iterator p = old_pools.begin(); p != old_pools.end(); ++p) {
- n = *p;
+ for (auto &elem : old_pools) {
+ n = elem;
::encode(n, bl);
}
::encode(new_up_client, bl, 0);
// for ::encode(new_pg_temp, bl);
n = new_pg_temp.size();
::encode(n, bl);
- for (map<pg_t,vector<int32_t> >::const_iterator p = new_pg_temp.begin();
- p != new_pg_temp.end();
- ++p) {
- old_pg_t opg = p->first.get_old_pg();
+
+ for (const auto &elem : new_pg_temp) {
+ old_pg_t opg = elem.first.get_old_pg();
::encode(opg, bl);
- ::encode(p->second, bl);
+ ::encode(elem.second, bl);
}
}
f->open_object_section("full_map");
OSDMap full;
bufferlist fbl = fullmap; // kludge around constness.
- bufferlist::iterator p = fbl.begin();
+ auto p = fbl.begin();
full.decode(p);
full.dump(f);
f->close_section();
f->open_object_section("crush");
CrushWrapper c;
bufferlist tbl = crush; // kludge around constness.
- bufferlist::iterator p = tbl.begin();
+ auto p = tbl.begin();
c.decode(p);
c.dump(f);
f->close_section();
f->dump_int("new_max_osd", new_max_osd);
f->open_array_section("new_pools");
- for (map<int64_t,pg_pool_t>::const_iterator p = new_pools.begin(); p != new_pools.end(); ++p) {
+
+ for (const auto &elem : new_pools) {
f->open_object_section("pool");
- f->dump_int("pool", p->first);
- p->second.dump(f);
+ f->dump_int("pool", elem.first);
+ elem.second.dump(f);
f->close_section();
}
f->close_section();
f->open_array_section("new_pool_names");
- for (map<int64_t,string>::const_iterator p = new_pool_names.begin(); p != new_pool_names.end(); ++p) {
+
+ for (const auto &elem : new_pool_names) {
f->open_object_section("pool_name");
- f->dump_int("pool", p->first);
- f->dump_string("name", p->second);
+ f->dump_int("pool", elem.first);
+ f->dump_string("name", elem.second);
f->close_section();
}
f->close_section();
f->open_array_section("old_pools");
- for (set<int64_t>::const_iterator p = old_pools.begin(); p != old_pools.end(); ++p)
- f->dump_int("pool", *p);
+
+ for (const auto &elem : old_pools)
+ f->dump_int("pool", elem);
f->close_section();
f->open_array_section("new_up_osds");
- for (map<int32_t,entity_addr_t>::const_iterator p = new_up_client.begin(); p != new_up_client.end(); ++p) {
+
+ for (const auto &elem : new_up_client) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_stream("public_addr") << p->second;
- f->dump_stream("cluster_addr") << new_up_cluster.find(p->first)->second;
- f->dump_stream("heartbeat_back_addr") << new_hb_back_up.find(p->first)->second;
+ f->dump_int("osd", elem.first);
+ f->dump_stream("public_addr") << elem.second;
+ f->dump_stream("cluster_addr") << new_up_cluster.find(elem.first)->second;
+ f->dump_stream("heartbeat_back_addr") << new_hb_back_up.find(elem.first)->second;
map<int32_t, entity_addr_t>::const_iterator q;
- if ((q = new_hb_front_up.find(p->first)) != new_hb_front_up.end())
+ if ((q = new_hb_front_up.find(elem.first)) != new_hb_front_up.end())
f->dump_stream("heartbeat_front_addr") << q->second;
f->close_section();
}
f->close_section();
f->open_array_section("new_weight");
- for (map<int32_t,uint32_t>::const_iterator p = new_weight.begin(); p != new_weight.end(); ++p) {
+
+ for (const auto &elem : new_weight) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_int("weight", p->second);
+ f->dump_int("osd", elem.first);
+ f->dump_int("weight", elem.second);
f->close_section();
}
f->close_section();
f->open_array_section("osd_state_xor");
- for (map<int32_t,uint8_t>::const_iterator p = new_state.begin(); p != new_state.end(); ++p) {
+ for (const auto &elemm : new_state) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
+ f->dump_int("osd", elemm.first);
set<string> st;
- calc_state_set(new_state.find(p->first)->second, st);
+ calc_state_set(new_state.find(elemm.first)->second, st);
f->open_array_section("state_xor");
- for (set<string>::iterator p = st.begin(); p != st.end(); ++p)
- f->dump_string("state", *p);
+ for (auto &elems : st)
+ f->dump_string("state", elems);
f->close_section();
}
f->close_section();
f->open_array_section("new_pg_temp");
- for (map<pg_t,vector<int32_t> >::const_iterator p = new_pg_temp.begin();
- p != new_pg_temp.end();
- ++p) {
+
+ for (const auto &elemm : new_pg_temp) {
f->open_object_section("pg");
- f->dump_stream("pgid") << p->first;
+ f->dump_stream("pgid") << elemm.first;
f->open_array_section("osds");
- for (vector<int>::const_iterator q = p->second.begin(); q != p->second.end(); ++q)
- f->dump_int("osd", *q);
+
+ for (const auto &elemv : elemm.second)
+ f->dump_int("osd", elemv);
f->close_section();
f->close_section();
}
f->close_section();
f->open_array_section("primary_temp");
- for (map<pg_t, int32_t>::const_iterator p = new_primary_temp.begin();
- p != new_primary_temp.end();
- ++p) {
- f->dump_stream("pgid") << p->first;
- f->dump_int("osd", p->second);
+
+ for (const auto &elem : new_primary_temp) {
+ f->dump_stream("pgid") << elem.first;
+ f->dump_int("osd", elem.second);
}
f->close_section(); // primary_temp
f->close_section();
f->open_array_section("new_up_thru");
- for (map<int32_t,uint32_t>::const_iterator p = new_up_thru.begin(); p != new_up_thru.end(); ++p) {
+
+ for (const auto &elem : new_up_thru) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_int("up_thru", p->second);
+ f->dump_int("osd", elem.first);
+ f->dump_int("up_thru", elem.second);
f->close_section();
}
f->close_section();
f->open_array_section("new_lost");
- for (map<int32_t,uint32_t>::const_iterator p = new_lost.begin(); p != new_lost.end(); ++p) {
+
+ for (const auto &elem : new_lost) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_int("epoch_lost", p->second);
+ f->dump_int("osd", elem.first);
+ f->dump_int("epoch_lost", elem.second);
f->close_section();
}
f->close_section();
f->open_array_section("new_last_clean_interval");
- for (map<int32_t,pair<epoch_t,epoch_t> >::const_iterator p = new_last_clean_interval.begin();
- p != new_last_clean_interval.end();
- ++p) {
+
+ for (const auto &elem : new_last_clean_interval) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_int("first", p->second.first);
- f->dump_int("last", p->second.second);
+ f->dump_int("osd", elem.first);
+ f->dump_int("first", elem.second.first);
+ f->dump_int("last", elem.second.second);
f->close_section();
}
f->close_section();
f->open_array_section("new_blacklist");
- for (map<entity_addr_t,utime_t>::const_iterator p = new_blacklist.begin();
- p != new_blacklist.end();
- ++p) {
+ for (const auto &elem : new_blacklist) {
stringstream ss;
- ss << p->first;
- f->dump_stream(ss.str().c_str()) << p->second;
+ ss << elem.first;
+ f->dump_stream(ss.str().c_str()) << elem.second;
}
f->close_section();
f->open_array_section("old_blacklist");
- for (vector<entity_addr_t>::const_iterator p = old_blacklist.begin(); p != old_blacklist.end(); ++p)
- f->dump_stream("addr") << *p;
+ for (const auto &elem : old_blacklist)
+ f->dump_stream("addr") << elem;
f->close_section();
f->open_array_section("new_xinfo");
- for (map<int32_t,osd_xinfo_t>::const_iterator p = new_xinfo.begin(); p != new_xinfo.end(); ++p) {
+ for (const auto &elem : new_xinfo) {
f->open_object_section("xinfo");
- f->dump_int("osd", p->first);
- p->second.dump(f);
+ f->dump_int("osd", elem.first);
+ elem.second.dump(f);
f->close_section();
}
f->close_section();
f->dump_string("cluster_snapshot", cluster_snapshot);
f->open_array_section("new_uuid");
- for (map<int32_t,uuid_d>::const_iterator p = new_uuid.begin(); p != new_uuid.end(); ++p) {
+ for (const auto &elem : new_uuid) {
f->open_object_section("osd");
- f->dump_int("osd", p->first);
- f->dump_stream("uuid") << p->second;
+ f->dump_int("osd", elem.first);
+ f->dump_stream("uuid") << elem.second;
f->close_section();
}
f->close_section();
OSDMap::dump_erasure_code_profiles(new_erasure_code_profiles, f);
f->open_array_section("old_erasure_code_profiles");
- for (vector<string>::const_iterator p = old_erasure_code_profiles.begin();
- p != old_erasure_code_profiles.end();
- ++p) {
- f->dump_string("old", p->c_str());
+ for (const auto &elem : old_erasure_code_profiles) {
+ f->dump_string("old", elem.c_str());
}
f->close_section();
}
void OSDMap::set_epoch(epoch_t e)
{
epoch = e;
- for (map<int64_t,pg_pool_t>::iterator p = pools.begin();
- p != pools.end();
- ++p)
- p->second.last_change = e;
+ for (auto &elem : pools)
+ elem.second.last_change = e;
}
bool OSDMap::is_blacklisted(const entity_addr_t& a) const
void OSDMap::adjust_osd_weights(const map<int,double>& weights, Incremental& inc) const
{
float max = 0;
- for (map<int,double>::const_iterator p = weights.begin();
- p != weights.end(); ++p) {
- if (p->second > max)
- max = p->second;
+ for (const auto &elem : weights) {
+ if (elem.second > max)
+ max = elem.second;
}
- for (map<int,double>::const_iterator p = weights.begin();
- p != weights.end(); ++p) {
- inc.new_weight[p->first] = (unsigned)((p->second / max) * CEPH_OSD_IN);
+ for (const auto &elem : weights) {
+ inc.new_weight[elem.first] = (unsigned)((elem.second / max) * CEPH_OSD_IN);
}
}
features |= CEPH_FEATUREMASK_OSDMAP_REMAP;
mask |= CEPH_FEATUREMASK_OSDMAP_REMAP;
- for (auto p = pools.begin(); p != pools.end(); ++p) {
- if (p->second.has_flag(pg_pool_t::FLAG_HASHPSPOOL)) {
+ for (auto &elem: pools) {
+ if (elem.second.has_flag(pg_pool_t::FLAG_HASHPSPOOL)) {
features |= CEPH_FEATURE_OSDHASHPSPOOL;
}
- if (p->second.is_erasure() &&
+ if (elem.second.is_erasure() &&
entity_type != CEPH_ENTITY_TYPE_CLIENT) { // not for clients
features |= CEPH_FEATURE_OSD_ERASURE_CODES;
}
- if (!p->second.tiers.empty() ||
- p->second.is_tier()) {
+ if (!elem.second.tiers.empty() ||
+ elem.second.is_tier()) {
features |= CEPH_FEATURE_OSD_CACHEPOOL;
}
- int ruleid = crush->find_rule(p->second.get_crush_ruleset(),
- p->second.get_type(),
- p->second.get_size());
+ int ruleid = crush->find_rule(elem.second.get_crush_ruleset(),
+ elem.second.get_type(),
+ elem.second.get_size());
if (ruleid >= 0) {
if (crush->is_v2_rule(ruleid))
features |= CEPH_FEATURE_CRUSH_V2;
}
}
if (entity_type == CEPH_ENTITY_TYPE_OSD) {
- for (auto p = erasure_code_profiles.begin();
- p != erasure_code_profiles.end();
- ++p) {
- const map<string,string> &profile = p->second;
- map<string,string>::const_iterator plugin = profile.find("plugin");
+ for (auto &elem : erasure_code_profiles) {
+ const map<string,string> &profile = elem.second;
+ const auto &plugin = profile.find("plugin");
if (plugin != profile.end()) {
if (plugin->second == "isa" || plugin->second == "lrc")
features |= CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2;
tmpmap.deepish_copy_from(osdmap);
tmpmap.apply_incremental(*pending_inc);
- for (map<pg_t,vector<int32_t> >::iterator p = tmpmap.pg_temp->begin();
- p != tmpmap.pg_temp->end();
- ++p) {
+ for (auto &elem : *tmpmap.pg_temp) {
// if pool does not exist, remove any existing pg_temps associated with
// it. we don't care about pg_temps on the pending_inc either; if there
// are new_pg_temp entries on the pending, clear them out just as well.
- if (!osdmap.have_pg_pool(p->first.pool())) {
- ldout(cct, 10) << __func__ << " removing pg_temp " << p->first
- << " for nonexistent pool " << p->first.pool() << dendl;
- pending_inc->new_pg_temp[p->first].clear();
+ if (!osdmap.have_pg_pool(elem.first.pool())) {
+ ldout(cct, 10) << __func__ << " removing pg_temp " << elem.first
+ << " for nonexistent pool " << elem.first.pool() << dendl;
+ pending_inc->new_pg_temp[elem.first].clear();
continue;
}
// all osds down?
unsigned num_up = 0;
- for (auto o : p->second) {
+ for (auto o : elem.second) {
if (!tmpmap.is_down(o)) {
++num_up;
break;
}
}
if (num_up == 0) {
- ldout(cct, 10) << __func__ << " removing pg_temp " << p->first
- << " with all down osds" << p->second << dendl;
- pending_inc->new_pg_temp[p->first].clear();
+ ldout(cct, 10) << __func__ << " removing pg_temp " << elem.first
+ << " with all down osds" << elem.second << dendl;
+ pending_inc->new_pg_temp[elem.first].clear();
continue;
}
// redundant pg_temp?
vector<int> raw_up;
int primary;
- tmpmap.pg_to_raw_up(p->first, &raw_up, &primary);
- if (raw_up == p->second) {
- ldout(cct, 10) << __func__ << " removing pg_temp " << p->first << " "
- << p->second << " that matches raw_up mapping" << dendl;
- if (osdmap.pg_temp->count(p->first))
- pending_inc->new_pg_temp[p->first].clear();
+ tmpmap.pg_to_raw_up(elem.first, &raw_up, &primary);
+ if (raw_up == elem.second) {
+ ldout(cct, 10) << __func__ << " removing pg_temp " << elem.first << " "
+ << elem.second << " that matches raw_up mapping" << dendl;
+ if (osdmap.pg_temp->count(elem.first))
+ pending_inc->new_pg_temp[elem.first].clear();
else
- pending_inc->new_pg_temp.erase(p->first);
+ pending_inc->new_pg_temp.erase(elem.first);
}
}
- for (map<pg_t,int32_t>::iterator p = tmpmap.primary_temp->begin();
- p != tmpmap.primary_temp->end();
- ++p) {
+ for (auto &elem : *tmpmap.primary_temp) {
// primary down?
- if (tmpmap.is_down(p->second)) {
- ldout(cct, 10) << __func__ << " removing primary_temp " << p->first
- << " to down " << p->second << dendl;
- pending_inc->new_primary_temp[p->first] = -1;
+ if (tmpmap.is_down(elem.second)) {
+ ldout(cct, 10) << __func__ << " removing primary_temp " << elem.first
+ << " to down " << elem.second << dendl;
+ pending_inc->new_primary_temp[elem.first] = -1;
continue;
}
// redundant primary_temp?
vector<int> real_up, templess_up;
int real_primary, templess_primary;
- pg_t pgid = p->first;
+ pg_t pgid = elem.first;
tmpmap.pg_to_acting_osds(pgid, &real_up, &real_primary);
tmpmap.pg_to_raw_up(pgid, &templess_up, &templess_primary);
if (real_primary == templess_primary){
if (inc.new_pool_max != -1)
pool_max = inc.new_pool_max;
- for (map<int64_t,pg_pool_t>::const_iterator p = inc.new_pools.begin();
- p != inc.new_pools.end();
- ++p) {
- pools[p->first] = p->second;
- pools[p->first].last_change = epoch;
+ for (const auto &elem : inc.new_pools) {
+ pools[elem.first] = elem.second;
+ pools[elem.first].last_change = epoch;
}
- for (map<int64_t,string>::const_iterator p = inc.new_pool_names.begin();
- p != inc.new_pool_names.end();
- ++p) {
- auto pool_name_entry = pool_name.find(p->first);
+
+ for (const auto &elem : inc.new_pool_names) {
+ auto pool_name_entry = pool_name.find(elem.first);
if (pool_name_entry != pool_name.end()) {
name_pool.erase(pool_name_entry->second);
- pool_name_entry->second = p->second;
+ pool_name_entry->second = elem.second;
} else {
- pool_name[p->first] = p->second;
+ pool_name[elem.first] = elem.second;
}
- name_pool[p->second] = p->first;
+ name_pool[elem.second] = elem.first;
}
- for (set<int64_t>::const_iterator p = inc.old_pools.begin();
- p != inc.old_pools.end();
- ++p) {
- pools.erase(*p);
- name_pool.erase(pool_name[*p]);
- pool_name.erase(*p);
+ for (const auto &elem : inc.old_pools) {
+ pools.erase(elem);
+ name_pool.erase(pool_name[elem]);
+ pool_name.erase(elem);
}
- for (map<int32_t,uint32_t>::const_iterator i = inc.new_weight.begin();
- i != inc.new_weight.end();
- ++i) {
- set_weight(i->first, i->second);
+ for (const auto &elem : inc.new_weight) {
+ set_weight(elem.first, elem.second);
// if we are marking in, clear the AUTOOUT and NEW bits, and clear
// xinfo old_weight.
- if (i->second) {
- osd_state[i->first] &= ~(CEPH_OSD_AUTOOUT | CEPH_OSD_NEW);
- osd_xinfo[i->first].old_weight = 0;
+ if (elem.second) {
+ osd_state[elem.first] &= ~(CEPH_OSD_AUTOOUT | CEPH_OSD_NEW);
+ osd_xinfo[elem.first].old_weight = 0;
}
}
- for (map<int32_t,uint32_t>::const_iterator i = inc.new_primary_affinity.begin();
- i != inc.new_primary_affinity.end();
- ++i) {
- set_primary_affinity(i->first, i->second);
+ for (const auto &elem : inc.new_primary_affinity) {
+ set_primary_affinity(elem.first, elem.second);
}
// erasure_code_profiles
- for (vector<string>::const_iterator i = inc.old_erasure_code_profiles.begin();
- i != inc.old_erasure_code_profiles.end();
- ++i)
- erasure_code_profiles.erase(*i);
+ for (const auto &elem : inc.old_erasure_code_profiles)
+ erasure_code_profiles.erase(elem);
- for (map<string,map<string,string> >::const_iterator i =
- inc.new_erasure_code_profiles.begin();
- i != inc.new_erasure_code_profiles.end();
- ++i) {
- set_erasure_code_profile(i->first, i->second);
+ for (const auto &elem : inc.new_erasure_code_profiles) {
+ set_erasure_code_profile(elem.first, elem.second);
}
// up/down
- for (map<int32_t,uint8_t>::const_iterator i = inc.new_state.begin();
- i != inc.new_state.end();
- ++i) {
- int s = i->second ? i->second : CEPH_OSD_UP;
- if ((osd_state[i->first] & CEPH_OSD_UP) &&
+ for (const auto &elem : inc.new_state) {
+ int s = elem.second ? elem.second : CEPH_OSD_UP;
+ if ((osd_state[elem.first] & CEPH_OSD_UP) &&
(s & CEPH_OSD_UP)) {
- osd_info[i->first].down_at = epoch;
- osd_xinfo[i->first].down_stamp = modified;
+ osd_info[elem.first].down_at = epoch;
+ osd_xinfo[elem.first].down_stamp = modified;
}
- if ((osd_state[i->first] & CEPH_OSD_EXISTS) &&
+ if ((osd_state[elem.first] & CEPH_OSD_EXISTS) &&
(s & CEPH_OSD_EXISTS)) {
// osd is destroyed; clear out anything interesting.
- (*osd_uuid)[i->first] = uuid_d();
- osd_info[i->first] = osd_info_t();
- osd_xinfo[i->first] = osd_xinfo_t();
- set_primary_affinity(i->first, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY);
- osd_addrs->client_addr[i->first].reset(new entity_addr_t());
- osd_addrs->cluster_addr[i->first].reset(new entity_addr_t());
- osd_addrs->hb_front_addr[i->first].reset(new entity_addr_t());
- osd_addrs->hb_back_addr[i->first].reset(new entity_addr_t());
- osd_state[i->first] = 0;
+ (*osd_uuid)[elem.first] = uuid_d();
+ osd_info[elem.first] = osd_info_t();
+ osd_xinfo[elem.first] = osd_xinfo_t();
+ set_primary_affinity(elem.first, CEPH_OSD_DEFAULT_PRIMARY_AFFINITY);
+ osd_addrs->client_addr[elem.first].reset(new entity_addr_t());
+ osd_addrs->cluster_addr[elem.first].reset(new entity_addr_t());
+ osd_addrs->hb_front_addr[elem.first].reset(new entity_addr_t());
+ osd_addrs->hb_back_addr[elem.first].reset(new entity_addr_t());
+ osd_state[elem.first] = 0;
} else {
- osd_state[i->first] ^= s;
+ osd_state[elem.first] ^= s;
}
}
- for (map<int32_t,entity_addr_t>::const_iterator i = inc.new_up_client.begin();
- i != inc.new_up_client.end();
- ++i) {
- osd_state[i->first] |= CEPH_OSD_EXISTS | CEPH_OSD_UP;
- osd_addrs->client_addr[i->first].reset(new entity_addr_t(i->second));
+
+ for (const auto &elem : inc.new_up_client) {
+ osd_state[elem.first] |= CEPH_OSD_EXISTS | CEPH_OSD_UP;
+ osd_addrs->client_addr[elem.first].reset(new entity_addr_t(elem.second));
if (inc.new_hb_back_up.empty())
- osd_addrs->hb_back_addr[i->first].reset(new entity_addr_t(i->second)); //this is a backward-compatibility hack
+ osd_addrs->hb_back_addr[elem.first].reset(new entity_addr_t(elem.second)); //this is a backward-compatibility hack
else
- osd_addrs->hb_back_addr[i->first].reset(
- new entity_addr_t(inc.new_hb_back_up.find(i->first)->second));
- map<int32_t,entity_addr_t>::const_iterator j = inc.new_hb_front_up.find(i->first);
+ osd_addrs->hb_back_addr[elem.first].reset(
+ new entity_addr_t(inc.new_hb_back_up.find(elem.first)->second));
+ const auto j = inc.new_hb_front_up.find(elem.first);
if (j != inc.new_hb_front_up.end())
- osd_addrs->hb_front_addr[i->first].reset(new entity_addr_t(j->second));
+ osd_addrs->hb_front_addr[elem.first].reset(new entity_addr_t(j->second));
else
- osd_addrs->hb_front_addr[i->first].reset();
+ osd_addrs->hb_front_addr[elem.first].reset();
- osd_info[i->first].up_from = epoch;
+ osd_info[elem.first].up_from = epoch;
}
- for (map<int32_t,entity_addr_t>::const_iterator i = inc.new_up_cluster.begin();
- i != inc.new_up_cluster.end();
- ++i)
- osd_addrs->cluster_addr[i->first].reset(new entity_addr_t(i->second));
+
+ for (const auto &elem : inc.new_up_cluster)
+ osd_addrs->cluster_addr[elem.first].reset(new entity_addr_t(elem.second));
// info
- for (map<int32_t,epoch_t>::const_iterator i = inc.new_up_thru.begin();
- i != inc.new_up_thru.end();
- ++i)
- osd_info[i->first].up_thru = i->second;
- for (map<int32_t,pair<epoch_t,epoch_t> >::const_iterator i = inc.new_last_clean_interval.begin();
- i != inc.new_last_clean_interval.end();
- ++i) {
- osd_info[i->first].last_clean_begin = i->second.first;
- osd_info[i->first].last_clean_end = i->second.second;
- }
- for (map<int32_t,epoch_t>::const_iterator p = inc.new_lost.begin(); p != inc.new_lost.end(); ++p)
- osd_info[p->first].lost_at = p->second;
+ for (const auto &elem : inc.new_up_thru)
+ osd_info[elem.first].up_thru = elem.second;
+ for (const auto &elem : inc.new_last_clean_interval) {
+ osd_info[elem.first].last_clean_begin = elem.second.first;
+ osd_info[elem.first].last_clean_end = elem.second.second;
+ }
+ for (const auto &elem : inc.new_lost)
+ osd_info[elem.first].lost_at = elem.second;
// xinfo
- for (map<int32_t,osd_xinfo_t>::const_iterator p = inc.new_xinfo.begin(); p != inc.new_xinfo.end(); ++p)
- osd_xinfo[p->first] = p->second;
+ for (const auto &elem : inc.new_xinfo)
+ osd_xinfo[elem.first] = elem.second;
// uuid
- for (map<int32_t,uuid_d>::const_iterator p = inc.new_uuid.begin(); p != inc.new_uuid.end(); ++p)
- (*osd_uuid)[p->first] = p->second;
+ for (const auto &elem : inc.new_uuid)
+ (*osd_uuid)[elem.first] = elem.second;
// pg rebuild
- for (map<pg_t, vector<int> >::const_iterator p = inc.new_pg_temp.begin(); p != inc.new_pg_temp.end(); ++p) {
- if (p->second.empty())
- pg_temp->erase(p->first);
+ for (const auto &elem : inc.new_pg_temp) {
+ if (elem.second.empty())
+ pg_temp->erase(elem.first);
else
- (*pg_temp)[p->first] = p->second;
+ (*pg_temp)[elem.first] = elem.second;
}
- for (map<pg_t,int32_t>::const_iterator p = inc.new_primary_temp.begin();
- p != inc.new_primary_temp.end();
- ++p) {
- if (p->second == -1)
- primary_temp->erase(p->first);
+ for (const auto &elem : inc.new_primary_temp) {
+ if (elem.second == -1)
+ primary_temp->erase(elem.first);
else
- (*primary_temp)[p->first] = p->second;
+ (*primary_temp)[elem.first] = elem.second;
}
for (auto& p : inc.new_pg_remap) {
blacklist.insert(inc.new_blacklist.begin(),inc.new_blacklist.end());
new_blacklist_entries = true;
}
- for (vector<entity_addr_t>::const_iterator p = inc.old_blacklist.begin();
- p != inc.old_blacklist.end();
- ++p)
- blacklist.erase(*p);
+ for (const auto &elem : inc.old_blacklist)
+ blacklist.erase(elem);
// cluster snapshot?
if (inc.cluster_snapshot.length()) {
// do new crush map last (after up/down stuff)
if (inc.crush.length()) {
bufferlist bl(inc.crush);
- bufferlist::iterator blp = bl.begin();
+ auto blp = bl.begin();
crush.reset(new CrushWrapper);
crush->decode(blp);
}
if (removed)
osds.resize(osds.size() - removed);
} else {
- for (vector<int>::iterator p = osds.begin(); p != osds.end(); ++p) {
- if (!exists(*p))
- *p = CRUSH_ITEM_NONE;
+ for (auto &elem : osds) {
+ if (!exists(elem))
+ elem = CRUSH_ITEM_NONE;
}
}
}
return;
bool any = false;
- for (vector<int>::const_iterator p = osds->begin(); p != osds->end(); ++p) {
- if (*p != CRUSH_ITEM_NONE &&
- (*osd_primary_affinity)[*p] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) {
+ for (const auto &elem : *osds) {
+ if (elem != CRUSH_ITEM_NONE &&
+ (*osd_primary_affinity)[elem] != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) {
any = true;
break;
}
vector<int> *temp_pg, int *temp_primary) const
{
pg = pool.raw_pg_to_pg(pg);
- map<pg_t,vector<int32_t> >::const_iterator p = pg_temp->find(pg);
+ const auto p = pg_temp->find(pg);
temp_pg->clear();
if (p != pg_temp->end()) {
for (unsigned i=0; i<p->second.size(); i++) {
}
}
}
- map<pg_t,int32_t>::const_iterator pp = primary_temp->find(pg);
+ const auto &pp = primary_temp->find(pg);
*temp_primary = -1;
if (pp != primary_temp->end()) {
*temp_primary = pp->second;
// for ::encode(pools, bl);
__u32 n = pools.size();
::encode(n, bl);
- for (map<int64_t,pg_pool_t>::const_iterator p = pools.begin();
- p != pools.end();
- ++p) {
- n = p->first;
+
+ for (const auto &elem : pools) {
+ n = elem.first;
::encode(n, bl);
- ::encode(p->second, bl, 0);
+ ::encode(elem.second, bl, 0);
}
// for ::encode(pool_name, bl);
n = pool_name.size();
::encode(n, bl);
- for (map<int64_t, string>::const_iterator p = pool_name.begin();
- p != pool_name.end();
- ++p) {
- n = p->first;
+ for (const auto &elem : pool_name) {
+ n = elem.first;
::encode(n, bl);
- ::encode(p->second, bl);
+ ::encode(elem.second, bl);
}
// for ::encode(pool_max, bl);
n = pool_max;
// for ::encode(pg_temp, bl);
n = pg_temp->size();
::encode(n, bl);
- for (map<pg_t,vector<int32_t> >::const_iterator p = pg_temp->begin();
- p != pg_temp->end();
- ++p) {
- old_pg_t opg = p->first.get_old_pg();
+ for (const auto &elem : *pg_temp) {
+ old_pg_t opg = elem.first.get_old_pg();
::encode(opg, bl);
- ::encode(p->second, bl);
+ ::encode(elem.second, bl);
}
// crush
// put this in a sorted, ordered map<> so that we encode in a
// deterministic order.
map<entity_addr_t,utime_t> blacklist_map;
- for (ceph::unordered_map<entity_addr_t,utime_t>::const_iterator p =
- blacklist.begin(); p != blacklist.end(); ++p)
- blacklist_map.insert(make_pair(p->first, p->second));
+ for (const auto &elem : blacklist)
+ blacklist_map.insert(make_pair(elem.first, elem.second));
::encode(blacklist_map, bl, features);
}
::encode(osd_addrs->cluster_addr, bl, features);
void OSDMap::decode(bufferlist& bl)
{
- bufferlist::iterator p = bl.begin();
+ auto p = bl.begin();
decode(p);
}
// crush
bufferlist cbl;
::decode(cbl, p);
- bufferlist::iterator cblp = cbl.begin();
+ auto cblp = cbl.begin();
crush->decode(cblp);
// extended
// crush
bufferlist cbl;
::decode(cbl, bl);
- bufferlist::iterator cblp = cbl.begin();
+ auto cblp = cbl.begin();
crush->decode(cblp);
if (struct_v >= 3) {
::decode(erasure_code_profiles, bl);
{
// index pool names
name_pool.clear();
- for (map<int64_t,string>::iterator i = pool_name.begin();
- i != pool_name.end(); ++i) {
- name_pool[i->second] = i->first;
+ for (const auto &elem : pool_name) {
+ name_pool[elem.second] = elem.first;
}
calc_num_osds();
Formatter *f)
{
f->open_object_section("erasure_code_profiles");
- for (map<string,map<string,string> >::const_iterator i = profiles.begin();
- i != profiles.end();
- ++i) {
- f->open_object_section(i->first.c_str());
- for (map<string,string>::const_iterator j = i->second.begin();
- j != i->second.end();
- ++j) {
- f->dump_string(j->first.c_str(), j->second.c_str());
+ for (const auto &elemp : profiles) {
+ f->open_object_section(elemp.first.c_str());
+ for (const auto &elems : elemp.second) {
+ f->dump_string(elems.first.c_str(), elems.second.c_str());
}
f->close_section();
}
f->dump_int("max_osd", get_max_osd());
f->open_array_section("pools");
- for (map<int64_t,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
+ for (const auto &elem : pools) {
std::string name("<unknown>");
- map<int64_t,string>::const_iterator pni = pool_name.find(p->first);
+ const auto &pni = pool_name.find(elem.first);
if (pni != pool_name.end())
name = pni->second;
f->open_object_section("pool");
- f->dump_int("pool", p->first);
+ f->dump_int("pool", elem.first);
f->dump_string("pool_name", name);
- p->second.dump(f);
+ elem.second.dump(f);
f->close_section();
}
f->close_section();
set<string> st;
get_state(i, st);
f->open_array_section("state");
- for (set<string>::iterator p = st.begin(); p != st.end(); ++p)
- f->dump_string("state", *p);
+ for (auto &elem : st)
+ f->dump_string("state", elem);
f->close_section();
f->close_section();
}
f->close_section();
f->open_array_section("pg_temp");
- for (map<pg_t,vector<int32_t> >::const_iterator p = pg_temp->begin();
- p != pg_temp->end();
- ++p) {
+ for (const auto &elemp : *pg_temp) {
f->open_object_section("osds");
- f->dump_stream("pgid") << p->first;
+ f->dump_stream("pgid") << elemp.first;
f->open_array_section("osds");
- for (vector<int>::const_iterator q = p->second.begin(); q != p->second.end(); ++q)
- f->dump_int("osd", *q);
+ for (const auto &elems : elemp.second)
+ f->dump_int("osd", elems);
f->close_section();
f->close_section();
}
f->close_section();
f->open_array_section("primary_temp");
- for (map<pg_t, int32_t>::const_iterator p = primary_temp->begin();
- p != primary_temp->end();
- ++p) {
- f->dump_stream("pgid") << p->first;
- f->dump_int("osd", p->second);
+ for (const auto &elem : *primary_temp) {
+ f->dump_stream("pgid") << elem.first;
+ f->dump_int("osd", elem.second);
}
f->close_section(); // primary_temp
f->open_object_section("blacklist");
- for (ceph::unordered_map<entity_addr_t,utime_t>::const_iterator p = blacklist.begin();
- p != blacklist.end();
- ++p) {
+ for (const auto &elem : blacklist) {
stringstream ss;
- ss << p->first;
- f->dump_stream(ss.str().c_str()) << p->second;
+ ss << elem.first;
+ f->dump_stream(ss.str().c_str()) << elem.second;
}
f->close_section();
void OSDMap::print_pools(ostream& out) const
{
- for (map<int64_t,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
+ for (const auto &elemp : pools) {
std::string name("<unknown>");
- map<int64_t,string>::const_iterator pni = pool_name.find(p->first);
+ const auto &pni = pool_name.find(elemp.first);
if (pni != pool_name.end())
name = pni->second;
- out << "pool " << p->first
+ out << "pool " << elemp.first
<< " '" << name
- << "' " << p->second << "\n";
- for (map<snapid_t,pool_snap_info_t>::const_iterator q = p->second.snaps.begin();
- q != p->second.snaps.end();
- ++q)
- out << "\tsnap " << q->second.snapid << " '" << q->second.name << "' " << q->second.stamp << "\n";
- if (!p->second.removed_snaps.empty())
- out << "\tremoved_snaps " << p->second.removed_snaps << "\n";
+ << "' " << elemp.second << "\n";
+
+ for (const auto &elems : elemp.second.snaps)
+ out << "\tsnap " << elems.second.snapid << " '" << elems.second.name << "' " << elems.second.stamp << "\n";
+
+ if (!elemp.second.removed_snaps.empty())
+ out << "\tremoved_snaps " << elemp.second.removed_snaps << "\n";
}
out << std::endl;
}
out << "pg_remap_items " << p.first << " " << p.second << "\n";
}
- for (map<pg_t,vector<int32_t> >::const_iterator p = pg_temp->begin();
- p != pg_temp->end();
- ++p)
- out << "pg_temp " << p->first << " " << p->second << "\n";
+ for (const auto &elem : *pg_temp)
+ out << "pg_temp " << elem.first << " " << elem.second << "\n";
- for (map<pg_t,int32_t>::const_iterator p = primary_temp->begin();
- p != primary_temp->end();
- ++p)
- out << "primary_temp " << p->first << " " << p->second << "\n";
+ for (const auto &elem : *primary_temp)
+ out << "primary_temp " << elem.first << " " << elem.second << "\n";
- for (ceph::unordered_map<entity_addr_t,utime_t>::const_iterator p = blacklist.begin();
- p != blacklist.end();
- ++p)
- out << "blacklist " << p->first << " expires " << p->second << "\n";
+ for (const auto &elem : blacklist)
+ out << "blacklist " << elem.first << " expires " << elem.second << "\n";
// ignore pg_swap_primary
}
bool OSDMap::crush_ruleset_in_use(int ruleset) const
{
- for (map<int64_t,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
- if (p->second.crush_ruleset == ruleset)
+ for (const auto &elem : pools) {
+ if (elem.second.crush_ruleset == ruleset)
return true;
}
return false;
const md_config_t *conf = cct->_conf;
vector<string> sections;
conf->get_all_sections(sections);
- for (vector<string>::iterator i = sections.begin(); i != sections.end(); ++i) {
- if (i->find("osd.") != 0)
+
+ for (auto &elem : sections) {
+ if (elem.find("osd.") != 0)
continue;
- const char *begin = i->c_str() + 4;
+ const char *begin = elem.c_str() + 4;
char *end = (char*)begin;
int o = strtol(begin, &end, 10);
if (*end != '\0')
int const default_replicated_ruleset = crush->get_osd_pool_default_crush_replicated_ruleset(cct);
assert(default_replicated_ruleset >= 0);
- for (vector<string>::iterator p = pool_names.begin();
- p != pool_names.end(); ++p) {
+ for (auto &elem : pool_names) {
int64_t pool = ++pool_max;
pools[pool].type = pg_pool_t::TYPE_REPLICATED;
pools[pool].flags = cct->_conf->osd_pool_default_flags;
pools[pool].set_pg_num(poolbase << pg_bits);
pools[pool].set_pgp_num(poolbase << pgp_bits);
pools[pool].last_change = epoch;
- pool_name[pool] = *p;
- name_pool[*p] = pool;
+ pool_name[pool] = elem;
+ name_pool[elem] = pool;
}
for (int i=0; i<get_max_osd(); i++) {
// add osds
vector<string> sections;
conf->get_all_sections(sections);
- for (vector<string>::iterator i = sections.begin(); i != sections.end(); ++i) {
- if (i->find("osd.") != 0)
+
+ for (auto &elem : sections) {
+ if (elem.find("osd.") != 0)
continue;
- const char *begin = i->c_str() + 4;
+ const char *begin = elem.c_str() + 4;
char *end = (char*)begin;
int o = strtol(begin, &end, 10);
if (*end != '\0')
string host, rack, row, room, dc, pool;
vector<string> sections;
sections.push_back("osd");
- sections.push_back(*i);
+ sections.push_back(elem);
conf->get_val_from_conf_file(sections, "host", host, false);
conf->get_val_from_conf_file(sections, "rack", rack, false);
conf->get_val_from_conf_file(sections, "row", row, false);
loc["root"] = "default";
ldout(cct, 5) << " adding osd." << o << " at " << loc << dendl;
- crush.insert_item(cct, o, 1.0, *i, loc);
+ crush.insert_item(cct, o, 1.0, elem, loc);
}
build_simple_crush_rulesets(cct, crush, "default", ss);