---
.../scheduler/fair/policies/ComputeFairShares.java | 15 ++++----
.../fair/policies/ComputeFairSharesTest.java | 42 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 6 deletions(-)
create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairSharesTest.java
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java
index 0a21b026714..3fe0c68986b 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairShares.java
@@ -145,7 +145,7 @@ private static void computeSharesInternal(
double right = rMax;
for (int i = 0; i < COMPUTE_FAIR_SHARES_ITERATIONS; i++) {
double mid = (left + right) / 2.0;
- int plannedResourceUsed = resourceUsedWithWeightToResourceRatio(
+ long plannedResourceUsed = resourceUsedWithWeightToResourceRatio(
mid, schedulables, type);
if (plannedResourceUsed == totalResource) {
right = mid;
@@ -174,11 +174,14 @@ private static void computeSharesInternal(
* Compute the resources that would be used given a weight-to-resource ratio
* w2rRatio, for use in the computeFairShares algorithm as described in #
*/
- private static int resourceUsedWithWeightToResourceRatio(double w2rRatio,
+ private static long resourceUsedWithWeightToResourceRatio(double w2rRatio,
Collection extends Schedulable> schedulables, String type) {
- int resourcesTaken = 0;
+ long resourcesTaken = 0;
for (Schedulable sched : schedulables) {
- int share = computeShare(sched, w2rRatio, type);
+ long share = computeShare(sched, w2rRatio, type);
+ if (Long.MAX_VALUE - resourcesTaken < share) {
+ return Long.MAX_VALUE;
+ }
resourcesTaken += share;
}
return resourcesTaken;
@@ -188,12 +191,12 @@ private static int resourceUsedWithWeightToResourceRatio(double w2rRatio,
* Compute the resources assigned to a Schedulable given a particular
* weight-to-resource ratio w2rRatio.
*/
- private static int computeShare(Schedulable sched, double w2rRatio,
+ private static long computeShare(Schedulable sched, double w2rRatio,
String type) {
double share = sched.getWeight() * w2rRatio;
share = Math.max(share, sched.getMinShare().getResourceValue(type));
share = Math.min(share, sched.getMaxShare().getResourceValue(type));
- return (int) share;
+ return (long) share;
}
/**
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairSharesTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairSharesTest.java
new file mode 100644
index 00000000000..4ceb7cb5866
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/ComputeFairSharesTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.policies;
+
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.ResourceInformation;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FakeSchedulable;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.Schedulable;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+public class ComputeFairSharesTest {
+
+ @Test(timeout = 10000)
+ public void testResourceUsedWithWeightToResourceRatio() throws Exception {
+ Collection schedulables = new ArrayList<>();
+
+ schedulables.add(new FakeSchedulable(Integer.MAX_VALUE));
+ schedulables.add(new FakeSchedulable(Integer.MAX_VALUE));
+
+ Resource totalResource = Resource.newInstance(Integer.MAX_VALUE, 0);
+ ComputeFairShares.computeShares(schedulables, totalResource, ResourceInformation.MEMORY_URI);
+ }
+}
--
2.15.0