Skip to content

Commit

Permalink
Merge pull request ceph#557 from ceph/wip-5896
Browse files Browse the repository at this point in the history
mon: MonmapMonitor: make 'ceph mon add' idempotent

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Oct 4, 2013
2 parents de788bd + dce3d26 commit e9e6454
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/mon/MonmapMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit e9e6454

Please sign in to comment.