diff options
author | Sage Weil <sage@inktank.com> | 2013-10-03 18:27:58 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-10-03 18:27:58 -0700 |
commit | e9e64545d5300364e4775ec68b4a6b9ca76b505b (patch) | |
tree | e5891fda22f1d1164c113ef99c54b04dafc92e5c | |
parent | de788bd687adf041203d469b0fceb4b2e8cb5b4f (diff) | |
parent | dce3d26d84f140d01a968dc0a615372c1cb8f7f3 (diff) | |
download | ceph-e9e64545d5300364e4775ec68b4a6b9ca76b505b.tar.gz |
Merge pull request #557 from ceph/wip-5896
mon: MonmapMonitor: make 'ceph mon add' idempotent
Reviewed-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | src/mon/MonmapMonitor.cc | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 799f19df154..ca855592445 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -298,20 +298,45 @@ bool MonmapMonitor::prepare_command(MMonCommand *m) addr.set_port(CEPH_MON_PORT); } - if (pending_map.contains(addr) || - pending_map.contains(name)) { + /** + * If we have a monitor with the same name and different addr, then EEXIST + * If we have a monitor with the same addr and different name, then EEXIST + * If we have a monitor with the same addr and same name, then return as if + * we had just added the monitor. + * If we don't have the monitor, add it. + */ + + err = 0; + if (!ss.str().empty()) + ss << "; "; + + do { + if (pending_map.contains(addr)) { + string n = pending_map.get_name(addr); + if (n == name) + break; + } else if (pending_map.contains(name)) { + entity_addr_t tmp_addr = pending_map.get_addr(name); + if (tmp_addr == addr) + break; + } else { + break; + } err = -EEXIST; - if (!ss.str().empty()) - ss << "; "; - ss << "mon " << name << " " << addr << " already exists"; + ss << "mon." << name << " at " << addr << " already exists"; + goto out; + } while (false); + + ss << "added mon." << name << " at " << addr; + if (pending_map.contains(name)) { goto out; } pending_map.add(name, addr); pending_map.last_changed = ceph_clock_now(g_ceph_context); - ss << "added mon." << name << " at " << addr; getline(ss, rs); - wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_last_committed())); + wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, + get_last_committed())); return true; } else if (prefix == "mon remove") { |