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/05/03 00:00:58 UTC
[02/20] mesos git commit: Introduced an allocator helper function to
track used resources.
Introduced an allocator helper function to track used resources.
This patch introduces a helper to track allocated resources. It
encapsulates all needed updates to the various sorters for
reusability.
Review: https://reviews.apache.org/r/64136/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e2d52d36
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e2d52d36
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e2d52d36
Branch: refs/heads/1.4.x
Commit: e2d52d362bde8ebd1a7f8bed79196842afbf2a38
Parents: 5adc12e
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Thu Nov 30 17:03:45 2017 +0100
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Wed May 2 16:43:19 2018 -0700
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 93 +++++++++++-------------
src/master/allocator/mesos/hierarchical.hpp | 5 ++
2 files changed, 49 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e2d52d36/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index f021c34..dc6f27f 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -284,20 +284,7 @@ void HierarchicalAllocatorProcess::addFramework(
continue;
}
- hashmap<string, Resources> allocations = resources.allocations();
-
- foreachpair (const string& role, const Resources& allocation, allocations) {
- roleSorter->allocated(role, slaveId, allocation);
- frameworkSorters.at(role)->add(slaveId, allocation);
- frameworkSorters.at(role)->allocated(
- frameworkId.value(), slaveId, allocation);
-
- if (quotas.contains(role)) {
- // See comment at `quotaRoleSorter` declaration
- // regarding non-revocable.
- quotaRoleSorter->allocated(role, slaveId, allocation.nonRevocable());
- }
- }
+ trackAllocatedResources(slaveId, {{frameworkId, resources}});
}
LOG(INFO) << "Added framework " << frameworkId;
@@ -516,41 +503,7 @@ void HierarchicalAllocatorProcess::addSlave(
// See comment at `quotaRoleSorter` declaration regarding non-revocable.
quotaRoleSorter->add(slaveId, total.nonRevocable());
- // Update the allocation for each framework.
- foreachpair (const FrameworkID& frameworkId,
- const Resources& used_,
- used) {
- if (!frameworks.contains(frameworkId)) {
- continue;
- }
-
- foreachpair (const string& role,
- const Resources& allocated,
- used_.allocations()) {
- // The framework has resources allocated to this role but it may
- // or may not be subscribed to the role. Either way, we need to
- // track the framework under the role.
- if (!isFrameworkTrackedUnderRole(frameworkId, role)) {
- trackFrameworkUnderRole(frameworkId, role);
- }
-
- // TODO(bmahler): Validate that the reserved resources have the
- // framework's role.
- CHECK(roleSorter->contains(role));
- CHECK(frameworkSorters.contains(role));
- CHECK(frameworkSorters.at(role)->contains(frameworkId.value()));
-
- roleSorter->allocated(role, slaveId, allocated);
- frameworkSorters.at(role)->add(slaveId, allocated);
- frameworkSorters.at(role)->allocated(
- frameworkId.value(), slaveId, allocated);
-
- if (quotas.contains(role)) {
- // See comment at `quotaRoleSorter` declaration regarding non-revocable.
- quotaRoleSorter->allocated(role, slaveId, allocated.nonRevocable());
- }
- }
- }
+ trackAllocatedResources(slaveId, used);
slaves[slaveId] = Slave();
@@ -2417,6 +2370,48 @@ bool HierarchicalAllocatorProcess::isRemoteSlave(const Slave& slave) const
return masterRegion != slaveRegion;
}
+
+void HierarchicalAllocatorProcess::trackAllocatedResources(
+ const SlaveID& slaveId,
+ const hashmap<FrameworkID, Resources>& used)
+{
+ // Update the allocation for each framework.
+ foreachpair (const FrameworkID& frameworkId,
+ const Resources& used_,
+ used) {
+ if (!frameworks.contains(frameworkId)) {
+ continue;
+ }
+
+ foreachpair (const string& role,
+ const Resources& allocated,
+ used_.allocations()) {
+ // The framework has resources allocated to this role but it may
+ // or may not be subscribed to the role. Either way, we need to
+ // track the framework under the role.
+ if (!isFrameworkTrackedUnderRole(frameworkId, role)) {
+ trackFrameworkUnderRole(frameworkId, role);
+ }
+
+ // TODO(bmahler): Validate that the reserved resources have the
+ // framework's role.
+ CHECK(roleSorter->contains(role));
+ CHECK(frameworkSorters.contains(role));
+ CHECK(frameworkSorters.at(role)->contains(frameworkId.value()));
+
+ roleSorter->allocated(role, slaveId, allocated);
+ frameworkSorters.at(role)->add(slaveId, allocated);
+ frameworkSorters.at(role)->allocated(
+ frameworkId.value(), slaveId, allocated);
+
+ if (quotas.contains(role)) {
+ // See comment at `quotaRoleSorter` declaration regarding non-revocable.
+ quotaRoleSorter->allocated(role, slaveId, allocated.nonRevocable());
+ }
+ }
+ }
+}
+
} // namespace internal {
} // namespace allocator {
} // namespace master {
http://git-wip-us.apache.org/repos/asf/mesos/blob/e2d52d36/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index c234605..ececf31 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -538,6 +538,11 @@ private:
// different region than the master. This can only be the case if
// the agent and the master are both configured with a fault domain.
bool isRemoteSlave(const Slave& slave) const;
+
+ // Helper to track used resources on an agent.
+ void trackAllocatedResources(
+ const SlaveID& slaveId,
+ const hashmap<FrameworkID, Resources>& used);
};