From dc4132395e8d635584f5ae10d98084745bf17fba Mon Sep 17 00:00:00 2001 From: bibinchundatt Date: Mon, 20 Nov 2017 21:31:50 +0530 Subject: [PATCH] YARN-7489. ConcurrentModificationException in RMAppImpl#getRMAppMetrics. Contributed by Tao Yang. (cherry picked from commit 5c2986e58dfc86fada8554a3f48cd417a4458abc) --- .../resourcemanager/rmapp/RMAppImpl.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 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/rmapp/RMAppImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java index 7526ea3c611..cc3d618f8ff 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java @@ -1616,24 +1616,29 @@ public class RMAppImpl implements RMApp, Recoverable { long vcoreSeconds = 0; long preemptedMemorySeconds = 0; long preemptedVcoreSeconds = 0; - for (RMAppAttempt attempt : attempts.values()) { - if (null != attempt) { - RMAppAttemptMetrics attemptMetrics = - attempt.getRMAppAttemptMetrics(); - Resources.addTo(resourcePreempted, - attemptMetrics.getResourcePreempted()); - numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0; - numNonAMContainerPreempted += - attemptMetrics.getNumNonAMContainersPreempted(); - // getAggregateAppResourceUsage() will calculate resource usage stats - // for both running and finished containers. - AggregateAppResourceUsage resUsage = - attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage(); - memorySeconds += resUsage.getMemorySeconds(); - vcoreSeconds += resUsage.getVcoreSeconds(); - preemptedMemorySeconds += attemptMetrics.getPreemptedMemory(); - preemptedVcoreSeconds += attemptMetrics.getPreemptedVcore(); + this.readLock.lock(); + try { + for (RMAppAttempt attempt : attempts.values()) { + if (null != attempt) { + RMAppAttemptMetrics attemptMetrics = + attempt.getRMAppAttemptMetrics(); + Resources.addTo(resourcePreempted, + attemptMetrics.getResourcePreempted()); + numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0; + numNonAMContainerPreempted += + attemptMetrics.getNumNonAMContainersPreempted(); + // getAggregateAppResourceUsage() will calculate resource usage stats + // for both running and finished containers. + AggregateAppResourceUsage resUsage = + attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage(); + memorySeconds += resUsage.getMemorySeconds(); + vcoreSeconds += resUsage.getVcoreSeconds(); + preemptedMemorySeconds += attemptMetrics.getPreemptedMemory(); + preemptedVcoreSeconds += attemptMetrics.getPreemptedVcore(); + } } + } finally { + this.readLock.unlock(); } return new RMAppMetrics(resourcePreempted,