You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2017/04/28 03:16:11 UTC
[1/3] mesos git commit: Made the activation of a client in
`Sorter::add` explicit.
Repository: mesos
Updated Branches:
refs/heads/master 61823d33f -> 72752fc6d
Made the activation of a client in `Sorter::add` explicit.
Review: https://reviews.apache.org/r/58687/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/88e21892
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/88e21892
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/88e21892
Branch: refs/heads/master
Commit: 88e218928f20b7f52b1c8bb359a8927d562bf4e9
Parents: 61823d3
Author: Michael Park <mp...@apache.org>
Authored: Thu Apr 27 20:14:52 2017 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Thu Apr 27 20:14:52 2017 -0700
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 8 +++
src/master/allocator/sorter/drf/sorter.cpp | 3 +-
src/master/allocator/sorter/sorter.hpp | 5 +-
src/tests/sorter_tests.cpp | 82 ++++++++++++++++++++++++
4 files changed, 94 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/88e21892/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 984a0a4..968fec0 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -241,6 +241,9 @@ void HierarchicalAllocatorProcess::addFramework(
foreach (const string& role, framework.roles) {
trackFrameworkUnderRole(frameworkId, role);
+
+ CHECK(frameworkSorters.contains(role));
+ frameworkSorters.at(role)->activate(frameworkId.value());
}
// TODO(bmahler): Validate that the reserved resources have the
@@ -470,6 +473,9 @@ void HierarchicalAllocatorProcess::addSlave(
// track the framework under the role.
if (!isFrameworkTrackedUnderRole(frameworkId, role)) {
trackFrameworkUnderRole(frameworkId, role);
+
+ CHECK(frameworkSorters.contains(role));
+ frameworkSorters.at(role)->activate(frameworkId.value());
}
// TODO(bmahler): Validate that the reserved resources have the
@@ -1277,6 +1283,7 @@ void HierarchicalAllocatorProcess::setQuota(
// allocation group.
quotas[role] = quota;
quotaRoleSorter->add(role);
+ quotaRoleSorter->activate(role);
// Copy allocation information for the quota'ed role.
if (roleSorter->contains(role)) {
@@ -2219,6 +2226,7 @@ void HierarchicalAllocatorProcess::trackFrameworkUnderRole(
roles[role] = {};
CHECK(!roleSorter->contains(role));
roleSorter->add(role);
+ roleSorter->activate(role);
CHECK(!frameworkSorters.contains(role));
frameworkSorters.insert({role, Owned<Sorter>(frameworkSorterFactory())});
http://git-wip-us.apache.org/repos/asf/mesos/blob/88e21892/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 a8b35c4..26b77f5 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -150,10 +150,9 @@ void DRFSorter::add(const string& clientPath)
// `current` is the newly created node associated with the last
// element of the path. `current` should be an inactive node with no
- // children; activate it now.
+ // children.
CHECK(current->children.empty());
CHECK(!current->active);
- current->active = true;
// Add a new entry to the lookup table. The full path of the newly
// added client should not already exist in `clients`.
http://git-wip-us.apache.org/repos/asf/mesos/blob/88e21892/src/master/allocator/sorter/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/sorter.hpp b/src/master/allocator/sorter/sorter.hpp
index 0c9f172..2c6e162 100644
--- a/src/master/allocator/sorter/sorter.hpp
+++ b/src/master/allocator/sorter/sorter.hpp
@@ -56,8 +56,9 @@ public:
virtual void initialize(
const Option<std::set<std::string>>& fairnessExcludeResourceNames) = 0;
- // Adds a client to allocate resources to. A client
- // may be a user or a framework.
+ // Adds a client to allocate resources to.
+ // A client may be a user or a framework.
+ // This function will not activate the client.
virtual void add(const std::string& client) = 0;
// Removes a client.
http://git-wip-us.apache.org/repos/asf/mesos/blob/88e21892/src/tests/sorter_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp
index 3d183bf..8e7ff79 100644
--- a/src/tests/sorter_tests.cpp
+++ b/src/tests/sorter_tests.cpp
@@ -54,11 +54,13 @@ TEST(SorterTest, DRFSorter)
EXPECT_EQ(vector<string>({}), sorter.sort());
sorter.add("a");
+ sorter.activate("a");
Resources aResources = Resources::parse("cpus:5;mem:5").get();
sorter.allocated("a", slaveId, aResources);
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.add("b");
+ sorter.activate("b");
sorter.allocated("b", slaveId, bResources);
// shares: a = .05, b = .06
@@ -66,10 +68,12 @@ TEST(SorterTest, DRFSorter)
Resources cResources = Resources::parse("cpus:1;mem:1").get();
sorter.add("c");
+ sorter.activate("c");
sorter.allocated("c", slaveId, cResources);
Resources dResources = Resources::parse("cpus:3;mem:1").get();
sorter.add("d");
+ sorter.activate("d");
sorter.allocated("d", slaveId, dResources);
// shares: a = .05, b = .06, c = .01, d = .03
@@ -85,6 +89,7 @@ TEST(SorterTest, DRFSorter)
Resources eResources = Resources::parse("cpus:1;mem:5").get();
sorter.add("e");
+ sorter.activate("e");
sorter.allocated("e", slaveId, eResources);
Resources removedResources = Resources::parse("cpus:50;mem:0").get();
@@ -100,6 +105,7 @@ TEST(SorterTest, DRFSorter)
Resources fResources = Resources::parse("cpus:5;mem:1").get();
sorter.add("f");
+ sorter.activate("f");
sorter.allocated("f", slaveId, fResources);
Resources cResources2 = Resources::parse("cpus:0;mem:15").get();
@@ -138,10 +144,12 @@ TEST(SorterTest, WDRFSorter)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("a");
+ sorter.activate("a");
sorter.allocated("a", slaveId, Resources::parse("cpus:5;mem:5").get());
sorter.add("b");
+ sorter.activate("b");
sorter.updateWeight("b", 2);
sorter.allocated("b", slaveId, Resources::parse("cpus:6;mem:6").get());
@@ -149,12 +157,14 @@ TEST(SorterTest, WDRFSorter)
EXPECT_EQ(vector<string>({"b", "a"}), sorter.sort());
sorter.add("c");
+ sorter.activate("c");
sorter.allocated("c", slaveId, Resources::parse("cpus:4;mem:4").get());
// shares: a = .05, b = .03, c = .04
EXPECT_EQ(vector<string>({"b", "c", "a"}), sorter.sort());
sorter.add("d");
+ sorter.activate("d");
sorter.updateWeight("d", 10);
sorter.allocated("d", slaveId, Resources::parse("cpus:10;mem:20").get());
@@ -171,6 +181,7 @@ TEST(SorterTest, WDRFSorter)
EXPECT_EQ(vector<string>({"c", "d", "a"}), sorter.sort());
sorter.add("e");
+ sorter.activate("e");
sorter.updateWeight("e", 0.1);
sorter.allocated("e", slaveId, Resources::parse("cpus:1;mem:1").get());
@@ -195,9 +206,11 @@ TEST(SorterTest, WDRFSorterUpdateWeight)
sorter.add(slaveId, totalResources);
sorter.add("a");
+ sorter.activate("a");
sorter.allocated("a", slaveId, Resources::parse("cpus:5;mem:5").get());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated("b", slaveId, Resources::parse("cpus:6;mem:6").get());
// shares: a = .05, b = .06
@@ -229,6 +242,11 @@ TEST(SorterTest, CountAllocations)
sorter.add("c");
sorter.add("d");
sorter.add("e");
+ sorter.activate("a");
+ sorter.activate("b");
+ sorter.activate("c");
+ sorter.activate("d");
+ sorter.activate("e");
// Everyone is allocated the same amount of resources; "c" gets
// three distinct allocations, "d" gets two, and all other clients
@@ -302,12 +320,14 @@ TEST(SorterTest, ShallowHierarchy)
sorter.add(slaveId, totalResources);
sorter.add("a/a");
+ sorter.activate("a/a");
Resources aResources = Resources::parse("cpus:5;mem:5").get();
sorter.allocated("a/a", slaveId, aResources);
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.add("b/b");
+ sorter.activate("b/b");
sorter.allocated("b/b", slaveId, bResources);
// shares: a/a = .05, b/b = .06
@@ -315,10 +335,12 @@ TEST(SorterTest, ShallowHierarchy)
Resources cResources = Resources::parse("cpus:1;mem:1").get();
sorter.add("c/c");
+ sorter.activate("c/c");
sorter.allocated("c/c", slaveId, cResources);
Resources dResources = Resources::parse("cpus:3;mem:1").get();
sorter.add("d/d");
+ sorter.activate("d/d");
sorter.allocated("d/d", slaveId, dResources);
// shares: a/a = .05, b/b = .06, c/c = .01, d/d = .03
@@ -334,6 +356,7 @@ TEST(SorterTest, ShallowHierarchy)
Resources eResources = Resources::parse("cpus:1;mem:5").get();
sorter.add("e/e");
+ sorter.activate("e/e");
sorter.allocated("e/e", slaveId, eResources);
Resources removedResources = Resources::parse("cpus:50;mem:0").get();
@@ -349,6 +372,7 @@ TEST(SorterTest, ShallowHierarchy)
Resources fResources = Resources::parse("cpus:5;mem:1").get();
sorter.add("f/f");
+ sorter.activate("f/f");
sorter.allocated("f/f", slaveId, fResources);
Resources cResources2 = Resources::parse("cpus:0;mem:15").get();
@@ -391,11 +415,13 @@ TEST(SorterTest, DeepHierarchy)
sorter.add(slaveId, totalResources);
sorter.add("a/a/a/a/a");
+ sorter.activate("a/a/a/a/a");
Resources aResources = Resources::parse("cpus:5;mem:5").get();
sorter.allocated("a/a/a/a/a", slaveId, aResources);
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.add("b/b/b/b");
+ sorter.activate("b/b/b/b");
sorter.allocated("b/b/b/b", slaveId, bResources);
// shares: a/a/a/a/a = .05, b/b/b/b = .06
@@ -403,10 +429,12 @@ TEST(SorterTest, DeepHierarchy)
Resources cResources = Resources::parse("cpus:1;mem:1").get();
sorter.add("c/c/c");
+ sorter.activate("c/c/c");
sorter.allocated("c/c/c", slaveId, cResources);
Resources dResources = Resources::parse("cpus:3;mem:1").get();
sorter.add("d/d");
+ sorter.activate("d/d");
sorter.allocated("d/d", slaveId, dResources);
// shares: a/a/a/a/a = .05, b/b/b/b = .06, c/c/c = .01, d/d = .03
@@ -423,6 +451,7 @@ TEST(SorterTest, DeepHierarchy)
Resources eResources = Resources::parse("cpus:1;mem:5").get();
sorter.add("e/e/e/e/e/e");
+ sorter.activate("e/e/e/e/e/e");
sorter.allocated("e/e/e/e/e/e", slaveId, eResources);
Resources removedResources = Resources::parse("cpus:50;mem:0").get();
@@ -439,6 +468,7 @@ TEST(SorterTest, DeepHierarchy)
Resources fResources = Resources::parse("cpus:5;mem:1").get();
sorter.add("f/f");
+ sorter.activate("f/f");
sorter.allocated("f/f", slaveId, fResources);
Resources cResources2 = Resources::parse("cpus:0;mem:15").get();
@@ -483,6 +513,9 @@ TEST(SorterTest, HierarchicalAllocation)
sorter.add("a");
sorter.add("b/c");
sorter.add("b/d");
+ sorter.activate("a");
+ sorter.activate("b/c");
+ sorter.activate("b/d");
EXPECT_EQ(3, sorter.count());
EXPECT_TRUE(sorter.contains("a"));
@@ -529,6 +562,7 @@ TEST(SorterTest, HierarchicalAllocation)
EXPECT_EQ(vector<string>({"b/d", "b/c", "a"}), sorter.sort());
sorter.add("b/e/f");
+ sorter.activate("b/e/f");
EXPECT_FALSE(sorter.contains("b/e"));
EXPECT_TRUE(sorter.contains("b/e/f"));
@@ -561,6 +595,7 @@ TEST(SorterTest, HierarchicalAllocation)
EXPECT_EQ(vector<string>({"b/c", "b/d", "a"}), sorter.sort());
sorter.add("b/e/f");
+ sorter.activate("b/e/f");
sorter.allocated("b/e/f", slaveId, fResources);
// Shares: b/c = 0.01, b/d = 0.03, b/e/f = 0.035, a = 0.08.
@@ -582,10 +617,12 @@ TEST(SorterTest, AddChildToLeaf)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("a");
+ sorter.activate("a");
sorter.allocated(
"a", slaveId, Resources::parse("cpus:10;mem:10").get());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated(
"b", slaveId, Resources::parse("cpus:6;mem:6").get());
@@ -596,6 +633,7 @@ TEST(SorterTest, AddChildToLeaf)
// sibling) against "a/c".
sorter.add("a/c");
+ sorter.activate("a/c");
sorter.allocated(
"a/c", slaveId, Resources::parse("cpus:5;mem:5").get());
@@ -613,6 +651,7 @@ TEST(SorterTest, AddChildToLeaf)
// Re-add the "a" client with the same resources. The client order
// should revert to its previous value.
sorter.add("a");
+ sorter.activate("a");
sorter.allocated(
"a", slaveId, Resources::parse("cpus:10;mem:10").get());
@@ -649,22 +688,26 @@ TEST(SorterTest, AddChildToInternal)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("x/a");
+ sorter.activate("x/a");
sorter.allocated(
"x/a", slaveId, Resources::parse("cpus:10;mem:10").get());
sorter.add("x/b");
+ sorter.activate("x/b");
sorter.allocated(
"x/b", slaveId, Resources::parse("cpus:6;mem:6").get());
EXPECT_EQ(vector<string>({"x/b", "x/a"}), sorter.sort());
sorter.add("x");
+ sorter.activate("x");
sorter.allocated(
"x", slaveId, Resources::parse("cpus:7;mem:7").get());
EXPECT_EQ(vector<string>({"x/b", "x", "x/a"}), sorter.sort());
sorter.add("z");
+ sorter.activate("z");
sorter.allocated(
"z", slaveId, Resources::parse("cpus:20;mem:20").get());
@@ -688,10 +731,12 @@ TEST(SorterTest, AddChildToInactiveLeaf)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("a");
+ sorter.activate("a");
sorter.allocated(
"a", slaveId, Resources::parse("cpus:10;mem:10").get());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated(
"b", slaveId, Resources::parse("cpus:6;mem:6").get());
@@ -700,6 +745,7 @@ TEST(SorterTest, AddChildToInactiveLeaf)
EXPECT_EQ(vector<string>({"b"}), sorter.sort());
sorter.add("a/c");
+ sorter.activate("a/c");
sorter.allocated(
"a/c", slaveId, Resources::parse("cpus:5;mem:5").get());
@@ -720,14 +766,17 @@ TEST(SorterTest, RemoveLeafCollapseParent)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("a");
+ sorter.activate("a");
sorter.allocated(
"a", slaveId, Resources::parse("cpus:10;mem:10").get());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated(
"b", slaveId, Resources::parse("cpus:6;mem:6").get());
sorter.add("a/c");
+ sorter.activate("a/c");
sorter.allocated(
"a/c", slaveId, Resources::parse("cpus:5;mem:5").get());
@@ -752,14 +801,17 @@ TEST(SorterTest, RemoveLeafCollapseParentInactive)
sorter.add(slaveId, Resources::parse("cpus:100;mem:100").get());
sorter.add("a");
+ sorter.activate("a");
sorter.allocated(
"a", slaveId, Resources::parse("cpus:10;mem:10").get());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated(
"b", slaveId, Resources::parse("cpus:6;mem:6").get());
sorter.add("a/c");
+ sorter.activate("a/c");
sorter.allocated(
"a/c", slaveId, Resources::parse("cpus:5;mem:5").get());
@@ -789,6 +841,8 @@ TEST(SorterTest, ChangeWeightOnSubtree)
sorter.add("a/x");
sorter.add("b/y");
+ sorter.activate("a/x");
+ sorter.activate("b/y");
EXPECT_EQ(vector<string>({"a/x", "b/y"}), sorter.sort());
@@ -801,18 +855,21 @@ TEST(SorterTest, ChangeWeightOnSubtree)
EXPECT_EQ(vector<string>({"b/y", "a/x"}), sorter.sort());
sorter.add("b/z");
+ sorter.activate("b/z");
sorter.allocated(
"b/z", slaveId, Resources::parse("cpus:5;mem:5").get());
EXPECT_EQ(vector<string>({"b/z", "b/y", "a/x"}), sorter.sort());
sorter.add("b");
+ sorter.activate("b");
sorter.allocated(
"b", slaveId, Resources::parse("cpus:4;mem:4").get());
EXPECT_EQ(vector<string>({"a/x", "b", "b/z", "b/y"}), sorter.sort());
sorter.add("a/zz");
+ sorter.activate("a/zz");
sorter.allocated(
"a/zz", slaveId, Resources::parse("cpus:2;mem:2").get());
@@ -832,6 +889,8 @@ TEST(SorterTest, SplitResourceShares)
sorter.add("a");
sorter.add("b");
+ sorter.activate("a");
+ sorter.activate("b");
Resource disk1 = Resources::parse("disk", "5", "*").get();
disk1.mutable_disk()->mutable_persistence()->set_id("ID2");
@@ -865,6 +924,8 @@ TEST(SorterTest, UpdateAllocation)
sorter.add("a");
sorter.add("b");
+ sorter.activate("a");
+ sorter.activate("b");
sorter.add(slaveId, Resources::parse("cpus:10;mem:10;disk:10").get());
@@ -900,6 +961,8 @@ TEST(SorterTest, UpdateAllocationNestedClient)
sorter.add("a/x");
sorter.add("b/y");
+ sorter.activate("a/x");
+ sorter.activate("b/y");
sorter.add(slaveId, Resources::parse("cpus:10;mem:10;disk:10").get());
@@ -942,6 +1005,7 @@ TEST(SorterTest, MultipleSlaves)
slaveB.set_value("agentB");
sorter.add("framework");
+ sorter.activate("framework");
Resources slaveResources =
Resources::parse("cpus:2;mem:512;ports:[31000-32000]").get();
@@ -974,6 +1038,7 @@ TEST(SorterTest, MultipleSlavesUpdateAllocation)
slaveB.set_value("agentB");
sorter.add("framework");
+ sorter.activate("framework");
Resources slaveResources =
Resources::parse("cpus:2;mem:512;disk:10;ports:[31000-32000]").get();
@@ -1014,6 +1079,8 @@ TEST(SorterTest, UpdateTotal)
sorter.add("a");
sorter.add("b");
+ sorter.activate("a");
+ sorter.activate("b");
sorter.add(slaveId, Resources::parse("cpus:10;mem:100").get());
@@ -1052,6 +1119,8 @@ TEST(SorterTest, MultipleSlavesUpdateTotal)
sorter.add("a");
sorter.add("b");
+ sorter.activate("a");
+ sorter.activate("b");
sorter.add(slaveA, Resources::parse("cpus:5;mem:50").get());
sorter.add(slaveB, Resources::parse("cpus:5;mem:50").get());
@@ -1088,6 +1157,8 @@ TEST(SorterTest, RevocableResources)
sorter.add("a");
sorter.add("b");
+ sorter.activate("a");
+ sorter.activate("b");
// Create a total resource pool of 10 revocable cpus and 10 cpus and
// 100 MB mem.
@@ -1137,11 +1208,13 @@ TEST(SorterTest, SharedResources)
// Verify sort() works when shared resources are in the allocations.
sorter.add("a");
+ sorter.activate("a");
Resources aResources = Resources::parse("cpus:5;mem:5").get();
aResources += sharedDisk;
sorter.allocated("a", slaveId, aResources);
sorter.add("b");
+ sorter.activate("b");
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.allocated("b", slaveId, bResources);
@@ -1149,6 +1222,7 @@ TEST(SorterTest, SharedResources)
EXPECT_EQ(vector<string>({"b", "a"}), sorter.sort());
sorter.add("c");
+ sorter.activate("c");
Resources cResources = Resources::parse("cpus:1;mem:1").get();
cResources += sharedDisk;
sorter.allocated("c", slaveId, cResources);
@@ -1167,6 +1241,7 @@ TEST(SorterTest, SharedResources)
EXPECT_EQ(vector<string>({"b", "c"}), sorter.sort());
sorter.add("d");
+ sorter.activate("d");
Resources dResources = Resources::parse("cpus:1;mem:5").get();
dResources += sharedDisk;
sorter.allocated("d", slaveId, dResources);
@@ -1228,11 +1303,13 @@ TEST(SorterTest, SameDominantSharedResourcesAcrossClients)
// Add 2 clients each with the same shared disk, but with varying
// cpus and mem.
sorter.add("b");
+ sorter.activate("b");
Resources bResources = Resources::parse("cpus:5;mem:20").get();
bResources += sharedDisk;
sorter.allocated("b", slaveId, bResources);
sorter.add("c");
+ sorter.activate("c");
Resources cResources = Resources::parse("cpus:10;mem:6").get();
cResources += sharedDisk;
sorter.allocated("c", slaveId, cResources);
@@ -1242,6 +1319,7 @@ TEST(SorterTest, SameDominantSharedResourcesAcrossClients)
// Add 3rd client with the same shared resource.
sorter.add("a");
+ sorter.activate("a");
Resources aResources = Resources::parse("cpus:50;mem:40").get();
aResources += sharedDisk;
sorter.allocated("a", slaveId, aResources);
@@ -1273,11 +1351,13 @@ TEST(SorterTest, SameSharedResourcesSameClient)
// Verify sort() works when shared resources are in the allocations.
sorter.add("a");
+ sorter.activate("a");
Resources aResources = Resources::parse("cpus:2;mem:2").get();
aResources += sharedDisk;
sorter.allocated("a", slaveId, aResources);
sorter.add("b");
+ sorter.activate("b");
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.allocated("b", slaveId, bResources);
@@ -1317,6 +1397,7 @@ TEST(SorterTest, SharedResourcesUnallocated)
// Allocate 3 copies of shared resources to client 'a', but allocate no
// shared resource to client 'b'.
sorter.add("a");
+ sorter.activate("a");
Resources aResources = Resources::parse("cpus:2;mem:2").get();
aResources += sharedDisk;
aResources += sharedDisk;
@@ -1324,6 +1405,7 @@ TEST(SorterTest, SharedResourcesUnallocated)
sorter.allocated("a", slaveId, aResources);
sorter.add("b");
+ sorter.activate("b");
Resources bResources = Resources::parse("cpus:6;mem:6").get();
sorter.allocated("b", slaveId, bResources);
[3/3] mesos git commit: MESOS-7323: Made `addSlave` not activate any
frameworks.
Posted by mp...@apache.org.
MESOS-7323: Made `addSlave` not activate any frameworks.
Review: https://reviews.apache.org/r/58689/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/72752fc6
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/72752fc6
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/72752fc6
Branch: refs/heads/master
Commit: 72752fc6deb8ebcbfbd5448dc599ef3774339d31
Parents: 6ace0a7
Author: Michael Park <mp...@apache.org>
Authored: Thu Apr 27 20:15:07 2017 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Thu Apr 27 20:15:07 2017 -0700
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 3 -
src/tests/master_tests.cpp | 233 +++++++++++++++++++++++
src/tests/upgrade_tests.cpp | 1 +
3 files changed, 234 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/72752fc6/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 968fec0..84dc31d 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -473,9 +473,6 @@ void HierarchicalAllocatorProcess::addSlave(
// track the framework under the role.
if (!isFrameworkTrackedUnderRole(frameworkId, role)) {
trackFrameworkUnderRole(frameworkId, role);
-
- CHECK(frameworkSorters.contains(role));
- frameworkSorters.at(role)->activate(frameworkId.value());
}
// TODO(bmahler): Validate that the reserved resources have the
http://git-wip-us.apache.org/repos/asf/mesos/blob/72752fc6/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index d1828eb..7cb4774 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -6779,6 +6779,239 @@ TEST_F(MasterTest, TaskWithTinyResources)
driver.join();
}
+
+// This test ensures that when a paritioned agent comes back with tasks that
+// are allocated to a role that a framework is no longer subscribed to,
+// the framework is re-tracked under the role, but still does not receive
+// any offers with resources allocated to that role.
+TEST_F(MasterTest, MultiRoleSchedulerUnsubscribeFromRole)
+{
+ // Manipulate the clock manually.
+ Clock::pause();
+
+ master::Flags masterFlags = CreateMasterFlags();
+ Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
+ ASSERT_SOME(master);
+
+ // Allow the master to PING the agent, but drop all PONG messages
+ // from the agent. Note that we don't match on the master / agent
+ // PIDs because it's actually the `SlaveObserver` process that sends
+ // the pings.
+ Future<Message> ping = FUTURE_MESSAGE(
+ Eq(PingSlaveMessage().GetTypeName()), _, _);
+
+ DROP_PROTOBUFS(PongSlaveMessage(), _, _);
+
+ StandaloneMasterDetector detector(master.get()->pid);
+
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ slave::Flags agentFlags = CreateSlaveFlags();
+ agentFlags.resources = "cpus:2;mem:2048";
+
+ Try<Owned<cluster::Slave>> agent = StartSlave(&detector, agentFlags);
+ ASSERT_SOME(agent);
+
+ Clock::advance(agentFlags.registration_backoff_factor);
+
+ AWAIT_READY(slaveRegisteredMessage);
+ SlaveID agentId = slaveRegisteredMessage->slave_id();
+
+ // Start a scheduler. The scheduler has the PARTITION_AWARE
+ // capability, so we expect its tasks to continue running when the
+ // partitioned agent reregisters.
+ FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+ frameworkInfo.clear_role();
+ frameworkInfo.add_roles("foo");
+ frameworkInfo.add_capabilities()->set_type(
+ FrameworkInfo::Capability::PARTITION_AWARE);
+ frameworkInfo.add_capabilities()->set_type(
+ FrameworkInfo::Capability::MULTI_ROLE);
+
+ MockScheduler sched1;
+ MesosSchedulerDriver driver1(
+ &sched1, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ Future<FrameworkID> frameworkId;
+ EXPECT_CALL(sched1, registered(&driver1, _, _))
+ .WillOnce(FutureArg<1>(&frameworkId));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched1, resourceOffers(&driver1, _))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver1.start();
+
+ Clock::advance(masterFlags.allocation_interval);
+
+ AWAIT_READY(frameworkId);
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ Resources resources = Resources::parse("cpus:1;mem:512").get();
+
+ Offer offer = offers.get()[0];
+
+ TaskInfo task = createTask(offer.slave_id(), resources, "sleep 60");
+
+ Future<TaskStatus> runningStatus;
+ EXPECT_CALL(sched1, statusUpdate(&driver1, _))
+ .WillOnce(FutureArg<1>(&runningStatus));
+
+ driver1.launchTasks(offer.id(), {task});
+
+ AWAIT_READY(runningStatus);
+ EXPECT_EQ(TASK_RUNNING, runningStatus->state());
+ EXPECT_EQ(task.task_id(), runningStatus->task_id());
+
+ // Remove the role from the framework.
+
+ frameworkInfo.mutable_id()->CopyFrom(frameworkId.get());
+ frameworkInfo.clear_roles();
+
+ MockScheduler sched2;
+ MesosSchedulerDriver driver2(
+ &sched2, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ Future<Nothing> registered2;
+ EXPECT_CALL(sched2, registered(&driver2, frameworkId.get(), _))
+ .WillOnce(FutureSatisfy(®istered2));
+
+ Future<UpdateFrameworkMessage> updateFrameworkMessage =
+ FUTURE_PROTOBUF(UpdateFrameworkMessage(), _, _);
+
+ // Scheduler1 should get an error due to failover.
+ EXPECT_CALL(sched1, error(&driver1, "Framework failed over"));
+
+ // Expect that there will be no resource offers made to the scheduler.
+ EXPECT_CALL(sched2, resourceOffers(&driver2, _)).Times(0);
+
+ driver2.start();
+
+ Clock::advance(masterFlags.allocation_interval);
+
+ AWAIT_READY(registered2);
+
+ // Wait for the agent to get the updated framework info.
+ AWAIT_READY(updateFrameworkMessage);
+
+ driver1.stop();
+ driver1.join();
+
+ // Now, induce a partition of the slave by having the master
+ // timeout the slave.
+ Future<TaskStatus> unreachableStatus;
+ EXPECT_CALL(sched2, statusUpdate(&driver2, _))
+ .WillOnce(FutureArg<1>(&unreachableStatus));
+
+ // We expect to get a `slaveLost` callback, even though this
+ // scheduler is partition-aware.
+ Future<Nothing> agentLost;
+ EXPECT_CALL(sched2, slaveLost(&driver2, _))
+ .WillOnce(FutureSatisfy(&agentLost));
+
+ size_t pings = 0;
+ while (true) {
+ AWAIT_READY(ping);
+ pings++;
+ if (pings == masterFlags.max_agent_ping_timeouts) {
+ break;
+ }
+ ping = FUTURE_MESSAGE(Eq(PingSlaveMessage().GetTypeName()), _, _);
+ Clock::advance(masterFlags.agent_ping_timeout);
+ }
+
+ Clock::advance(masterFlags.agent_ping_timeout);
+
+ AWAIT_READY(unreachableStatus);
+ EXPECT_EQ(TASK_UNREACHABLE, unreachableStatus->state());
+ EXPECT_EQ(TaskStatus::REASON_SLAVE_REMOVED, unreachableStatus->reason());
+ EXPECT_EQ(task.task_id(), unreachableStatus->task_id());
+ EXPECT_EQ(agentId, unreachableStatus->slave_id());
+
+ AWAIT_READY(agentLost);
+
+ // Check that the framework is not tracked under the role.
+ {
+ Future<Response> response = process::http::get(
+ master.get()->pid,
+ "roles",
+ None(),
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+ AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response);
+
+ Try<JSON::Object> parse = JSON::parse<JSON::Object>(response->body);
+ ASSERT_SOME(parse);
+
+ const JSON::Object& result = parse.get();
+
+ JSON::Object expected = {
+ {"roles", JSON::Array{}}
+ };
+
+ EXPECT_EQ(expected, result);
+ }
+
+ // We now complete the partition on the agent side as well. We simulate
+ // a master loss event, which would normally happen during a network
+ // partition. The slave should then reregister with the master.
+ // The master will then re-track the framework under the role, but the
+ // framework should not receive any resources allocated to the role.
+ detector.appoint(None());
+
+ Future<SlaveReregisteredMessage> agentReregistered = FUTURE_PROTOBUF(
+ SlaveReregisteredMessage(), master.get()->pid, agent.get()->pid);
+
+ detector.appoint(master.get()->pid);
+
+ Clock::advance(agentFlags.registration_backoff_factor);
+
+ AWAIT_READY(agentReregistered);
+
+ // Check that the framework is re-tracked under the role by the master.
+ {
+ Future<Response> response = process::http::get(
+ master.get()->pid,
+ "roles",
+ None(),
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+ AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response);
+
+ Try<JSON::Object> parse = JSON::parse<JSON::Object>(response->body);
+ ASSERT_SOME(parse);
+
+ JSON::Value result = parse.get();
+
+ JSON::Object expected = {
+ {
+ "roles",
+ JSON::Array {
+ JSON::Object {
+ { "name", "foo" },
+ { "frameworks", JSON::Array { frameworkId.get().value() } }
+ }
+ }
+ }
+ };
+
+ EXPECT_TRUE(result.contains(expected));
+ }
+
+ // Ensure allocations to be made.
+ Clock::advance(masterFlags.allocation_interval);
+
+ Clock::settle();
+ Clock::resume();
+
+ driver2.stop();
+ driver2.join();
+}
+
} // namespace tests {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/72752fc6/src/tests/upgrade_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/upgrade_tests.cpp b/src/tests/upgrade_tests.cpp
index b5a28b5..03ca360 100644
--- a/src/tests/upgrade_tests.cpp
+++ b/src/tests/upgrade_tests.cpp
@@ -69,6 +69,7 @@ using std::initializer_list;
using std::vector;
using testing::_;
+using testing::Eq;
using testing::AtMost;
namespace mesos {
[2/3] mesos git commit: Removed an incorrect `CHECK` in the master.
Posted by mp...@apache.org.
Removed an incorrect `CHECK` in the master.
Review: https://reviews.apache.org/r/58688/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6ace0a76
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6ace0a76
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6ace0a76
Branch: refs/heads/master
Commit: 6ace0a762a97a87f0fa28adc6072aa8b039360c3
Parents: 88e2189
Author: Michael Park <mp...@apache.org>
Authored: Thu Apr 27 20:14:58 2017 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Thu Apr 27 20:14:58 2017 -0700
----------------------------------------------------------------------
src/master/master.cpp | 2 --
1 file changed, 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6ace0a76/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index a0cb505..e8c2a96 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -399,8 +399,6 @@ void Framework::trackUnderRole(const string& role)
CHECK(!isTrackedUnderRole(role));
- CHECK(roles.count(role) > 0);
-
if (!master->roles.contains(role)) {
master->roles[role] = new Role(role);
}