]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: create weight-set on demand when doing a choose-args reweight
authorSage Weil <sage@redhat.com>
Fri, 18 May 2018 22:10:14 +0000 (17:10 -0500)
committerSage Weil <sage@redhat.com>
Fri, 18 May 2018 22:12:22 +0000 (17:12 -0500)
If we try to reweight an item in a choose-args set for a given item
but the bucket doesn't have a weight_set yet, create it on the fly, and
populate it with the canonical bucket weights.

Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushWrapper.cc

index 6fde997e07f003e1afe94df6219a64b97e4ecb93..b3cc3c0fc1362d23816414802942f2f3c6c785db 100644 (file)
@@ -3437,11 +3437,20 @@ int CrushWrapper::_choose_args_adjust_item_weight_in_bucket(
   }
   crush_choose_arg *carg = &cmap.args[bidx];
   if (carg->weight_set == NULL) {
-    if (ss)
-      *ss << "no weight-set for bucket " << b->id;
-    ldout(cct, 10) << __func__ << "  no weight_set for bucket " << b->id
-                  << dendl;
-    return 0;
+    // create a weight-set for this bucket and populate it with the
+    // bucket weights
+    unsigned positions = get_choose_args_positions(cmap);
+    carg->weight_set_positions = positions;
+    carg->weight_set = static_cast<crush_weight_set*>(
+      calloc(sizeof(crush_weight_set), positions));
+    for (unsigned p = 0; p < positions; ++p) {
+      carg->weight_set[p].size = b->size;
+      carg->weight_set[p].weights = (__u32*)calloc(b->size, sizeof(__u32));
+      for (unsigned i = 0; i < b->size; ++i) {
+       carg->weight_set[p].weights[i] = crush_get_bucket_item_weight(b, i);
+      }
+    }
+    changed++;
   }
   if (carg->weight_set_positions != weight.size()) {
     if (ss)