]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
MDS: MDSMonitor: Make MDS set standby-replay preferences, not MDSMonitor.
authorGreg Farnum <gregory.farnum@dreamhost.com>
Mon, 24 Jan 2011 18:28:22 +0000 (10:28 -0800)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Mon, 24 Jan 2011 18:57:51 +0000 (10:57 -0800)
The MDS has more information about its configuration than the MDSMonitor
does. Therefore, encode that information into the standby_for_rank,
and let the monitor just operate based off that. This reduces magic
numbers and should be more robust.

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
src/mds/MDS.cc
src/mds/MDSMap.h
src/mon/MDSMonitor.cc

index 93c1d48d473f2a40706b0946ff6baed188615975..491daef9c3efd8bf1ad0f6db07dfb88195fb3e3d 100644 (file)
@@ -81,6 +81,7 @@ MDS::MDS(const char *n, Messenger *m, MonClient *mc) :
   timer(mds_lock),
   name(n),
   whoami(-1), incarnation(0),
+  standby_for_rank(MDSMap::MDS_NO_STANDBY_PREF),
   standby_type(0),
   continue_replay(false),
   messenger(m),
@@ -476,6 +477,18 @@ int MDS::init(int wanted_state)
     standby_type = wanted_state;
   }
 
+  standby_for_rank = g_conf.mds_standby_for_rank;
+  standby_for_name.assign(g_conf.mds_standby_for_name);
+
+  if (wanted_state == MDSMap::STATE_STANDBY_REPLAY &&
+      standby_for_rank == -1) {
+    if (standby_for_name.empty())
+      standby_for_rank = MDSMap::MDS_STANDBY_ANY;
+    else
+      standby_for_rank = MDSMap::MDS_STANDBY_NAME;
+  } else if (!standby_type && !standby_for_name.empty())
+    standby_for_rank = MDSMap::MDS_MATCHED_ACTIVE;
+
   beacon_start();
   whoami = -1;
   messenger->set_myname(entity_name_t::MDS(whoami));
@@ -593,8 +606,8 @@ void MDS::beacon_send()
   
   MMDSBeacon *beacon = new MMDSBeacon(monc->get_fsid(), monc->get_global_id(), name, mdsmap->get_epoch(), 
                                      want_state, beacon_last_seq);
-  beacon->set_standby_for_rank(g_conf.mds_standby_for_rank);
-  beacon->set_standby_for_name(g_conf.mds_standby_for_name);
+  beacon->set_standby_for_rank(standby_for_rank);
+  beacon->set_standby_for_name(standby_for_name);
 
   // include _my_ feature set
   beacon->set_compat(mdsmap_compat);
index a188c2d0990fc99a8a46431f59bf87234a8bf94d..b69baff89befe7b137998368802c57fd8eb260cc 100644 (file)
@@ -87,6 +87,16 @@ public:
   static const int STATE_ACTIVE =     CEPH_MDS_STATE_ACTIVE; // up, active
   static const int STATE_STOPPING  =  CEPH_MDS_STATE_STOPPING; // up, exporting metadata (-> standby or out)
 
