]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: add update_weight_sets arg to adjust_item_weight_*
authorSage Weil <sage@redhat.com>
Thu, 14 Mar 2019 16:29:10 +0000 (11:29 -0500)
committerSage Weil <sage@redhat.com>
Fri, 22 Mar 2019 10:01:55 +0000 (05:01 -0500)
- Make it optional whether the weight-set weights are adjusted to
  match the weight.

- Fix the adjustment of the parent bucket(s) so that the
  summations in weight-sets are correctly maintained.  Prior to
  this change, if I adjust any weight, all parent buckets'
  weight-set weights are reset to the bucket's primary weight.

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit d2f1440d7ae4635eaff8c75d38db454ab55f9d22)

src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 81470ac0140e4bac6075aff5671218fe35aa6139..6af6084207c6b6391f9ff56f0bbac4b25b2ff246 100644 (file)
@@ -1441,15 +1441,19 @@ int CrushWrapper::get_item_weight_in_loc(int id, const map<string,string> &loc)
   return -ENOENT;
 }
 
-int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
+int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight,
+                                    bool update_weight_sets)
 {
-  ldout(cct, 5) << __func__ << " " << id << " weight " << weight << dendl;
+  ldout(cct, 5) << __func__ << " " << id << " weight " << weight
+               << " update_weight_sets=" << (int)update_weight_sets
+               << dendl;
   int changed = 0;
   for (int bidx = 0; bidx < crush->max_buckets; bidx++) {
     if (!crush->buckets[bidx]) {
       continue;
     }
-    int r = adjust_item_weight_in_bucket(cct, id, weight, -1-bidx);
+    int r = adjust_item_weight_in_bucket(cct, id, weight, -1-bidx,
+                                        update_weight_sets);
     if (r > 0) {
       ++changed;
     }
@@ -1462,10 +1466,12 @@ int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
 
 int CrushWrapper::adjust_item_weight_in_bucket(
   CephContext *cct, int id, int weight,
-  int bucket_id)
+  int bucket_id,
+  bool update_weight_sets)
 {
   ldout(cct, 5) << __func__ << " " << id << " weight " << weight
                << " in bucket " << bucket_id
+               << " update_weight_sets=" << (int)update_weight_sets
                << dendl;
   int changed = 0;
   if (!bucket_exists(bucket_id)) {
@@ -1474,13 +1480,37 @@ int CrushWrapper::adjust_item_weight_in_bucket(
   crush_bucket *b = get_bucket(bucket_id);
   for (unsigned int i = 0; i < b->size; i++) {
     if (b->items[i] == id) {
-      int diff = bucket_adjust_item_weight(cct, b, id, weight);
+      int diff = bucket_adjust_item_weight(cct, b, id, weight,
+                                          update_weight_sets);
       ldout(cct, 5) << __func__ << " " << id << " diff " << diff
                    << " in bucket " << bucket_id << dendl;
-      adjust_item_weight(cct, bucket_id, b->weight);
+      adjust_item_weight(cct, bucket_id, b->weight, false);
       changed++;
     }
   }
+  // update weight-sets so they continue to sum
+  for (auto& p : choose_args) {
+    auto &cmap = p.second;
+    if (!cmap.args) {
+      continue;
+    }
+    crush_choose_arg *arg = &cmap.args[-1 - bucket_id];
+    if (!arg->weight_set) {
+      continue;
+    }
+    ceph_assert(arg->weight_set_positions > 0);
+    vector<int> w(arg->weight_set_positions);
+    for (unsigned i = 0; i < b->size; ++i) {
+      for (unsigned j = 0; j < arg->weight_set_positions; ++j) {
+       crush_weight_set *weight_set = &arg->weight_set[j];
+       w[j] += weight_set->weights[i];
+      }
+    }
+    ldout(cct,5) << __func__ << "  adjusting bucket " << bucket_id
+                << " cmap " << p.first << " weights to " << w << dendl;
+    ostringstream ss;
+    choose_args_adjust_item_weight(cct, cmap, bucket_id, w, &ss);
+  }
   if (!changed) {
     return -ENOENT;
   }
@@ -1489,16 +1519,20 @@ int CrushWrapper::adjust_item_weight_in_bucket(
 
 int CrushWrapper::adjust_item_weight_in_loc(
   CephContext *cct, int id, int weight,
-  const map<string,string>& loc)
+  const map<string,string>& loc,
+  bool update_weight_sets)
 {
   ldout(cct, 5) << "adjust_item_weight_in_loc " << id << " weight " << weight
-               << " in " << loc << dendl;
+               << " in " << loc
+               << " update_weight_sets=" << (int)update_weight_sets
+               << dendl;
   int changed = 0;
   for (auto l = loc.begin(); l != loc.end(); ++l) {
     int bid = get_item_id(l->second);
     if (!bucket_exists(bid))
       continue;
-    int r = adjust_item_weight_in_bucket(cct, id, weight, bid);
+    int r = adjust_item_weight_in_bucket(cct, id, weight, bid,
+                                        update_weight_sets);
     if (r > 0) {
       ++changed;
     }
@@ -2391,9 +2425,11 @@ int CrushWrapper::remove_rule(int ruleno)
   return rebuild_roots_with_classes(nullptr);
 }
 
-int CrushWrapper::bucket_adjust_item_weight(CephContext *cct, crush_bucket *bucket, int item, int weight)
+int CrushWrapper::bucket_adjust_item_weight(
+  CephContext *cct, crush_bucket *bucket, int item, int weight,
+  bool adjust_weight_sets)
 {
-  if (cct->_conf->osd_crush_update_weight_set) {
+  if (adjust_weight_sets) {
     unsigned position;
     for (position = 0; position < bucket->size; position++)
       if (bucket->items[position] == item)
index e3668729def250f80f1d3872d33f6fe321ba04bf..9cd19e96397f720688e736aff31bcb781ee09b63 100644 (file)
@@ -956,25 +956,32 @@ public:
     }
     return 0;
   }
-  int adjust_item_weight(CephContext *cct, int id, int weight);
-  int adjust_item_weightf(CephContext *cct, int id, float weight) {
+  int adjust_item_weight(CephContext *cct, int id, int weight,
+                        bool update_weight_sets=true);
+  int adjust_item_weightf(CephContext *cct, int id, float weight,
+                         bool update_weight_sets=true) {
     int r = validate_weightf(weight);
     if (r < 0) {
       return r;
     }
-    return adjust_item_weight(cct, id, (int)(weight * (float)0x10000));
+    return adjust_item_weight(cct, id, (int)(weight * (float)0x10000),
+                             update_weight_sets);
   }
-  int adjust_item_weight_in_bucket(
-    CephContext *cct, int id, int weight, int bucket_id);
+  int adjust_item_weight_in_bucket(CephContext *cct, int id, int weight,
+                                  int bucket_id,
+                                  bool update_weight_sets);
   int adjust_item_weight_in_loc(CephContext *cct, int id, int weight,
-                               const map<string,string>& loc);
+                               const map<string,string>& loc,
+                               bool update_weight_sets=true);
   int adjust_item_weightf_in_loc(CephContext *cct, int id, float weight,
-                                const map<string,string>& loc) {
+                                const map<string,string>& loc,
+                                bool update_weight_sets=true) {
     int r = validate_weightf(weight);
     if (r < 0) {
       return r;
     }
-    return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000), loc);
+    return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000),
+                                    loc, update_weight_sets);
   }
   void reweight(CephContext *cct);
   void reweight_bucket(crush_bucket *b,
@@ -1288,7 +1295,9 @@ public:
                 int *items, int *weights, int *idout);
   int bucket_add_item(crush_bucket *bucket, int item, int weight);
   int bucket_remove_item(struct crush_bucket *bucket, int item);
-  int bucket_adjust_item_weight(CephContext *cct, struct crush_bucket *bucket, int item, int weight);
+  int bucket_adjust_item_weight(
+    CephContext *cct, struct crush_bucket *bucket, int item, int weight,
+    bool adjust_weight_sets);
 
   void finalize() {
     ceph_assert(crush);