From: Sage Weil Date: Mon, 21 May 2018 18:24:25 +0000 (-0500) Subject: crush: fix device_class_clone for unpopulated/empty weight-sets X-Git-Tag: v14.0.0~42^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F22127%2Fhead;p=ceph.git crush: fix device_class_clone for unpopulated/empty weight-sets If the bucket is empty or does not have weight-set weights yet, avoid crashing when populating the parent bucket. Fixes: http://tracker.ceph.com/issues/23386 Signed-off-by: Sage Weil --- diff --git a/qa/workunits/mon/crush_ops.sh b/qa/workunits/mon/crush_ops.sh index 6c13b69908125..aa287c79ce3a5 100755 --- a/qa/workunits/mon/crush_ops.sh +++ b/qa/workunits/mon/crush_ops.sh @@ -213,4 +213,15 @@ ceph osd pool rm cool cool --yes-i-really-really-mean-it ceph osd pool rm cold cold --yes-i-really-really-mean-it ceph osd crush weight-set rm-compat +# weight set vs device classes vs move +ceph osd crush weight-set create-compat +ceph osd crush add-bucket fooo host +ceph osd crush move fooo root=default +ceph osd crush add-bucket barr rack +ceph osd crush move barr root=default +ceph osd crush move fooo rack=barr +ceph osd crush rm fooo +ceph osd crush rm barr +ceph osd crush weight-set rm-compat + echo OK diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 5b5d21a2ec56b..c5be83571371f 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1573,7 +1573,7 @@ int CrushWrapper::populate_classes( // accumulate weight values for each carg and bucket as we go. because it is // depth first, we will have the nested bucket weights we need when we // finish constructing the containing buckets. - map>> cmap_item_weight; // cargs -> bno -> weights + map>> cmap_item_weight; // cargs -> bno -> [bucket weight for each position] set roots; find_nonshadow_roots(&roots); for (auto &r : roots) { @@ -2182,8 +2182,10 @@ int CrushWrapper::device_class_clone( int item = copy->items[i]; if (item >= 0) { n.weight_set[s].weights[i] = o.weight_set[s].weights[item_orig_pos[i]]; - } else { + } else if ((*cmap_item_weight)[w.first].count(item)) { n.weight_set[s].weights[i] = (*cmap_item_weight)[w.first][item][s]; + } else { + n.weight_set[s].weights[i] = 0; } bucket_weights[s] += n.weight_set[s].weights[i]; }