]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: refactor MDS boot
authorJohn Spray <john.spray@redhat.com>
Mon, 21 Jul 2014 17:50:07 +0000 (18:50 +0100)
committerJohn Spray <john.spray@redhat.com>
Tue, 29 Jul 2014 21:32:18 +0000 (22:32 +0100)
* Make boot_start private.
* Define boot stages in enum, replace int with type.
* Merge steps 0 and 1, 0 always fell through to 1.
* starting_done was only ever reached by a fall through
  from the previous step, so call it directly from there.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/MDS.cc
src/mds/MDS.h

index e0bd19dedd8568756bb18e1cf054526caed5e45f..3a9adb2ec008583e3837a9b37c0edc5758a84866 100644 (file)
@@ -1380,14 +1380,16 @@ void MDS::creating_done()
 
 class C_MDS_BootStart : public Context {
   MDS *mds;
-  int nextstep;
+  MDS::BootStep nextstep;
 public:
-  C_MDS_BootStart(MDS *m, int n) : mds(m), nextstep(n) {}
+  C_MDS_BootStart(MDS *m, MDS::BootStep n) : mds(m), nextstep(n) {}
   void finish(int r) { mds->boot_start(nextstep, r); }
 };
 
-void MDS::boot_start(int step, int r)
+
+void MDS::boot_start(BootStep step, int r)
 {
+  // Handle errors from previous step
   if (r < 0) {
     if (is_standby_replay() && (r == -EAGAIN)) {
       dout(0) << "boot_start encountered an error EAGAIN"
@@ -1400,71 +1402,63 @@ void MDS::boot_start(int step, int r)
     }
   }
 
-  switch (step) {
-  case 0:
-    mdcache->init_layouts();
-    step = 1;  // fall-thru.
+  assert(is_starting() || is_any_replay());
 
-  case 1:
-    {
-      C_GatherBuilder gather(g_ceph_context, new C_MDS_BootStart(this, 2));
-      dout(2) << "boot_start " << step << ": opening inotable" << dendl;
-      inotable->load(gather.new_sub());
+  switch(step) {
+    case MDS_BOOT_INITIAL:
+      {
+        mdcache->init_layouts();
 
-      dout(2) << "boot_start " << step << ": opening sessionmap" << dendl;
-      sessionmap.load(gather.new_sub());
+        C_GatherBuilder gather(g_ceph_context, new C_MDS_BootStart(this, MDS_BOOT_OPEN_ROOT));
+        dout(2) << "boot_start " << step << ": opening inotable" << dendl;
+        inotable->load(gather.new_sub());
 
-      dout(2) << "boot_start " << step << ": opening mds log" << dendl;
-      mdlog->open(gather.new_sub());
+        dout(2) << "boot_start " << step << ": opening sessionmap" << dendl;
+        sessionmap.load(gather.new_sub());
 
-      if (mdsmap->get_tableserver() == whoami) {
-       dout(2) << "boot_start " << step << ": opening snap table" << dendl;
-       snapserver->load(gather.new_sub());
-      }
+        dout(2) << "boot_start " << step << ": opening mds log" << dendl;
+        mdlog->open(gather.new_sub());
 
-      gather.activate();
-    }
-    break;
+        if (mdsmap->get_tableserver() == whoami) {
+          dout(2) << "boot_start " << step << ": opening snap table" << dendl;
+          snapserver->load(gather.new_sub());
+        }
 
-  case 2:
-    {
-      dout(2) << "boot_start " << step << ": loading/discovering base inodes" << dendl;
+        gather.activate();
+      }
+      break;
+    case MDS_BOOT_OPEN_ROOT:
+      {
+        dout(2) << "boot_start " << step << ": loading/discovering base inodes" << dendl;
 
-      C_GatherBuilder gather(g_ceph_context, new C_MDS_BootStart(this, 3));
+        C_GatherBuilder gather(g_ceph_context, new C_MDS_BootStart(this, MDS_BOOT_PREPARE_LOG));
 
-      mdcache->open_mydir_inode(gather.new_sub());
+        mdcache->open_mydir_inode(gather.new_sub());
 
-      if (is_starting() ||
-         whoami == mdsmap->get_root()) {  // load root inode off disk if we are auth
-       mdcache->open_root_inode(gather.new_sub());
+        if (is_starting() ||
+            whoami == mdsmap->get_root()) {  // load root inode off disk if we are auth
+          mdcache->open_root_inode(gather.new_sub());
+        } else {
+          // replay.  make up fake root inode to start with
+          mdcache->create_root_inode();
+        }
+        gather.activate();
+      }
+      break;
+    case MDS_BOOT_PREPARE_LOG:
+      if (is_any_replay()) {
+        dout(2) << "boot_start " << step << ": replaying mds log" << dendl;
+        mdlog->replay(new C_MDS_BootStart(this, MDS_BOOT_REPLAY_DONE));
       } else {
-       // replay.  make up fake root inode to start with
-       mdcache->create_root_inode();
+        dout(2) << "boot_start " << step << ": positioning at end of old mds log" << dendl;
+        mdlog->append();
+        starting_done();
       }
-      gather.activate();
-    }
-    break;
-
-  case 3:
-    if (is_any_replay()) {
-      dout(2) << "boot_start " << step << ": replaying mds log" << dendl;
-      mdlog->replay(new C_MDS_BootStart(this, 4));
       break;
-    } else {
-      dout(2) << "boot_start " << step << ": positioning at end of old mds log" << dendl;
-      mdlog->append();
-      step++;
-    }
-
-  case 4:
-    if (is_any_replay()) {
+    case MDS_BOOT_REPLAY_DONE:
+      assert(is_any_replay());
       replay_done();
       break;
-    }
-    step++;
-    
-    starting_done();
-    break;
   }
 }
 
@@ -1514,7 +1508,7 @@ void MDS::replay_start()
   } else {
     dout(1) << " waiting for osdmap " << mdsmap->get_last_failure_osd_epoch() 
            << " (which blacklists prior instance)" << dendl;
-    objecter->wait_for_new_map(new C_MDS_BootStart(this, 0),
+    objecter->wait_for_new_map(new C_MDS_BootStart(this, MDS_BOOT_INITIAL),
                               mdsmap->get_last_failure_osd_epoch());
   }
 }
@@ -1539,7 +1533,7 @@ void MDS::_standby_replay_restart_finish(int r, uint64_t old_read_pos)
                  trying to reset everything in the cache, etc */
   } else {
     mdlog->standby_trim_segments();
-    boot_start(3, r);
+    boot_start(MDS_BOOT_PREPARE_LOG, r);
   }
 }
 
