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 2012/07/14 03:45:13 UTC

svn commit: r1361467 - in /incubator/mesos/trunk/src: master/ tests/

Author: benh
Date: Sat Jul 14 01:45:12 2012
New Revision: 1361467

URL: http://svn.apache.org/viewvc?rev=1361467&view=rev
Log:
Fixes a bug in the allocator that didn't properly handle master
failover when slaves connect before frameworks.

Modified:
    incubator/mesos/trunk/src/master/allocator.hpp
    incubator/mesos/trunk/src/master/dominant_share_allocator.cpp
    incubator/mesos/trunk/src/master/dominant_share_allocator.hpp
    incubator/mesos/trunk/src/master/master.cpp
    incubator/mesos/trunk/src/master/master.hpp
    incubator/mesos/trunk/src/tests/allocator_tests.cpp
    incubator/mesos/trunk/src/tests/resource_offers_tests.cpp
    incubator/mesos/trunk/src/tests/utils.hpp

Modified: incubator/mesos/trunk/src/master/allocator.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/allocator.hpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/allocator.hpp (original)
+++ incubator/mesos/trunk/src/master/allocator.hpp Sat Jul 14 01:45:12 2012
@@ -44,7 +44,8 @@ public:
   virtual void initialize(const process::PID<Master>& master) = 0;
 
   virtual void frameworkAdded(const FrameworkID& frameworkId,
-                              const FrameworkInfo& frameworkInfo) = 0;
+                              const FrameworkInfo& frameworkInfo,
+                              const Resources& used) = 0;
 
   virtual void frameworkDeactivated(const FrameworkID& frameworkId) = 0;
 

Modified: incubator/mesos/trunk/src/master/dominant_share_allocator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/dominant_share_allocator.cpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/dominant_share_allocator.cpp (original)
+++ incubator/mesos/trunk/src/master/dominant_share_allocator.cpp Sat Jul 14 01:45:12 2012
@@ -129,11 +129,22 @@ void DominantShareAllocator::initialize(
 
 void DominantShareAllocator::frameworkAdded(
     const FrameworkID& frameworkId,
-    const FrameworkInfo& frameworkInfo)
+    const FrameworkInfo& frameworkInfo,
+    const Resources& used)
 {
   CHECK(initialized);
 
-  frameworks[frameworkId] = frameworkInfo;
+  if (!frameworks.contains(frameworkId)) {
+    frameworks[frameworkId] = frameworkInfo;
+    allocated[frameworkId] += used;
+  } else {
+    // We at least update the framework info. TODO(benh): Consider
+    // adding a check which confirms that the resources used are a
+    // subset or equal to the resources allocated (a subset because
+    // the allocator might have just asked the master to offer some
+    // more resources).
+    frameworks[frameworkId] = frameworkInfo;
+  }
 
   LOG(INFO) << "Added framework " << frameworkId;
 
@@ -192,8 +203,9 @@ void DominantShareAllocator::slaveAdded(
   Resources unused = slaveInfo.resources();
 
   foreachpair (const FrameworkID& frameworkId, const Resources& resources, used) {
-    CHECK(frameworks.contains(frameworkId));
-    allocated[frameworkId] += resources;
+    if (frameworks.contains(frameworkId)) {
+      allocated[frameworkId] += resources;
+    }
     unused -= resources;
   }
 

Modified: incubator/mesos/trunk/src/master/dominant_share_allocator.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/dominant_share_allocator.hpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/dominant_share_allocator.hpp (original)
+++ incubator/mesos/trunk/src/master/dominant_share_allocator.hpp Sat Jul 14 01:45:12 2012
@@ -44,10 +44,11 @@ public:
 
   virtual ~DominantShareAllocator() {}
 
-  virtual void initialize(const process::PID<Master>& _master);
+  virtual void initialize(const process::PID<Master>& master);
 
   virtual void frameworkAdded(const FrameworkID& frameworkId,
-                              const FrameworkInfo& frameworkInfo);
+                              const FrameworkInfo& frameworkInfo,
+                              const Resources& used);
 
   virtual void frameworkDeactivated(const FrameworkID& frameworkId);
 

Modified: incubator/mesos/trunk/src/master/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.cpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.cpp (original)
+++ incubator/mesos/trunk/src/master/master.cpp Sat Jul 14 01:45:12 2012
@@ -661,8 +661,6 @@ void Master::reregisterFramework(const F
 
     // TODO(benh): Check for root submissions like above!
 
-    addFramework(framework);
-
     // Add any running tasks reported by slaves for this framework.
     foreachpair (const SlaveID& slaveId, Slave* slave, slaves) {
       foreachvalue (Task* task, slave->tasks) {
@@ -680,6 +678,11 @@ void Master::reregisterFramework(const F
         }
       }
     }
+
+    // N.B. Need to add the framwwork _after_ we add it's tasks
+    // (above) so that we can properly determine the resources it's
+    // currently using!
+    addFramework(framework);
   }
 
   CHECK(frameworks.count(frameworkInfo.id()) > 0);
@@ -1554,7 +1557,7 @@ void Master::addFramework(Framework* fra
   send(framework->pid, message);
 
   dispatch(allocator, &Allocator::frameworkAdded,
-           framework->id, framework->info);
+           framework->id, framework->info, framework->resources);
 }
 
 
