From fc6cb4b2dd90400a83e44e6177d83666b16af14f Mon Sep 17 00:00:00 2001 From: Yufei Gu Date: Thu, 25 May 2017 14:22:13 -0700 Subject: [PATCH] YARN-6582. FSAppAttempt demand can be updated atomically in updateDemand(). (Karthik Kambatla via Yufei Gu) (cherry picked from commit 87590090c887829e874a7132be9cf8de061437d6) --- .../scheduler/fair/FSAppAttempt.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 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 c8c0c323537..80914cd2764 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 @@ -1284,24 +1284,21 @@ public class FSAppAttempt extends SchedulerApplicationAttempt @Override public void updateDemand() { - demand = Resources.createResource(0); // Demand is current consumption plus outstanding requests - Resources.addTo(demand, getCurrentConsumption()); + Resource tmpDemand = Resources.clone(getCurrentConsumption()); // Add up outstanding resource requests - try { - writeLock.lock(); - for (SchedulerRequestKey k : getSchedulerKeys()) { - PendingAsk pendingAsk = getPendingAsk(k, ResourceRequest.ANY); - if (pendingAsk.getCount() > 0) { - Resources.multiplyAndAddTo(demand, - pendingAsk.getPerAllocationResource(), - pendingAsk.getCount()); - } + for (SchedulerRequestKey k : getSchedulerKeys()) { + PendingAsk pendingAsk = getPendingAsk(k, ResourceRequest.ANY); + if (pendingAsk.getCount() > 0) { + Resources.multiplyAndAddTo(tmpDemand, + pendingAsk.getPerAllocationResource(), + pendingAsk.getCount()); } - } finally { - writeLock.unlock(); } + + // Update demand + demand = tmpDemand; } @Override