Repository: mesos Updated Branches: refs/heads/master 83bf5671e -> 46cce8e35
Extended allocator interface to support dynamic weights. Review: https://reviews.apache.org/r/41597/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/815a596f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/815a596f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/815a596f Branch: refs/heads/master Commit: 815a596f77ef3113ccb1b2d3d87ac6a3ff3b9e16 Parents: 83bf567 Author: Yongqiao Wang <[email protected]> Authored: Thu Feb 18 23:50:07 2016 -0800 Committer: Adam B <[email protected]> Committed: Thu Feb 18 23:50:07 2016 -0800 ---------------------------------------------------------------------- include/mesos/master/allocator.hpp | 7 ++++++ include/mesos/mesos.proto | 12 +++++++++ include/mesos/v1/mesos.proto | 12 +++++++++ src/master/allocator/mesos/allocator.hpp | 17 +++++++++++++ src/master/allocator/mesos/hierarchical.cpp | 31 ++++++++++++++++++++++++ src/master/allocator/mesos/hierarchical.hpp | 3 +++ src/master/allocator/sorter/drf/sorter.cpp | 7 ++++++ src/master/allocator/sorter/drf/sorter.hpp | 2 ++ src/master/allocator/sorter/sorter.hpp | 3 +++ src/tests/allocator.hpp | 14 +++++++++++ 10 files changed, 108 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/include/mesos/master/allocator.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp index e163669..a4743c5 100644 --- a/include/mesos/master/allocator.hpp +++ b/include/mesos/master/allocator.hpp @@ -379,6 +379,13 @@ public: */ virtual void removeQuota( const std::string& role) = 0; + + /** + * Updates the weight of each provided role. + * Subsequent allocation calculations will use these updated weights. + */ + virtual void updateWeights( + const std::vector<WeightInfo>& weightInfos) = 0; }; } // namespace allocator { http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/include/mesos/mesos.proto ---------------------------------------------------------------------- diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto index 8047946..636550f 100644 --- a/include/mesos/mesos.proto +++ b/include/mesos/mesos.proto @@ -1764,3 +1764,15 @@ message DiscoveryInfo { optional Ports ports = 6; optional Labels labels = 7; } + + +/** + * Named WeightInfo to indicate resource allocation + * priority between the different roles. + */ +message WeightInfo { + required double weight = 1; + + // Related role name. + optional string role = 2; +} http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/include/mesos/v1/mesos.proto ---------------------------------------------------------------------- diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto index d909e60..1d5af88 100644 --- a/include/mesos/v1/mesos.proto +++ b/include/mesos/v1/mesos.proto @@ -1665,3 +1665,15 @@ message DiscoveryInfo { optional Ports ports = 6; optional Labels labels = 7; } + + +/** + * Named WeightInfo to indicate resource allocation + * priority between the different roles. + */ +message WeightInfo { + required double weight = 1; + + // Related role name. + optional string role = 2; +} http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/src/master/allocator/mesos/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp index 581eaad..64bce0f 100644 --- a/src/master/allocator/mesos/allocator.hpp +++ b/src/master/allocator/mesos/allocator.hpp @@ -149,6 +149,9 @@ public: void removeQuota( const std::string& role); + void updateWeights( + const std::vector<WeightInfo>& weightInfos); + private: MesosAllocator(); MesosAllocator(const MesosAllocator&); // Not copyable. @@ -272,6 +275,9 @@ public: virtual void removeQuota( const std::string& role) = 0; + + virtual void updateWeights( + const std::vector<WeightInfo>& weightInfos) = 0; }; @@ -620,6 +626,17 @@ inline void MesosAllocator<AllocatorProcess>::removeQuota( role); } + +template <typename AllocatorProcess> +inline void MesosAllocator<AllocatorProcess>::updateWeights( + const std::vector<WeightInfo>& weightInfos) +{ + process::dispatch( + process, + &MesosAllocatorProcess::updateWeights, + weightInfos); +} + } // namespace allocator { } // namespace master { } // namespace internal { http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/src/master/allocator/mesos/hierarchical.cpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp index a9d2c23..5ef29f2 100644 --- a/src/master/allocator/mesos/hierarchical.cpp +++ b/src/master/allocator/mesos/hierarchical.cpp @@ -1053,6 +1053,37 @@ void HierarchicalAllocatorProcess::removeQuota( } +void HierarchicalAllocatorProcess::updateWeights( + const vector<WeightInfo>& weightInfos) +{ + CHECK(initialized); + + bool rebalance = false; + + // Update the weight for each specified role. + foreach (const WeightInfo& weightInfo, weightInfos) { + CHECK(weightInfo.has_role()); + weights[weightInfo.role()] = weightInfo.weight(); + + if (quotas.contains(weightInfo.role())) { + quotaRoleSorter->update(weightInfo.role(), weightInfo.weight()); + } + + if (roleSorter->contains(weightInfo.role())) { + rebalance = true; + roleSorter->update(weightInfo.role(), weightInfo.weight()); + } + } + + // If at least one of the updated roles has registered frameworks, + // then trigger the allocation explicitly in order to promptly + // react to the operator's request. + if (rebalance) { + allocate(); + } +} + + void HierarchicalAllocatorProcess::pause() { if (!paused) { http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/src/master/allocator/mesos/hierarchical.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index 20d7ceb..0d39d3f 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -187,6 +187,9 @@ public: void removeQuota( const std::string& role); + void updateWeights( + const std::vector<WeightInfo>& weightInfos); + protected: // Useful typedefs for dispatch/delay/defer to self()/this. typedef HierarchicalAllocatorProcess Self; http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/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 18797e4..9e863dd 100644 --- a/src/master/allocator/sorter/drf/sorter.cpp +++ b/src/master/allocator/sorter/drf/sorter.cpp @@ -49,6 +49,13 @@ void DRFSorter::add(const string& name, double weight) } +void DRFSorter::update(const string& name, double weight) +{ + CHECK(weights.contains(name)); + weights[name] = weight; +} + + void DRFSorter::remove(const string& name) { set<Client, DRFComparator>::iterator it = find(name); http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/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 4669149..46b2a9c 100644 --- a/src/master/allocator/sorter/drf/sorter.hpp +++ b/src/master/allocator/sorter/drf/sorter.hpp @@ -65,6 +65,8 @@ public: virtual void add(const std::string& name, double weight = 1); + virtual void update(const std::string& name, double weight); + virtual void remove(const std::string& name); virtual void activate(const std::string& name); http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/src/master/allocator/sorter/sorter.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/sorter/sorter.hpp b/src/master/allocator/sorter/sorter.hpp index a0a779b..ba91a38 100644 --- a/src/master/allocator/sorter/sorter.hpp +++ b/src/master/allocator/sorter/sorter.hpp @@ -44,6 +44,9 @@ public: // may be a user or a framework. virtual void add(const std::string& client, double weight = 1) = 0; + // Update weight of a client. + virtual void update(const std::string& client, double weight) = 0; + // Removes a client. virtual void remove(const std::string& client) = 0; http://git-wip-us.apache.org/repos/asf/mesos/blob/815a596f/src/tests/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp index 206e9ac..4081193 100644 --- a/src/tests/allocator.hpp +++ b/src/tests/allocator.hpp @@ -196,6 +196,12 @@ ACTION_P(InvokeRemoveQuota, allocator) } +ACTION_P(InvokeUpdateWeights, allocator) +{ + allocator->real->updateWeights(arg0); +} + + template <typename T = master::allocator::HierarchicalDRFAllocator> mesos::master::allocator::Allocator* createAllocator() { @@ -342,6 +348,11 @@ public: .WillByDefault(InvokeRemoveQuota(this)); EXPECT_CALL(*this, removeQuota(_)) .WillRepeatedly(DoDefault()); + + ON_CALL(*this, updateWeights(_)) + .WillByDefault(InvokeUpdateWeights(this)); + EXPECT_CALL(*this, updateWeights(_)) + .WillRepeatedly(DoDefault()); } virtual ~TestAllocator() {} @@ -449,6 +460,9 @@ public: MOCK_METHOD1(removeQuota, void( const std::string&)); + MOCK_METHOD1(updateWeights, void( + const std::vector<WeightInfo>&)); + process::Owned<mesos::master::allocator::Allocator> real; };
