]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: fix idempotency of 'osd crush add'
authorSage Weil <sage@inktank.com>
Thu, 13 Jun 2013 21:01:01 +0000 (14:01 -0700)
committerSage Weil <sage@inktank.com>
Thu, 13 Jun 2013 21:42:05 +0000 (14:42 -0700)
If we add an item that already exists in particular position, we should
update instead of inserting it; the CrushWrapper methods are not
idempotent.

Signed-off-by: Sage Weil <sage@inktank.com>
qa/workunits/mon/crush_ops.sh
src/mon/OSDMonitor.cc

index 748d00bc3635a472fa7be431d3901799465494fb..4f66e5521531daa2bd1bbb2634bdfda82a35ce94 100755 (executable)
@@ -27,10 +27,15 @@ ceph osd crush add-bucket foo root
 o1=`ceph osd create`
 o2=`ceph osd create`
 ceph osd crush add $o1 1 host=host1 root=foo
+ceph osd crush add $o1 1 host=host1 root=foo  # idemptoent
 ceph osd crush add $o2 1 host=host2 root=foo
+ceph osd crush add $o2 1 host=host2 root=foo  # idempotent
 ceph osd crush add-bucket bar root
+ceph osd crush add-bucket bar root  # idempotent
 ceph osd crush link host1 root=bar
+ceph osd crush link host1 root=bar  # idempotent
 ceph osd crush link host2 root=bar
+ceph osd crush link host2 root=bar  # idempotent
 
 ceph osd tree | grep -c osd.$o1 | grep -q 2
 ceph osd tree | grep -c host1 | grep -q 2
index bdfea6f7a909ccb2cf708233546ae02408949b0c..d785cf626c39062e7665589a17b945dacc942e33 100644 (file)
@@ -2579,7 +2579,8 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       _get_pending_crush(newcrush);
 
       string action;
-      if (prefix == "osd crush set") {
+      if (prefix == "osd crush set" ||
+         newcrush.check_item_loc(g_ceph_context, id, loc, (int *)NULL)) {
        action = "set";
        err = newcrush.update_item(g_ceph_context, id, weight, name, loc);
       } else {