@@ -1550,7 +1544,7 @@ inline void MDS::standby_replay_restart()
   if (!standby_replaying && osdmap->get_epoch() < mdsmap->get_last_failure_osd_epoch()) {
     dout(1) << " waiting for osdmap " << mdsmap->get_last_failure_osd_epoch() 
            << " (which blacklists prior instance)" << dendl;
-    objecter->wait_for_new_map(new C_MDS_BootStart(this, 3),
+    objecter->wait_for_new_map(new C_MDS_BootStart(this, MDS_BOOT_PREPARE_LOG),
                               mdsmap->get_last_failure_osd_epoch());
   } else {
     mdlog->get_journaler()->reread_head_and_probe(
index b126bd20a4f53c970cbfb8dee9fe2ad57ac9dd92..5beba79fd70762cb8b5747de3645d5a0da75a47b 100644 (file)
@@ -38,7 +38,6 @@
 
 #define CEPH_MDS_PROTOCOL    24 /* cluster internal */
 
-
 enum {
   l_mds_first = 2000,
   l_mds_req,
@@ -377,9 +376,23 @@ class MDS : public Dispatcher, public md_config_obs_t {
   void bcast_mds_map();  // to mounted clients
 
   void boot_create();             // i am new mds.
-  void boot_start(int step=0, int r=0);    // starting|replay
 
+ private:
+  typedef enum {
+    // The MDSMap is available, configure default layouts and structures
+    MDS_BOOT_INITIAL = 0,
+    // We are ready to open some inodes
+    MDS_BOOT_OPEN_ROOT,
+    // We are ready to do a replay if needed
+    MDS_BOOT_PREPARE_LOG,
+    // Replay is complete
+    MDS_BOOT_REPLAY_DONE
+  } BootStep;
+
+  friend class C_MDS_BootStart;
+  void boot_start(BootStep step=MDS_BOOT_INITIAL, int r=0);    // starting|replay
   void calc_recovery_set();
+ public:
 
   void replay_start();
   void creating_done();