From 0f6a36e1e4d24c87668de157d9360f466e83a32f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 26 Oct 2018 09:32:27 -0500 Subject: [PATCH] crushtool: make --reweight re-sum choose_args weight-sets too This ensures that the weights add us for each weight-set (and each position). Note that since we don't have anything that actually creates positional weight-sets, the behavior here might not be what we want in the end, but for the compat weight-sets (no position), we *do* keep the weights as a properly summing tree. Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 35 +++++++++++++++++++++++++++++++++++ src/crush/CrushWrapper.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index b378b422a38..265c57cf40f 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -2032,11 +2032,46 @@ void CrushWrapper::reweight(CephContext *cct) ldout(cct, 5) << "reweight root bucket " << id << dendl; int r = crush_reweight_bucket(crush, b); ceph_assert(r == 0); + + for (auto& i : choose_args) { + //cout << "carg " << i.first << std::endl; + vector w; // discard top-level weights + reweight_bucket(b, i.second, &w); + } } int r = rebuild_roots_with_classes(); ceph_assert(r == 0); } +void CrushWrapper::reweight_bucket( + crush_bucket *b, + crush_choose_arg_map& arg_map, + vector *weightv) +{ + int idx = -1 - b->id; + unsigned npos = arg_map.args[idx].weight_set_positions; + //cout << __func__ << " " << b->id << " npos " << npos << std::endl; + weightv->resize(npos); + for (unsigned i = 0; i < b->size; ++i) { + int item = b->items[i]; + if (item >= 0) { + for (unsigned pos = 0; pos < npos; ++pos) { + (*weightv)[pos] += arg_map.args[idx].weight_set->weights[i]; + } + } else { + vector subw(npos); + crush_bucket *sub = get_bucket(item); + assert(sub); + reweight_bucket(sub, arg_map, &subw); + for (unsigned pos = 0; pos < npos; ++pos) { + (*weightv)[pos] += subw[pos]; + // strash the real bucket weight as the weights for this reference + arg_map.args[idx].weight_set->weights[i] = subw[pos]; + } + } + } + //cout << __func__ << " finish " << b->id << " " << *weightv << std::endl; +} int CrushWrapper::add_simple_rule_at( string name, string root_name, diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index a0edf3e9af5..abe587f6098 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -963,6 +963,9 @@ public: return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000), loc); } void reweight(CephContext *cct); + void reweight_bucket(crush_bucket *b, + crush_choose_arg_map& arg_map, + vector *weightv); int adjust_subtree_weight(CephContext *cct, int id, int weight); int adjust_subtree_weightf(CephContext *cct, int id, float weight) { -- 2.39.5