From 8d49c2fc3b93aa6db5ee883b8e0791afed4f20f2 Mon Sep 17 00:00:00 2001 From: Yufei Gu Date: Tue, 12 Sep 2017 14:58:23 -0700 Subject: [PATCH] YARN-7057. FSAppAttempt#getResourceUsage doesn't need to consider resources queued for preemption. (Contributed by Karthik via Yufei Gu) (cherry picked from commit 82c5dd1d508292ed88eda0f5356776437ba67d4c) --- .../scheduler/fair/FSAppAttempt.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 fe57d1b9c3a..309dff488f0 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 @@ -614,9 +614,16 @@ public class FSAppAttempt extends SchedulerApplicationAttempt // Check if the app's allocation will be over its fairshare even // after preempting this container - Resource usageAfterPreemption = Resources.subtract( - getResourceUsage(), container.getAllocatedResource()); + Resource usageAfterPreemption = Resources.clone(getResourceUsage()); + // Subtract resources of containers already queued for preemption + synchronized (preemptionVariablesLock) { + Resources.subtractFrom(usageAfterPreemption, resourcesToBePreempted); + } + + // Subtract this container's allocation to compute usage after preemption + Resources.subtractFrom( + usageAfterPreemption, container.getAllocatedResource()); return !isUsageBelowShare(usageAfterPreemption, getFairShare()); } @@ -1270,13 +1277,7 @@ public class FSAppAttempt extends SchedulerApplicationAttempt @Override public Resource getResourceUsage() { - // Subtract copies the object, so that we have a snapshot, - // in case usage changes, while the caller is using the value - synchronized (preemptionVariablesLock) { - return containersToBePreempted.isEmpty() - ? getCurrentConsumption() - : Resources.subtract(getCurrentConsumption(), resourcesToBePreempted); - } + return getCurrentConsumption(); } @Override