+  // indicate startup standby preferences for MDS
+  // of course, if they have a specific rank to follow, they just set that!
+  static const int MDS_NO_STANDBY_PREF = -1; // doesn't have instructions to do anything
+  static const int MDS_STANDBY_ANY = -2; // is instructed to be standby-replay, may
+                                     // or may not have specific name to follow
+  static const int MDS_STANDBY_NAME = -3; // standby for a named MDS
+  static const int MDS_MATCHED_ACTIVE = -4; // has a matched standby, which if up
+                                            // it should follow, but otherwise should
+                                            // be assigned a rank
+
   struct mds_info_t {
     uint64_t global_id;
     string name;
@@ -312,11 +322,11 @@ public:
       if (((p->second.rank == -1 &&
            (p->second.standby_for_rank == mds ||
             p->second.standby_for_name == name)) ||
-         (p->second.standby_for_rank == -2)) &&
+         (p->second.standby_for_rank == MDS_STANDBY_ANY)) &&
          (p->second.state == MDSMap::STATE_STANDBY ||
              p->second.state == MDSMap::STATE_STANDBY_REPLAY) &&
           !p->second.laggy()) {
-       if (p->second.standby_for_rank == -2)
+       if (p->second.standby_for_rank == MDS_STANDBY_ANY)
          generic_standby = p;
        else
          return p->first;
@@ -331,7 +341,8 @@ public:
         p != mds_info.end();
         ++p) {
       if (p->second.rank == -1 &&
-         p->second.standby_for_rank < 0 &&
+         (p->second.standby_for_rank == MDS_NO_STANDBY_PREF ||
+          p->second.standby_for_rank == MDS_MATCHED_ACTIVE) &&
          p->second.state == MDSMap::STATE_STANDBY &&
          !p->second.laggy()) {
        return p->first;
index 5d8c00ae24ef48a2322102d882ae57b3f73b2304..b8fa9ca97d5752622d50313bf842dfde76794033 100644 (file)
@@ -238,7 +238,7 @@ bool MDSMonitor::preprocess_beacon(MMDSBeacon *m)
        (state == MDSMap::STATE_STANDBY_REPLAY ||
            state == MDSMap::STATE_ONESHOT_REPLAY) &&
        (pending_mdsmap.is_degraded() ||
-        ((m->get_standby_for_rank() != -1) &&
+        ((m->get_standby_for_rank() >= 0) &&
             pending_mdsmap.get_state(m->get_standby_for_rank()) < MDSMap::STATE_ACTIVE))) {
       dout(10) << "mds_beacon can't standby-replay mds" << m->get_standby_for_rank() << " at this time (cluster degraded, or mds not active)" << dendl;
       dout(10) << "pending_mdsmap.is_degraded()==" << pending_mdsmap.is_degraded()
@@ -343,7 +343,7 @@ bool MDSMonitor::prepare_beacon(MMDSBeacon *m)
         info.standby_for_rank =
             pending_mdsmap.find_by_name(info.standby_for_name)->rank;
     }
-    if (info.standby_for_rank >= 0) {
+    if (info.standby_for_rank >= 0 && !mdsmap.is_dne(info.standby_for_rank)) {
       info.state = MDSMap::STATE_STANDBY_REPLAY;
     }
 
@@ -379,26 +379,28 @@ bool MDSMonitor::prepare_beacon(MMDSBeacon *m)
       pending_mdsmap.stopped.insert(info.rank);
       pending_mdsmap.mds_info.erase(gid);  // last! info is a ref into this map
       last_beacon.erase(gid);
-    } else if (state == MDSMap::STATE_STANDBY_REPLAY &&
-              (m->get_standby_for_rank() == -1) &&
-              (m->get_standby_for_name().empty())) {
-      // note the MDS as available for standby_replay on any MDS
-      dout(10) << "marking available for standby_replay" << dendl;
-      info.standby_for_rank = -2;
-    } else if (state == MDSMap::STATE_STANDBY_REPLAY &&
-              m->get_standby_for_rank() == -1) {
-      /* convert name to rank. If we don't have it, do nothing. The
+    } else if (state == MDSMap::STATE_STANDBY_REPLAY) {
+      if (m->get_standby_for_rank() == MDSMap::MDS_STANDBY_NAME) {
+        /* convert name to rank. If we don't have it, do nothing. The
         mds will stay in standby and keep requesting the state change */
-      dout(20) << "looking for mds " << m->get_standby_for_name()
-              << " to STANDBY_REPLAY for" << dendl;
-      if (pending_mdsmap.find_by_name(m->get_standby_for_name())) {
-          info.standby_for_rank =
-              pending_mdsmap.find_by_name(m->get_standby_for_name())->rank;
+        dout(20) << "looking for mds " << m->get_standby_for_name()
+                  << " to STANDBY_REPLAY for" << dendl;
+        const MDSMap::mds_info_t *found_mds = NULL;
+        if ((found_mds = mdsmap.find_by_name(m->get_standby_for_name())) &&
+            (found_mds->rank >= 0)) {
+          info.standby_for_rank = found_mds->rank;
           dout(10) <<" found mds " << m->get_standby_for_name()
-                   << "; it has rank " << info.standby_for_rank << dendl;
+                       << "; it has rank " << info.standby_for_rank << dendl;
           info.state = MDSMap::STATE_STANDBY_REPLAY;
           info.state_seq = seq;
-      }
+        }
+      } else if (m->get_standby_for_rank() >= 0 &&
+                 !mdsmap.is_dne(m->get_standby_for_rank())) {
+        /* switch to standby-replay for this MDS*/
+        info.state = MDSMap::STATE_STANDBY_REPLAY;
+        info.state_seq = seq;
+        info.standby_for_rank = m->get_standby_for_rank();
+      } // else it's a standby for anybody, and is already in the list
     } else {
       info.state = state;
       info.state_seq = seq;
@@ -840,13 +842,13 @@ void MDSMonitor::tick()
        continue;
       }
 
-      if (since >= cutoff && pending_mdsmap.mds_info[gid].standby_for_rank != -2)
+      if (since >= cutoff && pending_mdsmap.mds_info[gid].standby_for_rank != MDSMap::MDS_STANDBY_ANY)
        continue;
 
 
       MDSMap::mds_info_t& info = pending_mdsmap.mds_info[gid];
 
-      if (since >= cutoff && info.standby_for_rank == -2) {
+      if (since >= cutoff && info.standby_for_rank == MDSMap::MDS_STANDBY_ANY) {
         /* this mds is not laggy, but has no rank assigned.
          * See if we can find it somebody to shadow
          */