From 7de63e074ba7aacee966a2d2e81e0aafa16b307b Mon Sep 17 00:00:00 2001 From: sageweil Date: Sun, 9 Sep 2007 23:47:09 +0000 Subject: [PATCH] standby mds do automatic takeover git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1805 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/mds/MDS.cc | 11 +++----- trunk/ceph/mon/ClientMonitor.cc | 4 +++ trunk/ceph/mon/ClientMonitor.h | 2 ++ trunk/ceph/mon/MDSMonitor.cc | 47 ++++++++++++++++++++++++++++++--- trunk/ceph/mon/MDSMonitor.h | 2 ++ trunk/ceph/mon/OSDMonitor.cc | 6 +++++ trunk/ceph/mon/OSDMonitor.h | 2 ++ trunk/ceph/mon/PGMonitor.cc | 4 +++ trunk/ceph/mon/PGMonitor.h | 2 ++ trunk/ceph/mon/PaxosService.cc | 2 ++ trunk/ceph/mon/PaxosService.h | 2 ++ 11 files changed, 74 insertions(+), 10 deletions(-) diff --git a/trunk/ceph/mds/MDS.cc b/trunk/ceph/mds/MDS.cc index 7cc566bfbb2d4..c34415d51f232 100644 --- a/trunk/ceph/mds/MDS.cc +++ b/trunk/ceph/mds/MDS.cc @@ -529,6 +529,7 @@ void MDS::handle_mds_map(MMDSMap *m) dout(1) << "handle_mds_map i am now mds" << whoami << " incarnation " << mdsmap->get_inc(whoami) << dendl; + messenger->reset_myname(entity_name_t::MDS(whoami)); // do i need an osdmap? if (oldwhoami < 0) { @@ -565,13 +566,6 @@ void MDS::handle_mds_map(MMDSMap *m) want_state = state; } - // contemplate suicide - if (mdsmap->get_inst(whoami) != messenger->get_myinst()) { - dout(1) << "apparently i've been replaced by " << mdsmap->get_inst(whoami) << ", committing suicide." << dendl; - suicide(); - return; - } - // now active? if (is_active()) { // did i just recover? @@ -896,6 +890,9 @@ void MDS::replay_start() // note: don't actually start yet. boot() will get called once we have // an mdsmap AND osdmap. + if (osdmap->get_epoch() > 0 && + mdsmap->get_epoch() > 0) + boot_replay(); } void MDS::replay_done() diff --git a/trunk/ceph/mon/ClientMonitor.cc b/trunk/ceph/mon/ClientMonitor.cc index 329548c0091e8..ebc204507d034 100644 --- a/trunk/ceph/mon/ClientMonitor.cc +++ b/trunk/ceph/mon/ClientMonitor.cc @@ -99,6 +99,10 @@ void ClientMonitor::create_initial() dout(1) << "create_initial -- creating initial map" << dendl; } +void ClientMonitor::committed() +{ + +} void ClientMonitor::encode_pending(bufferlist &bl) diff --git a/trunk/ceph/mon/ClientMonitor.h b/trunk/ceph/mon/ClientMonitor.h index 33fc7dff57a60..f36ee9f7c18bd 100644 --- a/trunk/ceph/mon/ClientMonitor.h +++ b/trunk/ceph/mon/ClientMonitor.h @@ -159,6 +159,8 @@ private: void create_pending(); // prepare a new pending void encode_pending(bufferlist &bl); // propose pending update to peers + void committed(); + void _mounted(int c, MClientMount *m); void _unmounted(MClientUnmount *m); diff --git a/trunk/ceph/mon/MDSMonitor.cc b/trunk/ceph/mon/MDSMonitor.cc index 45f01a4ebc0b9..e8afa3bdd7007 100644 --- a/trunk/ceph/mon/MDSMonitor.cc +++ b/trunk/ceph/mon/MDSMonitor.cc @@ -376,6 +376,50 @@ void MDSMonitor::_updated(int from, MMDSBeacon *m) send_latest(m->get_mds_inst()); } + delete m; +} + + +void MDSMonitor::committed() +{ + // check for failed + set standby; + set failed; + mdsmap.get_mds_set(standby, MDSMap::STATE_STANDBY); + mdsmap.get_failed_mds_set(failed); + + if (!standby.empty() && !failed.empty()) { + while (!standby.empty() && !failed.empty()) { + int f = *failed.begin(); + int t = *standby.begin(); + failed.erase(failed.begin()); + standby.erase(standby.begin()); + + dout(0) << "mds" << t << " taking over for mds" << f << dendl; + + // send new map to old inst/name + waiting_for_map.push_back(mdsmap.mds_inst[t]); + + pending_mdsmap.mds_inst[f] = mdsmap.mds_inst[t]; + pending_mdsmap.mds_inst[f].name = entity_name_t::MDS(f); + pending_mdsmap.mds_inc[f]++; + pending_mdsmap.mds_state[f] = MDSMap::STATE_REPLAY; + pending_mdsmap.mds_state_seq[f] = mdsmap.mds_state_seq[t]; + + pending_mdsmap.mds_inst.erase(t); + pending_mdsmap.mds_state.erase(t); + pending_mdsmap.mds_state_seq.erase(t); + + last_beacon[f] = last_beacon[t]; + last_beacon.erase(t); + } + + 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 && @@ -383,12 +427,9 @@ void MDSMonitor::_updated(int from, MMDSBeacon *m) mdsmap.is_stopped()) mon->messenger->send_message(new MGenericMessage(MSG_SHUTDOWN), mon->monmap->get_inst(mon->whoami)); - - delete m; } - bool MDSMonitor::handle_command(MMonCommand *m) { int r = -EINVAL; diff --git a/trunk/ceph/mon/MDSMonitor.h b/trunk/ceph/mon/MDSMonitor.h index b25801064aefa..c398a64ee9d9a 100644 --- a/trunk/ceph/mon/MDSMonitor.h +++ b/trunk/ceph/mon/MDSMonitor.h @@ -66,6 +66,8 @@ class MDSMonitor : public PaxosService { bool preprocess_query(Message *m); // true if processed. bool prepare_update(Message *m); + void committed(); + bool preprocess_beacon(class MMDSBeacon *m); bool handle_beacon(class MMDSBeacon *m); bool handle_command(class MMonCommand *m); diff --git a/trunk/ceph/mon/OSDMonitor.cc b/trunk/ceph/mon/OSDMonitor.cc index 6c9dcb3c9655d..df6f4a77ae276 100644 --- a/trunk/ceph/mon/OSDMonitor.cc +++ b/trunk/ceph/mon/OSDMonitor.cc @@ -342,6 +342,12 @@ void OSDMonitor::encode_pending(bufferlist &bl) } +void OSDMonitor::committed() +{ + +} + + // ------------- bool OSDMonitor::preprocess_query(Message *m) diff --git a/trunk/ceph/mon/OSDMonitor.h b/trunk/ceph/mon/OSDMonitor.h index f1e9470d901d4..8db58dc328052 100644 --- a/trunk/ceph/mon/OSDMonitor.h +++ b/trunk/ceph/mon/OSDMonitor.h @@ -47,6 +47,8 @@ private: void create_pending(); // prepare a new pending void encode_pending(bufferlist &bl); + void committed(); + void handle_query(Message *m); bool preprocess_query(Message *m); // true if processed. bool prepare_update(Message *m); diff --git a/trunk/ceph/mon/PGMonitor.cc b/trunk/ceph/mon/PGMonitor.cc index a87dbd49d3ee1..6e571fea7f612 100644 --- a/trunk/ceph/mon/PGMonitor.cc +++ b/trunk/ceph/mon/PGMonitor.cc @@ -154,6 +154,10 @@ bool PGMonitor::prepare_update(Message *m) } } +void PGMonitor::committed() +{ + +} void PGMonitor::handle_statfs(MStatfs *statfs) { diff --git a/trunk/ceph/mon/PGMonitor.h b/trunk/ceph/mon/PGMonitor.h index e243d0851430d..7b6d44f814fd2 100644 --- a/trunk/ceph/mon/PGMonitor.h +++ b/trunk/ceph/mon/PGMonitor.h @@ -40,6 +40,8 @@ private: void create_pending(); // prepare a new pending void encode_pending(bufferlist &bl); // propose pending update to peers + void committed(); + bool preprocess_query(Message *m); // true if processed. bool prepare_update(Message *m); diff --git a/trunk/ceph/mon/PaxosService.cc b/trunk/ceph/mon/PaxosService.cc index bc85b49de5b55..7b0eed20972a0 100644 --- a/trunk/ceph/mon/PaxosService.cc +++ b/trunk/ceph/mon/PaxosService.cc @@ -100,6 +100,8 @@ void PaxosService::_commit() assert(have_pending == false); create_pending(); have_pending = true; + + committed(); } } diff --git a/trunk/ceph/mon/PaxosService.h b/trunk/ceph/mon/PaxosService.h index fb72efcfda588..a0f39c7862273 100644 --- a/trunk/ceph/mon/PaxosService.h +++ b/trunk/ceph/mon/PaxosService.h @@ -99,6 +99,8 @@ public: virtual bool prepare_update(Message *m) = 0; virtual bool should_propose(double &delay); + virtual void committed() = 0; + }; #endif -- 2.39.5