<< (restrict_to_up_acting ? " restrict_to_up_acting" : "") << std::endl;
// select primary
- map<pg_shard_t,pg_info_t>::const_iterator primary = all_info.find(up_primary);
+ auto primary = all_info.find(up_primary);
if (up.size() &&
!primary->second.is_incomplete() &&
primary->second.last_update >=
<< " with " << primary->second << std::endl;
want->push_back(primary->first.osd);
acting_backfill->insert(primary->first);
- unsigned usable = 1;
/* We include auth_log_shard->second.log_tail because in GetLog,
* we will request logs back to the min last_update over our
// select replicas that have log contiguity with primary.
// prefer up, then acting, then any peer_info osds
- for (vector<int>::const_iterator i = up.begin();
- i != up.end();
- ++i) {
- pg_shard_t up_cand = pg_shard_t(*i, shard_id_t::NO_SHARD);
+ for (auto i : up) {
+ pg_shard_t up_cand = pg_shard_t(i, shard_id_t::NO_SHARD);
if (up_cand == primary->first)
continue;
const pg_info_t &cur_info = all_info.find(up_cand)->second;
backfill->insert(up_cand);
acting_backfill->insert(up_cand);
} else {
- want->push_back(*i);
+ want->push_back(i);
acting_backfill->insert(up_cand);
- usable++;
- ss << " osd." << *i << " (up) accepted " << cur_info << std::endl;
+ ss << " osd." << i << " (up) accepted " << cur_info << std::endl;
}
}
- if (usable >= size) {
+ if (want->size() >= size) {
return;
}
std::vector<std::pair<eversion_t, int>> candidate_by_last_update;
candidate_by_last_update.reserve(acting.size());
// This no longer has backfill OSDs, but they are covered above.
- for (vector<int>::const_iterator i = acting.begin();
- i != acting.end();
- ++i) {
- pg_shard_t acting_cand(*i, shard_id_t::NO_SHARD);
+ for (auto i : acting) {
+ pg_shard_t acting_cand(i, shard_id_t::NO_SHARD);
// skip up osds we already considered above
if (acting_cand == primary->first)
continue;
- vector<int>::const_iterator up_it = find(up.begin(), up.end(), *i);
+ vector<int>::const_iterator up_it = find(up.begin(), up.end(), i);
if (up_it != up.end())
continue;
ss << " shard " << acting_cand << " (acting) REJECTED "
<< cur_info << std::endl;
} else {
- candidate_by_last_update.push_back(make_pair(cur_info.last_update, *i));
+ candidate_by_last_update.push_back(make_pair(cur_info.last_update, i));
}
}
+ auto sort_by_eversion =[](const std::pair<eversion_t, int> &lhs,
+ const std::pair<eversion_t, int> &rhs) {
+ return lhs.first > rhs.first;
+ };
// sort by last_update, in descending order.
- std::sort(candidate_by_last_update.begin(), candidate_by_last_update.end(),
- [](const std::pair<eversion_t, int> &lhs,
- const std::pair<eversion_t, int> &rhs) {
- return lhs.first > rhs.first;
- }
- );
-
+ std::sort(candidate_by_last_update.begin(),
+ candidate_by_last_update.end(), sort_by_eversion);
for (auto &p: candidate_by_last_update) {
- ceph_assert(usable < size);
+ ceph_assert(want->size() < size);
want->push_back(p.second);
pg_shard_t s = pg_shard_t(p.second, shard_id_t::NO_SHARD);
acting_backfill->insert(s);
ss << " shard " << s << " (acting) accepted "
<< all_info.find(s)->second << std::endl;
- usable++;
- if (usable >= size) {
+ if (want->size() >= size) {
return;
}
}
}
candidate_by_last_update.clear();
candidate_by_last_update.reserve(all_info.size()); // overestimate but fine
- for (map<pg_shard_t,pg_info_t>::const_iterator i = all_info.begin();
- i != all_info.end();
- ++i) {
+ // continue to search stray to find more suitable peers
+ for (auto &i : all_info) {
// skip up osds we already considered above
- if (i->first == primary->first)
+ if (i.first == primary->first)
continue;
- vector<int>::const_iterator up_it = find(up.begin(), up.end(), i->first.osd);
+ vector<int>::const_iterator up_it = find(up.begin(), up.end(), i.first.osd);
if (up_it != up.end())
continue;
vector<int>::const_iterator acting_it = find(
- acting.begin(), acting.end(), i->first.osd);
+ acting.begin(), acting.end(), i.first.osd);
if (acting_it != acting.end())
continue;
- if (i->second.is_incomplete() ||
- i->second.last_update < oldest_auth_log_entry) {
- ss << " shard " << i->first << " (stray) REJECTED "
- << i->second << std::endl;
+ if (i.second.is_incomplete() ||
+ i.second.last_update < oldest_auth_log_entry) {
+ ss << " shard " << i.first << " (stray) REJECTED " << i.second
+ << std::endl;
} else {
candidate_by_last_update.push_back(
- make_pair(i->second.last_update, i->first.osd));
+ make_pair(i.second.last_update, i.first.osd));
}
}
}
// sort by last_update, in descending order.
- std::sort(candidate_by_last_update.begin(), candidate_by_last_update.end(),
- [](const std::pair<eversion_t, int> &lhs,
- const std::pair<eversion_t, int> &rhs) {
- return lhs.first > rhs.first;
- }
- );
+ std::sort(candidate_by_last_update.begin(),
+ candidate_by_last_update.end(), sort_by_eversion);
for (auto &p: candidate_by_last_update) {
- ceph_assert(usable < size);
+ ceph_assert(want->size() < size);
want->push_back(p.second);
pg_shard_t s = pg_shard_t(p.second, shard_id_t::NO_SHARD);
acting_backfill->insert(s);
ss << " shard " << s << " (stray) accepted "
<< all_info.find(s)->second << std::endl;
- usable++;
- if (usable >= size) {
+ if (want->size() >= size) {
return;
}
}