@@ -1579,7 +1582,7 @@ void Master::failoverFramework(Framework
   framework->active = true;
 
   dispatch(allocator, &Allocator::frameworkAdded,
-           framework->id, framework->info);
+           framework->id, framework->info, framework->resources);
 
   framework->reregisteredTime = Clock::now();
 

Modified: incubator/mesos/trunk/src/master/master.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.hpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.hpp (original)
+++ incubator/mesos/trunk/src/master/master.hpp Sat Jul 14 01:45:12 2012
@@ -348,8 +348,8 @@ struct Slave
   double registeredTime;
   double lastHeartbeat;
 
-  Resources resourcesOffered; // Resources currently in offers.
-  Resources resourcesInUse;   // Resources currently used by tasks.
+  Resources resourcesOffered; // Resources offered.
+  Resources resourcesInUse;   // Resources used by tasks and executors.
 
   // Executors running on this slave.
   hashmap<FrameworkID, hashmap<ExecutorID, ExecutorInfo> > executors;

Modified: incubator/mesos/trunk/src/tests/allocator_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/allocator_tests.cpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/allocator_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/allocator_tests.cpp Sat Jul 14 01:45:12 2012
@@ -94,18 +94,18 @@ TEST(AllocatorTest, DominantShareAllocat
 
   EXPECT_CALL(a, initialize(_));
 
-  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo1)))
+  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo1), _))
     .WillOnce(DoAll(InvokeFrameworkAdded(&a),
 		    SaveArg<0>(&frameworkId1)));
 
   trigger framework2Added;
-  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo2)))
+  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo2), _))
     .WillOnce(DoAll(InvokeFrameworkAdded(&a),
 		    SaveArg<0>(&frameworkId2),
 		    Trigger(&framework2Added)));
 
   trigger framework3Added;
-  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo3)))
+  EXPECT_CALL(a, frameworkAdded(_, Eq(frameworkInfo3), _))
     .WillOnce(DoAll(InvokeFrameworkAdded(&a),
 		    SaveArg<0>(&frameworkId3),
 		    Trigger(&framework3Added)));
