]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: enable active daemon to return to standby
authorJohn Spray <john.spray@redhat.com>
Sat, 16 Jul 2016 21:04:39 +0000 (22:04 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 29 Sep 2016 16:26:59 +0000 (17:26 +0100)
Rather than respawn a whole process, just fall back
to being a standby.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/Mgr.cc
src/mgr/Mgr.h
src/mgr/MgrStandby.cc
src/mgr/MgrStandby.h

index bcc27855296cbbf57e62d3e7ae83793b5cb59a3d..c458c7d9cb8306e8a0ca39856a29e89bd0a273c6 100644 (file)
@@ -11,6 +11,7 @@
  * Foundation.  See file COPYING.
  */
 
+#include "osdc/Objecter.h"
 #include "common/errno.h"
 #include "mon/MonClient.h"
 #include "include/stringify.h"
@@ -33,9 +34,9 @@
 #define dout_prefix *_dout << "mgr " << __func__ << " "
 
 
-Mgr::Mgr(MonClient *monc_, Messenger *clientm_) :
+Mgr::Mgr(MonClient *monc_, Messenger *clientm_, Objecter *objecter_) :
   monc(monc_),
-  objecter(NULL),
+  objecter(objecter_),
   client_messenger(clientm_),
   lock("Mgr::lock"),
   timer(g_ceph_context, lock),
@@ -47,16 +48,12 @@ Mgr::Mgr(MonClient *monc_, Messenger *clientm_) :
   initialized(false),
   initializing(false)
 {
-  // Using Objecter to handle incremental decode of OSDMap
-  objecter = new Objecter(g_ceph_context, client_messenger, monc, NULL, 0, 0);
-
   cluster_state.set_objecter(objecter);
 }
 
 
 Mgr::~Mgr()
 {
-  delete objecter;
   assert(waiting_for_fs_map == nullptr);
 }
 
@@ -139,12 +136,6 @@ void Mgr::init()
   assert(initializing);
   assert(!initialized);
 
-  objecter->set_client_incarnation(0);
-  objecter->init();
-
-  // Dispatcher before starting objecter
-  client_messenger->add_dispatcher_head(objecter);
-
   // Start communicating with daemons to learn statistics etc
   server.init(monc->get_global_id(), client_messenger->get_myaddr());
   dout(4) << "Initialized server at " << server.get_myaddr() << dendl;
@@ -161,7 +152,6 @@ void Mgr::init()
   load_config();
 
   // Start Objecter and wait for OSD map
-  objecter->start();
   lock.Unlock();  // Drop lock because OSDMap dispatch calls into my ms_dispatch
   objecter->wait_for_osd_map();
   lock.Lock();
@@ -330,8 +320,6 @@ void Mgr::shutdown()
   // Then stop the finisher to ensure its enqueued contexts aren't going
   // to touch references to the things we're about to tear down
   finisher.stop();
-
-  objecter->shutdown();
 }
 
 void Mgr::handle_osd_map()
index 825edf153335357aae1c6aaaadbb8808a6245544..ffe1d1460c90d984a65b56a888b36c76d26a25f0 100644 (file)
@@ -23,7 +23,6 @@
 #undef _POSIX_C_SOURCE
 #undef _XOPEN_SOURCE
 
-#include "osdc/Objecter.h"
 #include "mds/FSMap.h"
 #include "messages/MFSMap.h"
 #include "msg/Messenger.h"
@@ -39,6 +38,7 @@
 
 class MCommand;
 class MMgrDigest;
+class Objecter;
 
 
 class MgrPyModule;
@@ -69,7 +69,7 @@ protected:
   bool initializing;
 
 public:
-  Mgr(MonClient *monc_, Messenger *clientm_);
+  Mgr(MonClient *monc_, Messenger *clientm_, Objecter *objecter_);
   ~Mgr();
 
   bool is_initialized() const {return initialized;}
