Skip to content

Commit

Permalink
mon: fix idempotency of 'osd crush add'
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sage Weil committed Jun 13, 2013
1 parent 7e1cf87 commit 9a7ed0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions qa/workunits/mon/crush_ops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9a7ed0b

Please sign in to comment.