This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 4b34a90c0a01a944f1c7a556d5d7a40e9e3dd2b1
Author: Andrei Sekretenko <[email protected]>
AuthorDate: Fri Oct 4 18:14:37 2019 -0400

    Added method to notify allocator that offered transitioned to allocated.
    
    This is a prerequisite for tracking quota consumption in allocator.
    
    Review: https://reviews.apache.org/r/71487/
---
 include/mesos/allocator/allocator.hpp       |  7 +++++++
 src/master/allocator/mesos/allocator.hpp    | 18 ++++++++++++++++++
 src/master/allocator/mesos/hierarchical.cpp |  6 ++++++
 src/master/allocator/mesos/hierarchical.hpp |  3 +++
 src/master/master.cpp                       | 14 ++++++++++++++
 src/tests/allocator.hpp                     | 15 +++++++++++++++
 6 files changed, 63 insertions(+)

diff --git a/include/mesos/allocator/allocator.hpp 
b/include/mesos/allocator/allocator.hpp
index 3c5fd55..96fd6e3 100644
--- a/include/mesos/allocator/allocator.hpp
+++ b/include/mesos/allocator/allocator.hpp
@@ -373,6 +373,13 @@ public:
     getInverseOfferStatuses() = 0;
 
   /**
+   * This method should be invoked when the offered resources has become
+   * actually allocated.
+   */
+  virtual void transitionOfferedToAllocated(
+      const SlaveID& slaveId, const Resources& resources) = 0;
+
+  /**
    * Recovers resources.
    *
    * Used to update the set of available resources for a specific agent. This
diff --git a/src/master/allocator/mesos/allocator.hpp 
b/src/master/allocator/mesos/allocator.hpp
index 9467912..dd7952b 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -144,6 +144,9 @@ public:
               hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>>
     getInverseOfferStatuses() override;
 
+  void transitionOfferedToAllocated(
+     const SlaveID& slaveId, const Resources& resources) override;
+
   void recoverResources(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
@@ -289,6 +292,9 @@ public:
               hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>>
     getInverseOfferStatuses() = 0;
 
+  virtual void transitionOfferedToAllocated(
+      const SlaveID& slaveId, const Resources& resources) = 0;
+
   virtual void recoverResources(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
@@ -628,6 +634,18 @@ inline process::Future<
       &MesosAllocatorProcess::getInverseOfferStatuses);
 }
 
+template <typename AllocatorProcess>
+inline void MesosAllocator<AllocatorProcess>::transitionOfferedToAllocated(
+    const SlaveID& slaveId,
+    const Resources& resources)
+{
+  process::dispatch(
+      process,
+      &MesosAllocatorProcess::transitionOfferedToAllocated,
+      slaveId,
+      resources);
+}
+
 
 template <typename AllocatorProcess>
 inline void MesosAllocator<AllocatorProcess>::recoverResources(
diff --git a/src/master/allocator/mesos/hierarchical.cpp 
b/src/master/allocator/mesos/hierarchical.cpp
index 7a2da4e..b36f893 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1457,6 +1457,12 @@ HierarchicalAllocatorProcess::getInverseOfferStatuses()
   return result;
 }
 
+void HierarchicalAllocatorProcess::transitionOfferedToAllocated(
+    const SlaveID& slaveId,
+    const Resources& resources)
+{
+}
+
 
 void HierarchicalAllocatorProcess::recoverResources(
     const FrameworkID& frameworkId,
diff --git a/src/master/allocator/mesos/hierarchical.hpp 
b/src/master/allocator/mesos/hierarchical.hpp
index 0dcfc87..7d48bdc 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -580,6 +580,9 @@ public:
       hashmap<FrameworkID, mesos::allocator::InverseOfferStatus>>>
     getInverseOfferStatuses() override;
 
+  void transitionOfferedToAllocated(
+      const SlaveID& slaveId, const Resources& resources) override;
+
   void recoverResources(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 6c7ae4b..351823e 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -5006,6 +5006,10 @@ void Master::_accept(
   // are removed from the remaining resources.
   Resources remainingResources = offeredResources;
 
+  // Allocator should be informed about resources allocated for tasks
+  /// and executors by LAUNCH/LAUNCH_GROUP operations.
+  Resources launchResources;
+
   // Converted resources from volume resizes. These converted resources are not
   // put into `remainingResources`, so no other operations can consume them.
   // TODO(zhitao): This will be unnecessary once `GROW_VOLUME` and
@@ -5660,6 +5664,7 @@ void Master::_accept(
             }
 
             remainingResources -= consumed;
+            launchResources += consumed;
 
             RunTaskMessage message;
             message.mutable_framework()->MergeFrom(framework->info);
@@ -5919,6 +5924,7 @@ void Master::_accept(
           << remainingResources << " does not contain " << totalResources;
 
         remainingResources -= totalResources;
+        launchResources += totalResources;
 
         // If the agent does not support reservation refinement, downgrade
         // the task and executor resources to the "pre-reservation-refinement"
@@ -6127,6 +6133,10 @@ void Master::_accept(
   Resources implicitlyDeclined = remainingResources - speculativelyConverted;
 
   // Prevent any allocations from occurring during resource recovery below.
+  //
+  // TODO(asekretenko): Ideally, we should be able to inform the allocator 
about
+  // all the resource state transitions in one call. This will obviate the need
+  // to pause/resume the allocator.
   allocator->pause();
 
   // Tell the allocator about the net speculatively converted resources. These
@@ -6142,6 +6152,10 @@ void Master::_accept(
         frameworkId, slaveId, implicitlyDeclined, accept.filters(), false);
   }
 
+  if (!launchResources.empty()) {
+    allocator->transitionOfferedToAllocated(slaveId, launchResources);
+  }
+
   allocator->resume();
 }
 
diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp
index a1f6737..4765604 100644
--- a/src/tests/allocator.hpp
+++ b/src/tests/allocator.hpp
@@ -178,6 +178,12 @@ ACTION_P(InvokeGetInverseOfferStatuses, allocator)
 }
 
 
+ACTION_P(InvokeTransitionOfferedToAllocated, allocator)
+{
+  allocator->real->transitionOfferedToAllocated(arg0, arg1);
+}
+
+
 ACTION_P(InvokeRecoverResources, allocator)
 {
   allocator->real->recoverResources(arg0, arg1, arg2, arg3, arg4);
@@ -356,6 +362,11 @@ public:
     EXPECT_CALL(*this, getInverseOfferStatuses())
       .WillRepeatedly(DoDefault());
 
+    ON_CALL(*this, transitionOfferedToAllocated(_, _))
+      .WillByDefault(InvokeTransitionOfferedToAllocated(this));
+    EXPECT_CALL(*this, transitionOfferedToAllocated(_, _))
+      .WillRepeatedly(DoDefault());
+
     ON_CALL(*this, recoverResources(_, _, _, _, _))
       .WillByDefault(InvokeRecoverResources(this));
     EXPECT_CALL(*this, recoverResources(_, _, _, _, _))
@@ -489,6 +500,10 @@ public:
           FrameworkID,
           mesos::allocator::InverseOfferStatus>>>());
 
+  MOCK_METHOD2(transitionOfferedToAllocated, void(
+      const SlaveID&,
+      const Resources&));
+
   MOCK_METHOD5(recoverResources, void(
       const FrameworkID&,
       const SlaveID&,

Reply via email to