index 896fb166f745677abf50a1d54926885128203b6b..0cb0cd01c1cfff49382fde4400dd2fcf01494328 100644 (file)
@@ -38,11 +38,13 @@ MgrStandby::MgrStandby() :
   active_mgr(nullptr)
 {
   client_messenger = Messenger::create_client_messenger(g_ceph_context, "mgr");
+  objecter = new Objecter(g_ceph_context, client_messenger, monc, NULL, 0, 0);
 }
 
 
 MgrStandby::~MgrStandby()
 {
+  delete objecter;
   delete monc;
   delete client_messenger;
   delete active_mgr;
@@ -82,6 +84,11 @@ int MgrStandby::init()
   client_t whoami = monc->get_global_id();
   client_messenger->set_myname(entity_name_t::CLIENT(whoami.v));
 
+  objecter->set_client_incarnation(0);
+  objecter->init();
+  client_messenger->add_dispatcher_head(objecter);
+  objecter->start();
+
   timer.init();
   send_beacon();
 
@@ -127,12 +134,40 @@ void MgrStandby::shutdown()
     active_mgr->shutdown();
   }
 
+  objecter->shutdown();
+
   timer.shutdown();
 
   monc->shutdown();
   client_messenger->shutdown();
 }
 
+void MgrStandby::handle_mgr_map(MMgrMap* mmap)
+{
+  auto map = mmap->get_map();
+  dout(4) << "received map epoch " << map.get_epoch() << dendl;
+  const bool active_in_map = map.active_gid == monc->get_global_id();
+  dout(4) << "active in map: " << active_in_map
+          << " active is " << map.active_gid << dendl;
+  if (active_in_map) {
+    if (active_mgr == nullptr) {
+      dout(1) << "Activating!" << dendl;
+      active_mgr = new Mgr(monc, client_messenger, objecter);
+      active_mgr->background_init();
+      dout(1) << "I am now active" << dendl;
+    } else {
+      dout(10) << "I was already active" << dendl;
+    }
+  } else {
+    if (active_mgr != nullptr) {
+      derr << "I was active but no longer am" << dendl;
+      active_mgr->shutdown();
+      delete active_mgr;
+      active_mgr = nullptr;
+    }
+  }
+}
+
 bool MgrStandby::ms_dispatch(Message *m)
 {
   Mutex::Locker l(lock);
@@ -140,31 +175,7 @@ bool MgrStandby::ms_dispatch(Message *m)
 
   switch (m->get_type()) {
     case MSG_MGR_MAP:
-      {
-        auto mmap = static_cast<MMgrMap*>(m);
-        auto map = mmap->get_map();
-        dout(4) << "received map epoch " << map.get_epoch() << dendl;
-        const bool active_in_map = map.active_gid == monc->get_global_id();
-        dout(4) << "active in map: " << active_in_map
-                << " active is " << map.active_gid << dendl;
-        if (active_in_map) {
-          if (active_mgr == nullptr) {
-            dout(1) << "Activating!" << dendl;
-            active_mgr = new Mgr(monc, client_messenger);
-            active_mgr->background_init();
-            dout(1) << "I am now active" << dendl;
-          } else {
-            dout(10) << "I was already active" << dendl;
-          }
-        } else {
-          if (active_mgr != nullptr) {
-            derr << "I was active but no longer am" << dendl;
-            shutdown();
-            // FIXME: should politely go back to standby (or respawn
-            // process) instead of stopping entirely.
-          }
-        }
-      }
+      handle_mgr_map(static_cast<MMgrMap*>(m));
       break;
 
     default:
@@ -174,6 +185,8 @@ bool MgrStandby::ms_dispatch(Message *m)
         return false;
       }
   }
+
+  m->put();
   return true;
 }
 
index ccb44d74b710ed51a8db4d4530d9fcf9c0d952bc..4c46a0730ee62add14fb3154adb905b2af4a0701 100644 (file)
 #include "DaemonState.h"
 #include "ClusterState.h"
 
+class MMgrMap;
 class Mgr;
 
 class MgrStandby : public Dispatcher {
 protected:
   MonClient *monc;
+  Objecter *objecter;
   Messenger *client_messenger;
 
   Mutex lock;
@@ -39,6 +41,8 @@ protected:
 
   std::string state_str();
 
+  void handle_mgr_map(MMgrMap *m);
+
 public:
   MgrStandby();
   ~MgrStandby();