From 9a7ed0b3f8df5bd74133f216bad61ae71eab0816 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 13 Jun 2013 14:01:01 -0700 Subject: [PATCH] mon: fix idempotency of 'osd crush add' 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 --- qa/workunits/mon/crush_ops.sh | 5 +++++ src/mon/OSDMonitor.cc | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/qa/workunits/mon/crush_ops.sh b/qa/workunits/mon/crush_ops.sh index 748d00bc3635a..4f66e5521531d 100755 --- a/qa/workunits/mon/crush_ops.sh +++ b/qa/workunits/mon/crush_ops.sh @@ -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 diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index bdfea6f7a909c..d785cf626c390 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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 { -- 2.39.5