diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 26c588d603e..7febc5b7203 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -353,18 +353,30 @@ bool OSDMonitor::thrash() while (n--) ++p; for (int i=0; i<50; i++) { + unsigned size = osdmap.get_pg_size(p->first); vector v; - for (int j=0; j<3; j++) { + bool have_real_osd = false; + for (int j=0; j < (int)size; j++) { o = rand() % osdmap.get_num_osds(); - if (osdmap.exists(o) && std::find(v.begin(), v.end(), o) == v.end()) + if (osdmap.exists(o) && std::find(v.begin(), v.end(), o) == v.end()) { + have_real_osd = true; v.push_back(o); + } } - if (v.size() < 3) { - for (vector::iterator q = p->second.acting.begin(); q != p->second.acting.end(); ++q) - if (std::find(v.begin(), v.end(), *q) == v.end()) - v.push_back(*q); + for (vector::iterator q = p->second.acting.begin(); + q != p->second.acting.end() && v.size() < size; + ++q) { + if (std::find(v.begin(), v.end(), *q) == v.end()) { + if (*q != CRUSH_ITEM_NONE) + have_real_osd = true; + v.push_back(*q); + } } - if (!v.empty()) + if (osdmap.pg_is_ec(p->first)) { + while (v.size() < size) + v.push_back(CRUSH_ITEM_NONE); + } + if (!v.empty() && have_real_osd) pending_inc.new_pg_temp[p->first] = v; dout(5) << "thrash_map pg " << p->first << " pg_temp remapped to " << v << dendl; diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 253e10d48a5..7fe4d5248de 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1555,10 +1555,10 @@ void OSDMap::_pg_to_up_acting_osds(pg_t pg, vector *up, int *up_primary, _raw_to_up_osds(*pool, raw, &_up, &_up_primary); _apply_primary_affinity(pps, *pool, &_up, &_up_primary); _get_temp_osds(*pool, pg, &_acting, &_acting_primary); - if (_acting.empty()) + if (_acting.empty()) { _acting = _up; - if (_acting_primary == -1) _acting_primary = _up_primary; + } if (up) up->swap(_up); if (up_primary)