You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/09/14 19:58:52 UTC

[08/16] mesos git commit: Maintenance Primitives: Added a new allocation overload to sorter.

Maintenance Primitives: Added a new allocation overload to sorter.

This provides the ability to compute the frameworks that currently have
resources allocated or reserved. This information is used by the
maintenance feature to send out inverse offers.

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


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

Branch: refs/heads/master
Commit: 8e042581671fba360c92378ba47dee5a7d2b0f34
Parents: f87f733
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Sun Aug 30 14:19:40 2015 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Sep 14 13:58:37 2015 -0400

----------------------------------------------------------------------
 src/master/allocator/sorter/drf/sorter.cpp | 20 ++++++++++++++++++++
 src/master/allocator/sorter/drf/sorter.hpp |  2 ++
 src/master/allocator/sorter/sorter.hpp     |  4 ++++
 3 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8e042581/src/master/allocator/sorter/drf/sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.cpp b/src/master/allocator/sorter/drf/sorter.cpp
index bfc2734..33c47e7 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -162,6 +162,26 @@ hashmap<SlaveID, Resources> DRFSorter::allocation(const string& name)
 }
 
 
+hashmap<std::string, Resources> DRFSorter::allocation(const SlaveID& slaveId)
+{
+  // TODO(jmlvanre): We can index the allocation by slaveId to make this faster.
+  // It is a tradeoff between speed vs. memory. For now we use existing data
+  // structures.
+
+  hashmap<std::string, Resources> result;
+
+  foreachpair (const string& name, const Allocation& allocation, allocations) {
+    if (allocation.resources.contains(slaveId)) {
+      // It is safe to use `at()` here because we've just checked the existence
+      // of the key. This avoid un-necessary copies.
+      result.emplace(name, allocation.resources.at(slaveId));
+    }
+  }
+
+  return result;
+}
+
+
 Resources DRFSorter::allocation(const string& name, const SlaveID& slaveId)
 {
   CHECK(contains(name));

http://git-wip-us.apache.org/repos/asf/mesos/blob/8e042581/src/master/allocator/sorter/drf/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.hpp b/src/master/allocator/sorter/drf/sorter.hpp
index 217c7c4..9c64d7a 100644
--- a/src/master/allocator/sorter/drf/sorter.hpp
+++ b/src/master/allocator/sorter/drf/sorter.hpp
@@ -91,6 +91,8 @@ public:
 
   virtual hashmap<SlaveID, Resources> allocation(const std::string& name);
 
+  virtual hashmap<std::string, Resources> allocation(const SlaveID& slaveId);
+
   virtual Resources allocation(const std::string& name, const SlaveID& slaveId);
 
   virtual void add(const SlaveID& slaveId, const Resources& resources);

http://git-wip-us.apache.org/repos/asf/mesos/blob/8e042581/src/master/allocator/sorter/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/sorter.hpp b/src/master/allocator/sorter/sorter.hpp
index 536a7ad..faebeb3 100644
--- a/src/master/allocator/sorter/sorter.hpp
+++ b/src/master/allocator/sorter/sorter.hpp
@@ -80,6 +80,10 @@ public:
   // Returns the resources that have been allocated to this client.
   virtual hashmap<SlaveID, Resources> allocation(const std::string& client) = 0;
 
+  // Returns the clients that have allocations on this slave.
+  virtual hashmap<std::string, Resources> allocation(
+      const SlaveID& slaveId) = 0;
+
   // Returns the given slave's resources that have been allocated to
   // this client.
   virtual Resources allocation(