You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 08:43:38 UTC

svn commit: r1131975 - in /incubator/mesos/trunk/src: master.cpp mesos_sched.cpp messages.hpp third_party/libprocess/serialization.cpp third_party/libprocess/serialization.hpp

Author: benh
Date: Sun Jun  5 06:43:38 2011
New Revision: 1131975

URL: http://svn.apache.org/viewvc?rev=1131975&view=rev
Log:
Cleaned up some code. Specifically removed the serialization of bool because it can cause nasty bugs if someone tries to send a pointer.

Modified:
    incubator/mesos/trunk/src/master.cpp
    incubator/mesos/trunk/src/mesos_sched.cpp
    incubator/mesos/trunk/src/messages.hpp
    incubator/mesos/trunk/src/third_party/libprocess/serialization.cpp
    incubator/mesos/trunk/src/third_party/libprocess/serialization.hpp

Modified: incubator/mesos/trunk/src/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.cpp?rev=1131975&r1=1131974&r2=1131975&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.cpp (original)
+++ incubator/mesos/trunk/src/master.cpp Sun Jun  5 06:43:38 2011
@@ -296,7 +296,7 @@ void Master::operator () ()
       LOG(INFO) << "Registering " << framework << " at " << framework->pid;
 
       if (framework->executorInfo.uri == "") {
-        LOG(INFO) << framework << " registered without an executor URI";
+        LOG(INFO) << framework << " registering without an executor URI";
         send(framework->pid, pack<M2F_ERROR>(1, "No executor URI given"));
         delete framework;
         break;
@@ -308,20 +308,20 @@ void Master::operator () ()
 
     case F2M_REREGISTER_FRAMEWORK: {
       Framework *framework = new Framework(from(), "", elapsed());
-      bool failover;
+      int32_t generation;
       unpack<F2M_REREGISTER_FRAMEWORK>(framework->id, framework->name,
                                        framework->user, framework->executorInfo,
-                                       failover);
+                                       generation);
 
       if (framework->executorInfo.uri == "") {
-        LOG(INFO) << framework << " re-registered without an executor URI";
+        LOG(INFO) << framework << " re-registering without an executor URI";
         send(framework->pid, pack<M2F_ERROR>(1, "No executor URI given"));
         delete framework;
         break;
       }
 
       if (framework->id == "") {
-        LOG(ERROR) << "Framework reconnect/failover without an id!";
+        LOG(ERROR) << "Framework re-registering without an id!";
         send(framework->pid, pack<M2F_ERROR>(1, "Missing framework id"));
         delete framework;
         break;
@@ -330,10 +330,12 @@ void Master::operator () ()
       LOG(INFO) << "Re-registering " << framework << " at " << framework->pid;
 
       if (frameworks.count(framework->id) > 0) {
-        if (failover) {
+        if (generation == 0) {
+          LOG(INFO) << framework << " failed over";
           replaceFramework(frameworks[framework->id], framework);
         } else {
-          LOG(INFO) << "Framework reregistering with an already used id!";
+          LOG(INFO) << framework << " re-registering with an already "
+		    << "used id and not failing over!";
           send(framework->pid, pack<M2F_ERROR>(1, "Framework id in use"));
           delete framework;
           break;
@@ -944,9 +946,9 @@ void Master::replaceFramework(Framework 
   CHECK(old->id == current->id);
 
   old->active = false;
-  // TODO: Notify allocator that a framework removal is beginning?
   
-  // Remove the framework's slot offers
+  // Remove the framework's slot offers.
+  // TODO(benh): Consider just reoffering these to the new framework.
   unordered_set<SlotOffer *> slotOffersCopy = old->slotOffers;
   foreach (SlotOffer* offer, slotOffersCopy) {
     removeSlotOffer(offer, ORR_FRAMEWORK_FAILOVER, offer->resources);
@@ -954,18 +956,15 @@ void Master::replaceFramework(Framework 
 
   send(old->pid, pack<M2F_ERROR>(1, "Framework failover"));
 
-  // TODO(benh): Similar code between removeFramework and
-  // replaceFramework needs to be shared!
-
   // TODO(benh): unlink(old->pid);
   pidToFid.erase(old->pid);
-
-  // Delete it
-  frameworks.erase(old->id);
-  allocator->frameworkRemoved(old);
   delete old;
 
-  addFramework(current);
+  frameworks[current->id] = current;
+  pidToFid[current->pid] = current->id;
+  link(current->pid);
+
+  send(current->pid, pack<M2F_REGISTER_REPLY>(current->id));
 }
 
 

Modified: incubator/mesos/trunk/src/mesos_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/mesos_sched.cpp?rev=1131975&r1=1131974&r2=1131975&view=diff
==============================================================================
--- incubator/mesos/trunk/src/mesos_sched.cpp (original)
+++ incubator/mesos/trunk/src/mesos_sched.cpp Sun Jun  5 06:43:38 2011
@@ -106,7 +106,7 @@ private:
   FrameworkID fid;
   string frameworkName;
   ExecutorInfo execInfo;
-
+  int32_t generation;
   PID master;
 
   volatile bool terminate;
@@ -127,6 +127,7 @@ public:
       fid(_fid),
       frameworkName(_frameworkName),
       execInfo(_execInfo),
+      generation(0),
       master(PID()),
       terminate(false) {}
 
@@ -172,10 +173,6 @@ protected:
 
 	LOG(INFO) << "New master at " << masterPid << " with ID:" << masterSeq;
 
-	// Connect as a failover if this is the first master we are
-        // being told about a master AND we already have an id.
-        bool failover = !master && fid != "";
-
         redirect(master, masterPid);
 	master = masterPid;
 	link(master);
@@ -186,7 +183,7 @@ protected:
 	} else {
 	  // Not the first time, or failing over.
 	  send(master, pack<F2M_REREGISTER_FRAMEWORK>(fid, frameworkName, user,
-						      execInfo, failover));
+						      execInfo, generation++));
 	}
 	break;
       }

Modified: incubator/mesos/trunk/src/messages.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/messages.hpp?rev=1131975&r1=1131974&r2=1131975&view=diff
==============================================================================
--- incubator/mesos/trunk/src/messages.hpp (original)
+++ incubator/mesos/trunk/src/messages.hpp Sun Jun  5 06:43:38 2011
@@ -125,11 +125,11 @@ TUPLE(F2M_REGISTER_FRAMEWORK,
        ExecutorInfo));
 
 TUPLE(F2M_REREGISTER_FRAMEWORK,
-      (std::string /*fid*/,
+      (FrameworkID,
        std::string /*name*/,
        std::string /*user*/,
        ExecutorInfo,
-       bool /*failover*/));
+       int32_t /*generation*/));
 
 TUPLE(F2M_UNREGISTER_FRAMEWORK,
       (FrameworkID));
@@ -199,7 +199,7 @@ TUPLE(S2M_REGISTER_SLAVE,
        Resources));
 
 TUPLE(S2M_REREGISTER_SLAVE,
-      (std::string /*slave id*/,
+      (SlaveID,
        std::string /*name*/,
        std::string /*publicDns*/,
        Resources,

Modified: incubator/mesos/trunk/src/third_party/libprocess/serialization.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/third_party/libprocess/serialization.cpp?rev=1131975&r1=1131974&r2=1131975&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/serialization.cpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/serialization.cpp Sun Jun  5 06:43:38 2011
@@ -5,16 +5,11 @@
 #include "process.hpp"
 #include "serialization.hpp"
 
+
 namespace process { namespace serialization {
 
 /* TODO(*): Check stream errors! Report errors! Ahhhh! */
 
-void serializer::operator & (const bool &b)
-{
-  stream.put(b ? 1 : 0);
-}
-
-
 void serializer::operator & (const int32_t &i)
 {
   uint32_t netInt = htonl((uint32_t) i);
@@ -65,12 +60,6 @@ void serializer::operator & (const PID &
 }
 
 
-void deserializer::operator & (bool &b)
-{
-  b = stream.get();
-}
-
-
 void deserializer::operator & (int32_t &i)
 {
   uint32_t netInt;

Modified: incubator/mesos/trunk/src/third_party/libprocess/serialization.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/third_party/libprocess/serialization.hpp?rev=1131975&r1=1131974&r2=1131975&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/serialization.hpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/serialization.hpp Sun Jun  5 06:43:38 2011
@@ -14,7 +14,6 @@ struct serializer
 
   serializer(std::ostringstream& s) : stream(s) {}
 
-  void operator & (const bool &);
   void operator & (const int32_t &);
   void operator & (const int64_t &);
   void operator & (const double &);
@@ -29,7 +28,6 @@ struct deserializer
 
   deserializer(std::istringstream &s) : stream(s) {}
 
-  void operator & (bool &);
   void operator & (int32_t &);
   void operator & (int64_t &);
   void operator & (double &);