You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ne...@apache.org on 2017/02/18 02:30:12 UTC
[2/4] mesos git commit: Const-ified several methods in the sorter
interface.
Const-ified several methods in the sorter interface.
Review: https://reviews.apache.org/r/56350
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7ddfce62
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7ddfce62
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7ddfce62
Branch: refs/heads/master
Commit: 7ddfce62a21fe5eb40d3968f4ccae8c5fb32d4a1
Parents: c07f928
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Feb 6 13:38:27 2017 -0800
Committer: Neil Conway <ne...@gmail.com>
Committed: Fri Feb 17 18:30:03 2017 -0800
----------------------------------------------------------------------
src/master/allocator/sorter/drf/sorter.cpp | 26 ++++++++++++++-----------
src/master/allocator/sorter/drf/sorter.hpp | 14 ++++++++-----
src/master/allocator/sorter/sorter.hpp | 19 +++++++++---------
3 files changed, 34 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7ddfce62/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 ae49fcd..cecf08b 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -234,23 +234,25 @@ void DRFSorter::update(
}
-const hashmap<SlaveID, Resources>& DRFSorter::allocation(const string& name)
+const hashmap<SlaveID, Resources>& DRFSorter::allocation(
+ const string& name) const
{
CHECK(contains(name));
- return allocations[name].resources;
+ return allocations.at(name).resources;
}
-const Resources& DRFSorter::allocationScalarQuantities(const string& name)
+const Resources& DRFSorter::allocationScalarQuantities(
+ const string& name) const
{
CHECK(contains(name));
- return allocations[name].scalarQuantities;
+ return allocations.at(name).scalarQuantities;
}
-hashmap<string, Resources> DRFSorter::allocation(const SlaveID& slaveId)
+hashmap<string, Resources> DRFSorter::allocation(const SlaveID& slaveId) const
{
// 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
@@ -270,12 +272,14 @@ hashmap<string, Resources> DRFSorter::allocation(const SlaveID& slaveId)
}
-Resources DRFSorter::allocation(const string& name, const SlaveID& slaveId)
+Resources DRFSorter::allocation(
+ const string& name,
+ const SlaveID& slaveId) const
{
CHECK(contains(name));
- if (allocations[name].resources.contains(slaveId)) {
- return allocations[name].resources[slaveId];
+ if (allocations.at(name).resources.contains(slaveId)) {
+ return allocations.at(name).resources.at(slaveId);
}
return Resources();
@@ -294,8 +298,8 @@ void DRFSorter::unallocated(
const Resources& resources)
{
CHECK(contains(name));
- CHECK(allocations[name].resources.contains(slaveId));
- CHECK(allocations[name].resources[slaveId].contains(resources));
+ CHECK(allocations.at(name).resources.contains(slaveId));
+ CHECK(allocations.at(name).resources.at(slaveId).contains(resources));
allocations[name].resources[slaveId] -= resources;
@@ -427,7 +431,7 @@ bool DRFSorter::contains(const string& name) const
}
-int DRFSorter::count()
+int DRFSorter::count() const
{
return allocations.size();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/7ddfce62/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 04d5ffc..9063498 100644
--- a/src/master/allocator/sorter/drf/sorter.hpp
+++ b/src/master/allocator/sorter/drf/sorter.hpp
@@ -105,13 +105,17 @@ public:
const Resources& resources);
virtual const hashmap<SlaveID, Resources>& allocation(
- const std::string& name);
+ const std::string& name) const;
- virtual const Resources& allocationScalarQuantities(const std::string& name);
+ virtual const Resources& allocationScalarQuantities(
+ const std::string& name) const;
- virtual hashmap<std::string, Resources> allocation(const SlaveID& slaveId);
+ virtual hashmap<std::string, Resources> allocation(
+ const SlaveID& slaveId) const;
- virtual Resources allocation(const std::string& name, const SlaveID& slaveId);
+ virtual Resources allocation(
+ const std::string& name,
+ const SlaveID& slaveId) const;
virtual const Resources& totalScalarQuantities() const;
@@ -123,7 +127,7 @@ public:
virtual bool contains(const std::string& name) const;
- virtual int count();
+ virtual int count() const;
private:
// Recalculates the share for the client and moves
http://git-wip-us.apache.org/repos/asf/mesos/blob/7ddfce62/src/master/allocator/sorter/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/sorter.hpp b/src/master/allocator/sorter/sorter.hpp
index 737b13f..b3029fc 100644
--- a/src/master/allocator/sorter/sorter.hpp
+++ b/src/master/allocator/sorter/sorter.hpp
@@ -60,7 +60,8 @@ public:
// may be a user or a framework.
virtual void add(const std::string& client, double weight = 1) = 0;
- // Update weight of a client.
+ // Updates the weight of a client. The client must have previously
+ // be added to the sorter, but it may currently be inactive.
virtual void update(const std::string& client, double weight) = 0;
// Removes a client.
@@ -81,7 +82,7 @@ public:
const Resources& resources) = 0;
// Updates a portion of the allocation for the client, in order to
- // augment the resources with additional metadata (e.g., volumes)
+ // augment the resources with additional metadata (e.g., volumes).
// This means that the new allocation must not affect the static
// roles, or the overall quantities of resources!
virtual void update(
@@ -98,23 +99,23 @@ public:
// Returns the resources that have been allocated to this client.
virtual const hashmap<SlaveID, Resources>& allocation(
- const std::string& client) = 0;
+ const std::string& client) const = 0;
// Returns the total scalar resource quantities that are allocated to
// this client. This omits metadata about dynamic reservations and
// persistent volumes; see `Resources::createStrippedScalarQuantity`.
virtual const Resources& allocationScalarQuantities(
- const std::string& client) = 0;
+ const std::string& client) const = 0;
// Returns the clients that have allocations on this slave.
virtual hashmap<std::string, Resources> allocation(
- const SlaveID& slaveId) = 0;
+ const SlaveID& slaveId) const = 0;
// Returns the given slave's resources that have been allocated to
// this client.
virtual Resources allocation(
const std::string& client,
- const SlaveID& slaveId) = 0;
+ const SlaveID& slaveId) const = 0;
// Returns the total scalar resource quantities in this sorter. This
// omits metadata about dynamic reservations and persistent volumes; see
@@ -133,12 +134,12 @@ public:
virtual std::vector<std::string> sort() = 0;
// Returns true if this Sorter contains the specified client,
- // either active or deactivated.
+ // which may be active or inactive.
virtual bool contains(const std::string& client) const = 0;
// Returns the number of clients this Sorter contains,
- // either active or deactivated.
- virtual int count() = 0;
+ // either active or inactive.
+ virtual int count() const = 0;
};
} // namespace allocator {