You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2018/07/25 23:20:02 UTC

[2/2] mesos git commit: Added a `stripIncapableResources` helper in the allocator.

Added a `stripIncapableResources` helper in the allocator.

This helper removes any resources that the framework is not
capable of receiving based on the given framework capability.

Review: https://reviews.apache.org/r/67827/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/eeb74c03
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/eeb74c03
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/eeb74c03

Branch: refs/heads/master
Commit: eeb74c03695a8311a9c3bf2d2f895c6c25f86266
Parents: a9d50ef
Author: Meng Zhu <mz...@mesosphere.io>
Authored: Wed Jul 25 16:15:48 2018 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Wed Jul 25 16:15:48 2018 -0700

----------------------------------------------------------------------
 src/master/allocator/mesos/hierarchical.cpp | 115 ++++++++++-------------
 src/master/allocator/mesos/hierarchical.hpp |   9 ++
 2 files changed, 59 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/eeb74c03/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 7b4e9db..3599247 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1803,21 +1803,14 @@ void HierarchicalAllocatorProcess::__allocate()
           continue;
         }
 
-        // Calculate the currently available resources on the slave, which
-        // is the difference in non-shared resources between total and
-        // allocated, plus all shared resources on the agent (if applicable).
-        Resources available = slave.getAvailable().nonShared();
-
-        // Since shared resources are offerable even when they are in use, we
-        // make one copy of the shared resources available regardless of the
-        // past allocations. Offer a shared resource only if it has not been
-        // offered in this offer cycle to a framework.
-        if (framework.capabilities.sharedResources) {
-          available += slave.getTotal().shared();
-          if (offeredSharedResources.contains(slaveId)) {
-            available -= offeredSharedResources[slaveId];
-          }
-        }
+        // Get the currently available resources on the agent and strip
+        // resources that are incompatible with the framework capabilities.
+        Resources available =
+          stripIncapableResources(slave.getAvailable(), framework.capabilities);
+
+        // Offer a shared resource only if it has not been offered in this
+        // offer cycle to a framework.
+        available -= offeredSharedResources.get(slaveId).getOrElse(Resources());
 
         // In this first stage, we allocate the role's reservations as well as
         // any unreserved resources while ensuring the role stays within its
@@ -1947,21 +1940,6 @@ void HierarchicalAllocatorProcess::__allocate()
           break;
         }
 
-        // When reservation refinements are present, old frameworks without the
-        // RESERVATION_REFINEMENT capability won't be able to understand the
-        // new format. While it's possible to translate the refined reservations
-        // into the old format by "hiding" the intermediate reservations in the
-        // "stack", this leads to ambiguity when processing RESERVE / UNRESERVE
-        // operations. This is due to the loss of information when we drop the
-        // intermediate reservations. Therefore, for now we simply filter out
-        // resources with refined reservations if the framework does not have
-        // the capability.
-        if (!framework.capabilities.reservationRefinement) {
-          toAllocate = toAllocate.filter([](const Resource& resource) {
-            return !Resources::hasRefinedReservations(resource);
-          });
-        }
-
         // If the framework filters these resources, ignore.
         if (isFiltered(frameworkId, role, slaveId, toAllocate)) {
           continue;
@@ -2036,21 +2014,14 @@ void HierarchicalAllocatorProcess::__allocate()
           continue;
         }
 
-        // Calculate the currently available resources on the slave, which
-        // is the difference in non-shared resources between total and
-        // allocated, plus all shared resources on the agent (if applicable).
-        Resources available = slave.getAvailable().nonShared();
-
-        // Since shared resources are offerable even when they are in use, we
-        // make one copy of the shared resources available regardless of the
-        // past allocations. Offer a shared resource only if it has not been
-        // offered in this offer cycle to a framework.
-        if (framework.capabilities.sharedResources) {
-          available += slave.getTotal().shared();
-          if (offeredSharedResources.contains(slaveId)) {
-            available -= offeredSharedResources[slaveId];
-          }
-        }
+        // Get the currently available resources on the agent and strip
+        // resources that are incompatible with the framework capabilities.
+        Resources available =
+          stripIncapableResources(slave.getAvailable(), framework.capabilities);
+
+        // Offer a shared resource only if it has not been offered in this offer
+        // cycle to a framework.
+        available -= offeredSharedResources.get(slaveId).getOrElse(Resources());
 
         // The resources we offer are the unreserved resources as well as the
         // reserved resources for this particular role and all its ancestors