@@ -271,7 +271,7 @@ TYPED_TEST(AllocatorTest, MockAllocator)
 {
   EXPECT_CALL(this->allocator, initialize(_));
 
-  EXPECT_CALL(this->allocator, frameworkAdded(_, _));
+  EXPECT_CALL(this->allocator, frameworkAdded(_, _, _));
 
   EXPECT_CALL(this->allocator, frameworkDeactivated(_));
 
@@ -335,7 +335,7 @@ TYPED_TEST(AllocatorTest, ResourcesUnuse
 {
   EXPECT_CALL(this->allocator, initialize(_));
 
-  EXPECT_CALL(this->allocator, frameworkAdded(_, _))
+  EXPECT_CALL(this->allocator, frameworkAdded(_, _, _))
     .Times(2);
 
   EXPECT_CALL(this->allocator, frameworkDeactivated(_))
@@ -440,11 +440,11 @@ TYPED_TEST(AllocatorTest, OutOfOrderDisp
 
   EXPECT_CALL(this->allocator, initialize(_));
 
-  EXPECT_CALL(this->allocator, frameworkAdded(_, Eq(frameworkInfo1)))
+  EXPECT_CALL(this->allocator, frameworkAdded(_, Eq(frameworkInfo1), _))
     .WillOnce(DoAll(InvokeFrameworkAdded(&this->allocator),
 		    SaveArg<0>(&frameworkId1)));
 
-  EXPECT_CALL(this->allocator, frameworkAdded(_, Eq(frameworkInfo2)))
+  EXPECT_CALL(this->allocator, frameworkAdded(_, Eq(frameworkInfo2), _))
     .WillOnce(DoAll(InvokeFrameworkAdded(&this->allocator),
 		    SaveArg<0>(&frameworkId2)));
 
@@ -575,7 +575,7 @@ TYPED_TEST(MasterFailoverAllocatorTest, 
   EXPECT_CALL(this->allocator2, initialize(_));
 
   trigger frameworkAdded;
-  EXPECT_CALL(this->allocator2, frameworkAdded(_, _));
+  EXPECT_CALL(this->allocator2, frameworkAdded(_, _, _));
 
   EXPECT_CALL(this->allocator2, frameworkDeactivated(_));
 

Modified: incubator/mesos/trunk/src/tests/resource_offers_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/resource_offers_tests.cpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/resource_offers_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/resource_offers_tests.cpp Sat Jul 14 01:45:12 2012
@@ -460,7 +460,7 @@ TEST(ResourceOffersTest, Request)
   EXPECT_CALL(allocator, initialize(_))
     .WillOnce(Return());
 
-  EXPECT_CALL(allocator, frameworkAdded(_, _))
+  EXPECT_CALL(allocator, frameworkAdded(_, _, _))
     .WillOnce(Return());
 
   EXPECT_CALL(allocator, frameworkDeactivated(_))

Modified: incubator/mesos/trunk/src/tests/utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/utils.hpp?rev=1361467&r1=1361466&r2=1361467&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/utils.hpp (original)
+++ incubator/mesos/trunk/src/tests/utils.hpp Sat Jul 14 01:45:12 2012
@@ -240,7 +240,7 @@ public:
     ON_CALL(*this, initialize(_))
       .WillByDefault(Invoke(&real, &T::initialize));
 
-    ON_CALL(*this, frameworkAdded(_, _))
+    ON_CALL(*this, frameworkAdded(_, _, _))
       .WillByDefault(Invoke(&real, &T::frameworkAdded));
 
     ON_CALL(*this, frameworkDeactivated(_))
@@ -268,7 +268,9 @@ public:
       .WillByDefault(Invoke(&real, &T::offersRevived));
   }
   MOCK_METHOD1(initialize, void(const process::PID<master::Master>&));
-  MOCK_METHOD2(frameworkAdded, void(const FrameworkID&, const FrameworkInfo&));
+  MOCK_METHOD3(frameworkAdded, void(const FrameworkID&,
+                                    const FrameworkInfo&,
+                                    const Resources&));
   MOCK_METHOD1(frameworkDeactivated, void(const FrameworkID&));
   MOCK_METHOD1(frameworkRemoved, void(const FrameworkID&));
   MOCK_METHOD3(slaveAdded, void(const SlaveID&,
@@ -293,12 +295,12 @@ public:
 
 // The following actions make up for the fact that DoDefault
 // cannot be used inside a DoAll, for example:
-// EXPECT_CALL(allocator, frameworkAdded(_))
+// EXPECT_CALL(allocator, frameworkAdded(_, _, _))
 //   .WillOnce(DoAll(InvokeFrameworkAdded(&allocator),
 //                   Trigger(&frameworkAddedTrigger)));
 ACTION_P(InvokeFrameworkAdded, allocator)
 {
-  allocator->real.frameworkAdded(arg0, arg1);
+  allocator->real.frameworkAdded(arg0, arg1, arg2);
 }