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 2017/12/12 01:04:20 UTC
mesos git commit: Tracked resource reservations in the allocator.
Repository: mesos
Updated Branches:
refs/heads/master 96fe7d9c3 -> 04ea195de
Tracked resource reservations in the allocator.
Resource reservations need to be tracked to make
sure quota limit will not be exceeded in the presence
of resource reservations.
Review: https://reviews.apache.org/r/64303/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/04ea195d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/04ea195d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/04ea195d
Branch: refs/heads/master
Commit: 04ea195de3c010a95033dce20a573746a7a87d0e
Parents: 96fe7d9
Author: Meng Zhu <mz...@mesosphere.io>
Authored: Mon Dec 11 16:45:49 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Dec 11 17:03:48 2017 -0800
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 48 ++++++++++++++++++++++++
src/master/allocator/mesos/hierarchical.hpp | 28 ++++++++++++++
2 files changed, 76 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/04ea195d/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 9d8b671..49a3b9e 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -522,6 +522,8 @@ void HierarchicalAllocatorProcess::addSlave(
slave.maintenance = Slave::Maintenance(unavailability.get());
}
+ trackReservations(total.reservations());
+
roleSorter->add(slaveId, total);
// See comment at `quotaRoleSorter` declaration regarding non-revocable.
@@ -594,6 +596,8 @@ void HierarchicalAllocatorProcess::removeSlave(
// See comment at `quotaRoleSorter` declaration regarding non-revocable.
quotaRoleSorter->remove(slaveId, slaves.at(slaveId).total.nonRevocable());
+ untrackReservations(slaves.at(slaveId).total.reservations());
+
slaves.erase(slaveId);
allocationCandidates.erase(slaveId);
@@ -2395,6 +2399,42 @@ void HierarchicalAllocatorProcess::untrackFrameworkUnderRole(
}
+void HierarchicalAllocatorProcess::trackReservations(
+ const hashmap<std::string, Resources>& reservations)
+{
+ foreachpair (const string& role,
+ const Resources& resources, reservations) {
+ // We remove the static reservation metadata here via `toUnreserved()`.
+ const Resources scalarQuantitesToTrack =
+ resources.createStrippedScalarQuantity().toUnreserved();
+
+ reservationScalarQuantities[role] += scalarQuantitesToTrack;
+ }
+}
+
+
+void HierarchicalAllocatorProcess::untrackReservations(
+ const hashmap<std::string, Resources>& reservations)
+{
+ foreachpair (const string& role,
+ const Resources& resources, reservations) {
+ CHECK(reservationScalarQuantities.contains(role));
+ Resources& currentReservationQuantity =
+ reservationScalarQuantities.at(role);
+
+ // We remove the static reservation metadata here via `toUnreserved()`.
+ const Resources scalarQuantitesToUntrack =
+ resources.createStrippedScalarQuantity().toUnreserved();
+ CHECK(currentReservationQuantity.contains(scalarQuantitesToUntrack));
+ currentReservationQuantity -= scalarQuantitesToUntrack;
+
+ if (currentReservationQuantity.empty()) {
+ reservationScalarQuantities.erase(role);
+ }
+ }
+}
+
+
bool HierarchicalAllocatorProcess::updateSlaveTotal(
const SlaveID& slaveId,
const Resources& total)
@@ -2411,6 +2451,14 @@ bool HierarchicalAllocatorProcess::updateSlaveTotal(
slave.total = total;
+ hashmap<std::string, Resources> oldReservations = oldTotal.reservations();
+ hashmap<std::string, Resources> newReservations = total.reservations();
+
+ if (oldReservations != newReservations) {
+ untrackReservations(oldReservations);
+ trackReservations(newReservations);
+ }
+
// Currently `roleSorter` and `quotaRoleSorter`, being the root-level
// sorters, maintain all of `slaves[slaveId].total` (or the `nonRevocable()`
// portion in the case of `quotaRoleSorter`) in their own totals (which
http://git-wip-us.apache.org/repos/asf/mesos/blob/04ea195d/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index aae6396..37d2df5 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -453,6 +453,14 @@ protected:
// change in the future.
hashmap<std::string, Quota> quotas;
+ // Aggregated resource reservations on all agents tied to a
+ // particular role, if any. These are stripped scalar quantities
+ // that contain no meta-data. Used for accounting resource
+ // reservations for quota limit.
+ //
+ // Only roles with non-empty reservations will be stored in the map.
+ hashmap<std::string, Resources> reservationScalarQuantities;
+
// Slaves to send offers for.
Option<hashset<std::string>> whitelist;
@@ -546,6 +554,26 @@ private:
const FrameworkID& frameworkId,
const std::string& role);
+ // `trackReservations` and `untrackReservations` are helpers
+ // to track role resource reservations. We need to keep
+ // track of reservations to enforce role quota limit
+ // in the presence of unallocated reservations. See MESOS-4527.
+ //
+ // TODO(mzhu): Ideally, we want these helpers to instead track the
+ // reservations as *allocated* in the sorters even when the
+ // reservations have not been allocated yet. This will help to:
+ //
+ // (1) Solve the fairness issue when roles with unallocated
+ // reservations may game the allocator (See MESOS-8299).
+ //
+ // (2) Simplify the quota enforcement logic -- the allocator
+ // would no longer need to track reservations separately.
+ void trackReservations(
+ const hashmap<std::string, Resources>& reservations);
+
+ void untrackReservations(
+ const hashmap<std::string, Resources>& reservations);
+
// Helper to update the agent's total resources maintained in the allocator
// and the role and quota sorters (whose total resources match the agent's
// total resources). Returns true iff the stored agent total was changed.