diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 536169c2fde..5c356b6d819 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -326,6 +326,9 @@ Release 2.8.0 - UNRELEASED YARN-3259. FairScheduler: Trigger fairShare updates on node events. (Anubhav Dhoot via kasha) + YARN-2768. Avoid cloning Resource in FSAppAttempt#updateDemand. + (Hong Zhiguo via kasha) + BUG FIXES YARN-3197. Confusing log generated by CapacityScheduler. (Varun Saxena diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java index 472811a72a9..503d456cfd3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java @@ -150,7 +150,19 @@ public class Resources { public static Resource multiply(Resource lhs, double by) { return multiplyTo(clone(lhs), by); } - + + /** + * Multiply @param rhs by @param by, and add the result to @param lhs + * without creating any new {@link Resource} object + */ + public static Resource multiplyAndAddTo( + Resource lhs, Resource rhs, double by) { + lhs.setMemory(lhs.getMemory() + (int)(rhs.getMemory() * by)); + lhs.setVirtualCores(lhs.getVirtualCores() + + (int)(rhs.getVirtualCores() * by)); + return lhs; + } + public static Resource multiplyAndNormalizeUp( ResourceCalculator calculator,Resource lhs, double by, Resource factor) { return calculator.multiplyAndNormalizeUp(lhs, by, factor); 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/FSAppAttempt.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/FSAppAttempt.java index 7419446aa5a..cfec9157f8c 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/FSAppAttempt.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/FSAppAttempt.java @@ -801,8 +801,8 @@ public class FSAppAttempt extends SchedulerApplicationAttempt synchronized (this) { for (Priority p : getPriorities()) { for (ResourceRequest r : getResourceRequests(p).values()) { - Resource total = Resources.multiply(r.getCapability(), r.getNumContainers()); - Resources.addTo(demand, total); + Resources.multiplyAndAddTo(demand, + r.getCapability(), r.getNumContainers()); } } }