From 87590090c887829e874a7132be9cf8de061437d6 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) --- .../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 4f7e16483a2..a5772badf22 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 @@ -1286,24 +1286,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