@@ -2076,26 +2047,6 @@ void HierarchicalAllocatorProcess::__allocate()
           break;
         }
 
-        // Remove revocable resources if the framework has not opted for them.
-        if (!framework.capabilities.revocableResources) {
-          toAllocate = toAllocate.nonRevocable();
-        }
-
-        // When reservation refinements are present, old frameworks without the
-        // RESERVATION_REFINEMENT capability won't be able to understand the
-        // new format. While it's possible to translate the refined reservations
-        // into the old format by "hiding" the intermediate reservations in the
-        // "stack", this leads to ambiguity when processing RESERVE / UNRESERVE
-        // operations. This is due to the loss of information when we drop the
-        // intermediate reservations. Therefore, for now we simply filter out
-        // resources with refined reservations if the framework does not have
-        // the capability.
-        if (!framework.capabilities.reservationRefinement) {
-          toAllocate = toAllocate.filter([](const Resource& resource) {
-            return !Resources::hasRefinedReservations(resource);
-          });
-        }
-
         // If allocating these resources would reduce the headroom
         // below what is required, we will hold them back.
         const Resources headroomToAllocate = toAllocate
@@ -2730,6 +2681,40 @@ bool HierarchicalAllocatorProcess::isCapableOfReceivingAgent(
 }
 
 
+Resources HierarchicalAllocatorProcess::stripIncapableResources(
+    const Resources& resources,
+    const protobuf::framework::Capabilities& frameworkCapabilities) const
+{
+  return resources.filter([&](const Resource& resource) {
+    if (!frameworkCapabilities.sharedResources &&
+        Resources::isShared(resource)) {
+      return false;
+    }
+
+    if (!frameworkCapabilities.revocableResources &&
+        Resources::isRevocable(resource)) {
+      return false;
+    }
+
+    // When reservation refinements are present, old frameworks without the
+    // RESERVATION_REFINEMENT capability won't be able to understand the
+    // new format. While it's possible to translate the refined reservations
+    // into the old format by "hiding" the intermediate reservations in the
+    // "stack", this leads to ambiguity when processing RESERVE / UNRESERVE
+    // operations. This is due to the loss of information when we drop the
+    // intermediate reservations. Therefore, for now we simply filter out
+    // resources with refined reservations if the framework does not have
+    // the capability.
+    if (!frameworkCapabilities.reservationRefinement &&
+        Resources::hasRefinedReservations(resource)) {
+      return false;
+    }
+
+    return true;
+  });
+}
+
+
 void HierarchicalAllocatorProcess::trackAllocatedResources(
     const SlaveID& slaveId,
     const FrameworkID& frameworkId,

http://git-wip-us.apache.org/repos/asf/mesos/blob/eeb74c03/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 02c63b1..0cd2fac 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -674,6 +674,15 @@ private:
       const protobuf::framework::Capabilities& frameworkCapabilities,
       const Slave& slave) const;
 
+  // Helper function that removes any resources that the framework is not
+  // capable of receiving based on the given framework capability.
+  //
+  // TODO(mzhu): Make this a `Framework` member function once we pull
+  // `struct Framework` out from being nested.
+  Resources stripIncapableResources(
+      const Resources& resources,
+      const protobuf::framework::Capabilities& frameworkCapabilities) const;
+
   // Helper to track allocated resources on an agent.
   void trackAllocatedResources(
       const SlaveID& slaveId,