From 1d156c8758ec3dc45da810d9abaecdb4e811891f Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Thu, 23 Feb 2017 14:29:30 -0800 Subject: [PATCH] YARN-6175. FairScheduler: Negative vcore for resource needed to preempt. (Yufei Gu via kasha) --- .../hadoop/yarn/util/resource/Resources.java | 18 ++++++++++++++++++ .../scheduler/fair/FSAppAttempt.java | 8 +------- .../scheduler/fair/FairScheduler.java | 8 ++++---- 3 files changed, 23 insertions(+), 11 deletions(-) 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 fdd9ec767aa..d62e55809b5 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 @@ -172,6 +172,24 @@ public class Resources { return subtractFrom(clone(lhs), rhs); } + /** + * Subtract rhs from lhs and reset any negative + * values to zero. + * @param lhs {@link Resource} to subtract from + * @param rhs {@link Resource} to subtract + * @return the value of lhs after subtraction + */ + public static Resource subtractFromNonNegative(Resource lhs, Resource rhs) { + subtractFrom(lhs, rhs); + if (lhs.getMemorySize() < 0) { + lhs.setMemorySize(0); + } + if (lhs.getVirtualCores() < 0) { + lhs.setVirtualCores(0); + } + return lhs; + } + public static Resource negate(Resource resource) { return subtract(NONE, resource); } 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 44d2b421f77..802479dd446 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 @@ -194,16 +194,10 @@ public class FSAppAttempt extends SchedulerApplicationAttempt for (NodeId nodeId: blacklistNodeIds) { SchedulerNode node = scheduler.getSchedulerNode(nodeId); if (node != null) { - Resources.subtractFrom(availableResources, + Resources.subtractFromNonNegative(availableResources, node.getAvailableResource()); } } - if (availableResources.getMemory() < 0) { - availableResources.setMemory(0); - } - if (availableResources.getVirtualCores() < 0) { - availableResources.setVirtualCores(0); - } } /** 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/FairScheduler.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/FairScheduler.java index 1586a49fa2a..8e7d299a4e3 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/FairScheduler.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/FairScheduler.java @@ -531,14 +531,14 @@ public class FairScheduler extends if (curTime - sched.getLastTimeAtMinShare() > minShareTimeout) { Resource target = Resources.componentwiseMin( sched.getMinShare(), sched.getDemand()); - resDueToMinShare = Resources.max(calc, clusterResource, - Resources.none(), Resources.subtract(target, sched.getResourceUsage())); + resDueToMinShare = + Resources.subtractFromNonNegative(target, sched.getResourceUsage()); } if (curTime - sched.getLastTimeAtFairShareThreshold() > fairShareTimeout) { Resource target = Resources.componentwiseMin( sched.getFairShare(), sched.getDemand()); - resDueToFairShare = Resources.max(calc, clusterResource, - Resources.none(), Resources.subtract(target, sched.getResourceUsage())); + resDueToFairShare = + Resources.subtractFromNonNegative(target, sched.getResourceUsage()); } Resource deficit = Resources.max(calc, clusterResource, resDueToMinShare, resDueToFairShare);