From 6fb760b572bde71ccb897900fedaf40e824de4d6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 16 Dec 2008 11:45:57 -0800 Subject: [PATCH] mon: clean up mdsmon a bit; do takeovers from tick(), not _committed() This puts all the takeover logic in one place. And avoids any funny issues where the monitor fails before it can do a takeover. More robust. --- src/mon/MDSMonitor.cc | 83 ++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 5c3320e17cec0..e0608f1598045 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -416,36 +416,6 @@ void MDSMonitor::_updated(int from, MMDSBeacon *m) void MDSMonitor::committed() { - // check for failed - set failed; - pending_mdsmap.get_failed_mds_set(failed); - - if (!pending_mdsmap.standby.empty() && !failed.empty()) { - bool didtakeover = false; - set::iterator p = failed.begin(); - while (p != failed.end()) { - int f = *p++; - - // someone standby for me? - if (pending_mdsmap.standby_for.count(f) && - !pending_mdsmap.standby_for[f].empty()) { - dout(0) << "mds" << f << " standby " << *pending_mdsmap.standby_for[f].begin() << " taking over" << dendl; - take_over(*pending_mdsmap.standby_for[f].begin(), f); - didtakeover = true; - } - else if (!pending_mdsmap.standby_any.empty()) { - dout(0) << "standby " << pending_mdsmap.standby.begin()->first << " taking over for mds" << f << dendl; - take_over(pending_mdsmap.standby.begin()->first, f); - didtakeover = true; - } - } - if (didtakeover) { - dout(7) << "pending map now:" << dendl; - print_map(pending_mdsmap); - propose_pending(); - } - } - // hackish: did all mds's shut down? if (mon->is_leader() && g_conf.mon_stop_with_last_mds && @@ -455,20 +425,6 @@ void MDSMonitor::committed() mon->monmap->get_inst(mon->whoami)); } -void MDSMonitor::take_over(entity_addr_t addr, int mds) -{ - pending_mdsmap.mds_inst[mds].addr = addr; - pending_mdsmap.mds_inst[mds].name = entity_name_t::MDS(mds); - pending_mdsmap.mds_inc[mds]++; - pending_mdsmap.mds_state[mds] = MDSMap::STATE_REPLAY; - pending_mdsmap.mds_state_seq[mds] = 0; - - // remove from standby list(s) - pending_mdsmap.standby.erase(addr); - pending_mdsmap.standby_for[mds].erase(addr); - pending_mdsmap.standby_any.erase(addr); -} - bool MDSMonitor::preprocess_command(MMonCommand *m) { @@ -768,10 +724,49 @@ void MDSMonitor::tick() } } + + // have a standby take over? + set failed; + pending_mdsmap.get_failed_mds_set(failed); + if (!pending_mdsmap.standby.empty() && !failed.empty()) { + set::iterator p = failed.begin(); + while (p != failed.end()) { + int f = *p++; + + // someone standby for me? + if (pending_mdsmap.standby_for.count(f) && + !pending_mdsmap.standby_for[f].empty()) { + dout(0) << "mds" << f << " standby " << *pending_mdsmap.standby_for[f].begin() << " taking over" << dendl; + take_over(*pending_mdsmap.standby_for[f].begin(), f); + do_propose = true; + } + else if (!pending_mdsmap.standby_any.empty()) { + dout(0) << "standby " << pending_mdsmap.standby.begin()->first << " taking over for mds" << f << dendl; + take_over(pending_mdsmap.standby.begin()->first, f); + do_propose = true; + } + } + } + + if (do_propose) propose_pending(); } +void MDSMonitor::take_over(entity_addr_t addr, int mds) +{ + dout(10) << "take_over mds" << mds << " by " << addr << dendl; + pending_mdsmap.mds_inst[mds].addr = addr; + pending_mdsmap.mds_inst[mds].name = entity_name_t::MDS(mds); + pending_mdsmap.mds_inc[mds]++; + pending_mdsmap.mds_state[mds] = MDSMap::STATE_REPLAY; + pending_mdsmap.mds_state_seq[mds] = 0; + + // remove from standby list(s) + pending_mdsmap.standby.erase(addr); + pending_mdsmap.standby_for[mds].erase(addr); + pending_mdsmap.standby_any.erase(addr); +} void MDSMonitor::do_stop() { -- 2.39.5