You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2017/11/30 17:35:59 UTC
[6/8] 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/8c0f8a40
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8c0f8a40
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8c0f8a40
Branch: refs/heads/master
Commit: 8c0f8a40b13fba93b881da02c4b33a7d1c9f01ee
Parents: 42c14e1
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Thu Nov 30 17:03:45 2017 +0100
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Thu Nov 30 18:33:58 2017 +0100
----------------------------------------------------------------------
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/8c0f8a40/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 5ce9cea..6b0be6a 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -287,20 +287,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;
@@ -523,41 +510,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();
@@ -2419,6 +2372,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/8c0f8a40/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 2c4832b..fd604c9 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -541,6 +541,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);
};