This is an automated email from the ASF dual-hosted git repository.
mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new b65b570 Fixed a bug where disk quota may be under allocated.
b65b570 is described below
commit b65b57038cb495408078a343ce4401e12d329561
Author: Meng Zhu <[email protected]>
AuthorDate: Fri Mar 29 11:35:42 2019 -0700
Fixed a bug where disk quota may be under allocated.
The resources chopping logic in the allocator
currently overly shrinks resources with the same
name (e.g. vanilla disk and mount disk) if there
are multiple such resources. Currently only
different disk resources might share the same
name (we only chop unreserved/non-revocable/non-shared
resources). This would lead to disk quota being under
allocated. This patch corrects the shrinking logic.
See MESOS-9692.
Review: https://reviews.apache.org/r/70344
---
src/master/allocator/mesos/hierarchical.cpp | 2 +-
src/tests/hierarchical_allocator_tests.cpp | 49 +++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/src/master/allocator/mesos/hierarchical.cpp
b/src/master/allocator/mesos/hierarchical.cpp
index 8bc7499..ef4f968 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1663,7 +1663,7 @@ void HierarchicalAllocatorProcess::__allocate()
targetScalarQuantites.get(resource.name());
if (Resources::shrink(&resource, limitScalar.get())) {
- targetScalarQuantites[resource.name()] -= limitScalar.get();
+ targetScalarQuantites[resource.name()] -= resource.scalar();
result += std::move(resource);
}
}
diff --git a/src/tests/hierarchical_allocator_tests.cpp
b/src/tests/hierarchical_allocator_tests.cpp
index a34fa96..39e209b 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -3945,6 +3945,55 @@ TEST_F(HierarchicalAllocatorTest,
QuotaAllocationGranularityUnchoppableResource)
}
+// This test ensures that quota is satisfied in the presence of multiple
+// unreserved disk resources. This is a regression test for MESOS-9692.
+TEST_F(HierarchicalAllocatorTest, QuotaAllocationMultipleDisk)
+{
+ // The test sets a quota that contains 100 disk resources and
+ // an agent with two kinds of disk resources: 50 vanilla disks
+ // and 50 mount disks. Both disks (100 in total) should be offered
+ // to the framework in a single offer to meet its role's quota.
+
+ Clock::pause();
+ initialize();
+
+ const string QUOTA_ROLE{"quota-role"};
+
+ const Quota quota = createQuota(QUOTA_ROLE, "cpus:1;mem:512;disk:100");
+ allocator->setQuota(QUOTA_ROLE, quota);
+
+ // Create 50 disk resource of type `MOUNT`.
+ Resources mountDiskResource = createDiskResource(
+ "50", "*", None(), None(), createDiskSourceMount(), false);
+
+ Resources agentResources =
+ Resources::parse("cpus:1;mem:512;disk:50").get() + mountDiskResource;
+
+ SlaveInfo agent1 = createSlaveInfo(agentResources);
+ allocator->addSlave(
+ agent1.id(),
+ agent1,
+ AGENT_CAPABILITIES(),
+ None(),
+ agent1.resources(),
+ {});
+
+ // Create `framework` under `QUOTA_ROLE`.
+ // This will tigger an event-driven allocation loop.
+ FrameworkInfo framework = createFrameworkInfo({QUOTA_ROLE});
+ allocator->addFramework(framework.id(), framework, {}, true, {});
+
+ Clock::settle();
+
+ // `framework` will get all resources (including both disks) of `agent1` to
+ // satisfy its role's quota.
+ Allocation expected = Allocation(
+ framework.id(), {{QUOTA_ROLE, {{agent1.id(), agent1.resources()}}}});
+
+ AWAIT_EXPECT_EQ(expected, allocations.get());
+}
+
+
// This test verifies the behavior of allocating a resource to quota roles
// that has no quota set for that particular resource (e.g. allocating
// memory to a role with only quota set for CPU). If a role has no quota