From: Sage Weil Date: Thu, 15 Nov 2018 22:28:34 +0000 (-0600) Subject: mgr/DaemonServer: use with_osdmap_and_pgmap instead of nested calls X-Git-Tag: v14.1.0~902^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e10cb8d2aefbc250f025cb0275698ddd1eb0a6aa;p=ceph.git mgr/DaemonServer: use with_osdmap_and_pgmap instead of nested calls Signed-off-by: Sage Weil --- diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 9e57125bb497..13ceb8941d04 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1048,21 +1048,19 @@ bool DaemonServer::_handle_command( for (auto osd : osds) { vector spgs; epoch_t epoch; - cluster_state.with_pgmap([&](const PGMap& pgmap) { - cluster_state.with_osdmap([&](const OSDMap& osdmap) { - epoch = osdmap.get_epoch(); - auto p = pgmap.pg_by_osd.find(osd); - if (p != pgmap.pg_by_osd.end()) { - for (auto pgid : p->second) { - int primary; - spg_t spg; - osdmap.get_primary_shard(pgid, &primary, &spg); - if (primary == osd) { - spgs.push_back(spg); - } - } + cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pgmap) { + epoch = osdmap.get_epoch(); + auto p = pgmap.pg_by_osd.find(osd); + if (p != pgmap.pg_by_osd.end()) { + for (auto pgid : p->second) { + int primary; + spg_t spg; + osdmap.get_primary_shard(pgid, &primary, &spg); + if (primary == osd) { + spgs.push_back(spg); } - }); + } + } }); auto p = osd_cons.find(osd); if (p == osd_cons.end()) { @@ -1144,18 +1142,16 @@ bool DaemonServer::_handle_command( cmd_getval(g_ceph_context, cmdctx->cmdmap, "no_increasing", no_increasing); string out_str; mempool::osdmap::map new_weights; - r = cluster_state.with_pgmap([&](const PGMap& pgmap) { - return cluster_state.with_osdmap([&](const OSDMap& osdmap) { - return reweight::by_utilization(osdmap, pgmap, - oload, - max_change, - max_osds, - by_pg, - pools.empty() ? NULL : &pools, - no_increasing, - &new_weights, - &ss, &out_str, f.get()); - }); + r = cluster_state.with_osdmap_and_pgmap([&](const OSDMap &osdmap, const PGMap& pgmap) { + return reweight::by_utilization(osdmap, pgmap, + oload, + max_change, + max_osds, + by_pg, + pools.empty() ? NULL : &pools, + no_increasing, + &new_weights, + &ss, &out_str, f.get()); }); if (r >= 0) { dout(10) << "reweight::by_utilization: finished with " << out_str << dendl; @@ -1195,14 +1191,12 @@ bool DaemonServer::_handle_command( } else if (prefix == "osd df") { string method; cmd_getval(g_ceph_context, cmdctx->cmdmap, "output_method", method); - r = cluster_state.with_pgmap([&](const PGMap& pgmap) { - return cluster_state.with_osdmap([&](const OSDMap& osdmap) { - print_osd_utilization(osdmap, pgmap, ss, - f.get(), method == "tree"); - - cmdctx->odata.append(ss); - return 0; - }); + r = cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pgmap) { + print_osd_utilization(osdmap, pgmap, ss, + f.get(), method == "tree"); + + cmdctx->odata.append(ss); + return 0; }); cmdctx->reply(r, ""); return true; @@ -1211,8 +1205,7 @@ bool DaemonServer::_handle_command( cmd_getval(g_ceph_context, cmdctx->cmdmap, "pool_name", pool_name); int64_t poolid = -ENOENT; bool one_pool = false; - r = cluster_state.with_pgmap([&](const PGMap& pg_map) { - return cluster_state.with_osdmap([&](const OSDMap& osdmap) { + r = cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pg_map) { if (!pool_name.empty()) { poolid = osdmap.lookup_pg_pool_name(pool_name); if (poolid < 0) { @@ -1249,7 +1242,6 @@ bool DaemonServer::_handle_command( } return 0; }); - }); if (r != -EOPNOTSUPP) { cmdctx->reply(r, ss); return true; @@ -1284,7 +1276,7 @@ bool DaemonServer::_handle_command( } set active_osds, missing_stats, stored_pgs, safe_to_destroy; int affected_pgs = 0; - cluster_state.with_pgmap([&](const PGMap& pg_map) { + cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pg_map) { if (pg_map.num_pg_unknown > 0) { ss << pg_map.num_pg_unknown << " pgs have unknown state; cannot draw" << " any conclusions"; @@ -1298,34 +1290,32 @@ bool DaemonServer::_handle_command( num_active_clean += p.second; } } - cluster_state.with_osdmap([&](const OSDMap& osdmap) { - for (auto osd : osds) { - if (!osdmap.exists(osd)) { - safe_to_destroy.insert(osd); - continue; // clearly safe to destroy - } - auto q = pg_map.num_pg_by_osd.find(osd); - if (q != pg_map.num_pg_by_osd.end()) { - if (q->second.acting > 0 || q->second.up > 0) { - active_osds.insert(osd); - affected_pgs += q->second.acting + q->second.up; - continue; - } - } - if (num_active_clean < pg_map.num_pg) { - // all pgs aren't active+clean; we need to be careful. - auto p = pg_map.osd_stat.find(osd); - if (p == pg_map.osd_stat.end()) { - missing_stats.insert(osd); - continue; - } else if (p->second.num_pgs > 0) { - stored_pgs.insert(osd); - continue; - } - } - safe_to_destroy.insert(osd); + for (auto osd : osds) { + if (!osdmap.exists(osd)) { + safe_to_destroy.insert(osd); + continue; // clearly safe to destroy + } + auto q = pg_map.num_pg_by_osd.find(osd); + if (q != pg_map.num_pg_by_osd.end()) { + if (q->second.acting > 0 || q->second.up > 0) { + active_osds.insert(osd); + affected_pgs += q->second.acting + q->second.up; + continue; } - }); + } + if (num_active_clean < pg_map.num_pg) { + // all pgs aren't active+clean; we need to be careful. + auto p = pg_map.osd_stat.find(osd); + if (p == pg_map.osd_stat.end()) { + missing_stats.insert(osd); + continue; + } else if (p->second.num_pgs > 0) { + stored_pgs.insert(osd); + continue; + } + } + safe_to_destroy.insert(osd); + } }); if (!r && (!active_osds.empty() || !missing_stats.empty() || !stored_pgs.empty())) { @@ -1405,48 +1395,46 @@ bool DaemonServer::_handle_command( } map pg_delta; // pgid -> net acting set size change int dangerous_pgs = 0; - cluster_state.with_pgmap([&](const PGMap& pg_map) { - return cluster_state.with_osdmap([&](const OSDMap& osdmap) { - if (pg_map.num_pg_unknown > 0) { - ss << pg_map.num_pg_unknown << " pgs have unknown state; " - << "cannot draw any conclusions"; - r = -EAGAIN; - return; - } - for (auto osd : osds) { - auto p = pg_map.pg_by_osd.find(osd); - if (p != pg_map.pg_by_osd.end()) { - for (auto& pgid : p->second) { - --pg_delta[pgid]; - } - } + cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pg_map) { + if (pg_map.num_pg_unknown > 0) { + ss << pg_map.num_pg_unknown << " pgs have unknown state; " + << "cannot draw any conclusions"; + r = -EAGAIN; + return; + } + for (auto osd : osds) { + auto p = pg_map.pg_by_osd.find(osd); + if (p != pg_map.pg_by_osd.end()) { + for (auto& pgid : p->second) { + --pg_delta[pgid]; } - for (auto& p : pg_delta) { - auto q = pg_map.pg_stat.find(p.first); - if (q == pg_map.pg_stat.end()) { - ss << "missing information about " << p.first << "; cannot draw" - << " any conclusions"; - r = -EAGAIN; - return; - } - if (!(q->second.state & PG_STATE_ACTIVE) || - (q->second.state & PG_STATE_DEGRADED)) { - // we don't currently have a good way to tell *how* degraded - // a degraded PG is, so we have to assume we cannot remove - // any more replicas/shards. - ++dangerous_pgs; - continue; - } - const pg_pool_t *pi = osdmap.get_pg_pool(p.first.pool()); - if (!pi) { - ++dangerous_pgs; // pool is creating or deleting - } else { - if (q->second.acting.size() + p.second < pi->min_size) { - ++dangerous_pgs; - } - } + } + } + for (auto& p : pg_delta) { + auto q = pg_map.pg_stat.find(p.first); + if (q == pg_map.pg_stat.end()) { + ss << "missing information about " << p.first << "; cannot draw" + << " any conclusions"; + r = -EAGAIN; + return; + } + if (!(q->second.state & PG_STATE_ACTIVE) || + (q->second.state & PG_STATE_DEGRADED)) { + // we don't currently have a good way to tell *how* degraded + // a degraded PG is, so we have to assume we cannot remove + // any more replicas/shards. + ++dangerous_pgs; + continue; + } + const pg_pool_t *pi = osdmap.get_pg_pool(p.first.pool()); + if (!pi) { + ++dangerous_pgs; // pool is creating or deleting + } else { + if (q->second.acting.size() + p.second < pi->min_size) { + ++dangerous_pgs; } - }); + } + } }); if (r) { cmdctx->reply(r, ss); @@ -2025,11 +2013,9 @@ bool DaemonServer::_handle_command( } // fall back to feeding command to PGMap - r = cluster_state.with_pgmap([&](const PGMap& pg_map) { - return cluster_state.with_osdmap([&](const OSDMap& osdmap) { - return process_pg_map_command(prefix, cmdctx->cmdmap, pg_map, osdmap, - f.get(), &ss, &cmdctx->odata); - }); + r = cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pg_map) { + return process_pg_map_command(prefix, cmdctx->cmdmap, pg_map, osdmap, + f.get(), &ss, &cmdctx->odata); }); if (f) { @@ -2253,7 +2239,7 @@ void DaemonServer::adjust_pgs() map pg_num_to_set; map pgp_num_to_set; set upmaps_to_clear; - cluster_state.with_pgmap([&](const PGMap& pg_map) { + cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, const PGMap& pg_map) { unsigned creating_or_unknown = 0; for (auto& i : pg_map.num_pg_by_state) { if ((i.first & (PG_STATE_CREATING)) || @@ -2285,232 +2271,230 @@ void DaemonServer::adjust_pgs() << "; target_max_misplaced_ratio " << max_misplaced << dendl; - cluster_state.with_osdmap([&](const OSDMap& osdmap) { - for (auto& i : osdmap.get_pools()) { - const pg_pool_t& p = i.second; + for (auto& i : osdmap.get_pools()) { + const pg_pool_t& p = i.second; - // adjust pg_num? - if (p.get_pg_num_target() != p.get_pg_num()) { - dout(20) << "pool " << i.first + // adjust pg_num? + if (p.get_pg_num_target() != p.get_pg_num()) { + dout(20) << "pool " << i.first + << " pg_num " << p.get_pg_num() + << " target " << p.get_pg_num_target() + << dendl; + if (p.has_flag(pg_pool_t::FLAG_CREATING)) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - still creating initial pgs" + << dendl; + } else if (p.get_pg_num_target() < p.get_pg_num()) { + // pg_num decrease (merge) + pg_t merge_source(p.get_pg_num() - 1, i.first); + pg_t merge_target = merge_source.get_parent(); + bool ok = true; + + if (osdmap.have_pg_upmaps(merge_target)) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() << " pg_num " << p.get_pg_num() - << " target " << p.get_pg_num_target() - << dendl; - if (p.has_flag(pg_pool_t::FLAG_CREATING)) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - still creating initial pgs" - << dendl; - } else if (p.get_pg_num_target() < p.get_pg_num()) { - // pg_num decrease (merge) - pg_t merge_source(p.get_pg_num() - 1, i.first); - pg_t merge_target = merge_source.get_parent(); - bool ok = true; - - if (osdmap.have_pg_upmaps(merge_target)) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge target " << merge_target - << " has upmap" << dendl; - upmaps_to_clear.insert(merge_target); - ok = false; - } else if (osdmap.have_pg_upmaps(merge_source)) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge source " << merge_source - << " has upmap" << dendl; - upmaps_to_clear.insert(merge_source); - ok = false; - } + << " - merge target " << merge_target + << " has upmap" << dendl; + upmaps_to_clear.insert(merge_target); + ok = false; + } else if (osdmap.have_pg_upmaps(merge_source)) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - merge source " << merge_source + << " has upmap" << dendl; + upmaps_to_clear.insert(merge_source); + ok = false; + } - auto q = pg_map.pg_stat.find(merge_source); - if (p.get_pg_num() != p.get_pg_num_pending()) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - decrease and pg_num_pending != pg_num, waiting" - << dendl; - ok = false; - } else if (p.get_pg_num() == p.get_pgp_num()) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - decrease blocked by pgp_num " - << p.get_pgp_num() - << dendl; - ok = false; - } else if (q == pg_map.pg_stat.end()) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - no state for " << merge_source - << " (merge source)" - << dendl; - ok = false; - } else if (!(q->second.state & (PG_STATE_ACTIVE | - PG_STATE_CLEAN))) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge source " << merge_source - << " not clean (" << pg_state_string(q->second.state) - << ")" << dendl; - ok = false; - } else if (q->second.state & PG_STATE_REMAPPED) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge source " << merge_source - << " remapped" << dendl; - ok = false; - } + auto q = pg_map.pg_stat.find(merge_source); + if (p.get_pg_num() != p.get_pg_num_pending()) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - decrease and pg_num_pending != pg_num, waiting" + << dendl; + ok = false; + } else if (p.get_pg_num() == p.get_pgp_num()) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - decrease blocked by pgp_num " + << p.get_pgp_num() + << dendl; + ok = false; + } else if (q == pg_map.pg_stat.end()) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - no state for " << merge_source + << " (merge source)" + << dendl; + ok = false; + } else if (!(q->second.state & (PG_STATE_ACTIVE | + PG_STATE_CLEAN))) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - merge source " << merge_source + << " not clean (" << pg_state_string(q->second.state) + << ")" << dendl; + ok = false; + } else if (q->second.state & PG_STATE_REMAPPED) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - merge source " << merge_source + << " remapped" << dendl; + ok = false; + } - q = pg_map.pg_stat.find(merge_target); - if (q == pg_map.pg_stat.end()) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - no state for " << merge_target - << " (merge target)" + q = pg_map.pg_stat.find(merge_target); + if (q == pg_map.pg_stat.end()) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - no state for " << merge_target + << " (merge target)" + << dendl; + ok = false; + } else if (!(q->second.state & (PG_STATE_ACTIVE | + PG_STATE_CLEAN))) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - merge target " << merge_target + << " not clean (" << pg_state_string(q->second.state) + << ")" << dendl; + ok = false; + } else if (q->second.state & PG_STATE_REMAPPED) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - merge target " << merge_target + << " remapped" << dendl; + ok = false; + } + if (ok) { + unsigned target = p.get_pg_num() - 1; + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " -> " << target + << " (merging " << merge_source + << " and " << merge_target + << ")" << dendl; + pg_num_to_set[osdmap.get_pool_name(i.first)] = target; + } + } else if (p.get_pg_num_target() > p.get_pg_num()) { + // pg_num increase (split) + bool active = true; + auto q = pg_map.num_pg_by_pool_state.find(i.first); + if (q != pg_map.num_pg_by_pool_state.end()) { + for (auto& j : q->second) { + if ((j.first & (PG_STATE_ACTIVE|PG_STATE_PEERED)) == 0) { + dout(20) << "pool " << i.first << " has " << j.second + << " pgs in " << pg_state_string(j.first) << dendl; - ok = false; - } else if (!(q->second.state & (PG_STATE_ACTIVE | - PG_STATE_CLEAN))) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge target " << merge_target - << " not clean (" << pg_state_string(q->second.state) - << ")" << dendl; - ok = false; - } else if (q->second.state & PG_STATE_REMAPPED) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - merge target " << merge_target - << " remapped" << dendl; - ok = false; - } - if (ok) { - unsigned target = p.get_pg_num() - 1; - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " -> " << target - << " (merging " << merge_source - << " and " << merge_target - << ")" << dendl; - pg_num_to_set[osdmap.get_pool_name(i.first)] = target; - } - } else if (p.get_pg_num_target() > p.get_pg_num()) { - // pg_num increase (split) - bool active = true; - auto q = pg_map.num_pg_by_pool_state.find(i.first); - if (q != pg_map.num_pg_by_pool_state.end()) { - for (auto& j : q->second) { - if ((j.first & (PG_STATE_ACTIVE|PG_STATE_PEERED)) == 0) { - dout(20) << "pool " << i.first << " has " << j.second - << " pgs in " << pg_state_string(j.first) - << dendl; - active = false; - break; - } - } - } else { active = false; - } - if (!active) { - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " - not all pgs active" - << dendl; - } else { - unsigned add = std::min( - left, - p.get_pg_num_target() - p.get_pg_num()); - unsigned target = p.get_pg_num() + add; - left -= add; - dout(10) << "pool " << i.first - << " pg_num_target " << p.get_pg_num_target() - << " pg_num " << p.get_pg_num() - << " -> " << target << dendl; - pg_num_to_set[osdmap.get_pool_name(i.first)] = target; + break; } } + } else { + active = false; } - - // adjust pgp_num? - unsigned target = std::min(p.get_pg_num_pending(), - p.get_pgp_num_target()); - if (target != p.get_pgp_num()) { - dout(20) << "pool " << i.first - << " pgp_num_target " << p.get_pgp_num_target() - << " pgp_num " << p.get_pgp_num() + if (!active) { + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() + << " - not all pgs active" + << dendl; + } else { + unsigned add = std::min( + left, + p.get_pg_num_target() - p.get_pg_num()); + unsigned target = p.get_pg_num() + add; + left -= add; + dout(10) << "pool " << i.first + << " pg_num_target " << p.get_pg_num_target() + << " pg_num " << p.get_pg_num() << " -> " << target << dendl; - if (target > p.get_pgp_num() && - p.get_pgp_num() == p.get_pg_num()) { - dout(10) << "pool " << i.first - << " pgp_num_target " << p.get_pgp_num_target() - << " pgp_num " << p.get_pgp_num() - << " - increase blocked by pg_num " << p.get_pg_num() - << dendl; - } else if (!aggro && (inactive_pgs_ratio > 0 || - degraded_ratio > 0 || - unknown_pgs_ratio > 0)) { - dout(10) << "pool " << i.first - << " pgp_num_target " << p.get_pgp_num_target() - << " pgp_num " << p.get_pgp_num() - << " - inactive|degraded|unknown pgs, deferring pgp_num" - << " update" << dendl; - } else if (!aggro && (misplaced_ratio > max_misplaced)) { - dout(10) << "pool " << i.first - << " pgp_num_target " << p.get_pgp_num_target() - << " pgp_num " << p.get_pgp_num() - << " - misplaced_ratio " << misplaced_ratio - << " > max " << max_misplaced - << ", deferring pgp_num update" << dendl; + pg_num_to_set[osdmap.get_pool_name(i.first)] = target; + } + } + } + + // adjust pgp_num? + unsigned target = std::min(p.get_pg_num_pending(), + p.get_pgp_num_target()); + if (target != p.get_pgp_num()) { + dout(20) << "pool " << i.first + << " pgp_num_target " << p.get_pgp_num_target() + << " pgp_num " << p.get_pgp_num() + << " -> " << target << dendl; + if (target > p.get_pgp_num() && + p.get_pgp_num() == p.get_pg_num()) { + dout(10) << "pool " << i.first + << " pgp_num_target " << p.get_pgp_num_target() + << " pgp_num " << p.get_pgp_num() + << " - increase blocked by pg_num " << p.get_pg_num() + << dendl; + } else if (!aggro && (inactive_pgs_ratio > 0 || + degraded_ratio > 0 || + unknown_pgs_ratio > 0)) { + dout(10) << "pool " << i.first + << " pgp_num_target " << p.get_pgp_num_target() + << " pgp_num " << p.get_pgp_num() + << " - inactive|degraded|unknown pgs, deferring pgp_num" + << " update" << dendl; + } else if (!aggro && (misplaced_ratio > max_misplaced)) { + dout(10) << "pool " << i.first + << " pgp_num_target " << p.get_pgp_num_target() + << " pgp_num " << p.get_pgp_num() + << " - misplaced_ratio " << misplaced_ratio + << " > max " << max_misplaced + << ", deferring pgp_num update" << dendl; + } else { + // NOTE: this calculation assumes objects are + // basically uniformly distributed across all PGs + // (regardless of pool), which is probably not + // perfectly correct, but it's a start. make no + // single adjustment that's more than half of the + // max_misplaced, to somewhat limit the magnitude of + // our potential error here. + int next; + if (aggro) { + next = target; + } else { + double room = + std::min(max_misplaced - misplaced_ratio, + misplaced_ratio / 2.0); + unsigned estmax = std::max( + (double)p.get_pg_num() * room, 1u); + int delta = target - p.get_pgp_num(); + next = p.get_pgp_num(); + if (delta < 0) { + next += std::max(-estmax, delta); } else { - // NOTE: this calculation assumes objects are - // basically uniformly distributed across all PGs - // (regardless of pool), which is probably not - // perfectly correct, but it's a start. make no - // single adjustment that's more than half of the - // max_misplaced, to somewhat limit the magnitude of - // our potential error here. - int next; - if (aggro) { - next = target; - } else { - double room = - std::min(max_misplaced - misplaced_ratio, - misplaced_ratio / 2.0); - unsigned estmax = std::max( - (double)p.get_pg_num() * room, 1u); - int delta = target - p.get_pgp_num(); - next = p.get_pgp_num(); - if (delta < 0) { - next += std::max(-estmax, delta); - } else { - next += std::min(estmax, delta); - } - dout(20) << " room " << room << " estmax " << estmax - << " delta " << delta << " next " << next << dendl; - } - dout(10) << "pool " << i.first - << " pgp_num_target " << p.get_pgp_num_target() - << " pgp_num " << p.get_pgp_num() - << " -> " << next << dendl; - pgp_num_to_set[osdmap.get_pool_name(i.first)] = next; + next += std::min(estmax, delta); } + dout(20) << " room " << room << " estmax " << estmax + << " delta " << delta << " next " << next << dendl; } - if (left == 0) { - return; - } + dout(10) << "pool " << i.first + << " pgp_num_target " << p.get_pgp_num_target() + << " pgp_num " << p.get_pgp_num() + << " -> " << next << dendl; + pgp_num_to_set[osdmap.get_pool_name(i.first)] = next; } - }); + } + if (left == 0) { + return; + } + } }); for (auto i : pg_num_to_set) { const string cmd =