YARN-7489. ConcurrentModificationException in RMAppImpl#getRMAppMetrics. Contributed by Tao Yang.

This commit is contained in:
bibinchundatt 2017-11-18 19:25:29 +05:30
parent 96e6a99360
commit b5b81a4f08
1 changed files with 31 additions and 27 deletions

View File

@ -1641,35 +1641,39 @@ public class RMAppImpl implements RMApp, Recoverable {
int numNonAMContainerPreempted = 0; int numNonAMContainerPreempted = 0;
Map<String, Long> resourceSecondsMap = new HashMap<>(); Map<String, Long> resourceSecondsMap = new HashMap<>();
Map<String, Long> preemptedSecondsMap = new HashMap<>(); Map<String, Long> preemptedSecondsMap = new HashMap<>();
this.readLock.lock();
for (RMAppAttempt attempt : attempts.values()) { try {
if (null != attempt) { for (RMAppAttempt attempt : attempts.values()) {
RMAppAttemptMetrics attemptMetrics = if (null != attempt) {
attempt.getRMAppAttemptMetrics(); RMAppAttemptMetrics attemptMetrics =
Resources.addTo(resourcePreempted, attempt.getRMAppAttemptMetrics();
attemptMetrics.getResourcePreempted()); Resources.addTo(resourcePreempted,
numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0; attemptMetrics.getResourcePreempted());
numNonAMContainerPreempted += numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0;
attemptMetrics.getNumNonAMContainersPreempted(); numNonAMContainerPreempted +=
// getAggregateAppResourceUsage() will calculate resource usage stats attemptMetrics.getNumNonAMContainersPreempted();
// for both running and finished containers. // getAggregateAppResourceUsage() will calculate resource usage stats
AggregateAppResourceUsage resUsage = // for both running and finished containers.
attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage(); AggregateAppResourceUsage resUsage =
for (Map.Entry<String, Long> entry : resUsage attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage();
.getResourceUsageSecondsMap().entrySet()) { for (Map.Entry<String, Long> entry : resUsage
long value = RMServerUtils .getResourceUsageSecondsMap().entrySet()) {
.getOrDefault(resourceSecondsMap, entry.getKey(), 0L); long value = RMServerUtils
value += entry.getValue(); .getOrDefault(resourceSecondsMap, entry.getKey(), 0L);
resourceSecondsMap.put(entry.getKey(), value); value += entry.getValue();
} resourceSecondsMap.put(entry.getKey(), value);
for (Map.Entry<String, Long> entry : attemptMetrics }
.getPreemptedResourceSecondsMap().entrySet()) { for (Map.Entry<String, Long> entry : attemptMetrics
long value = RMServerUtils .getPreemptedResourceSecondsMap().entrySet()) {
.getOrDefault(preemptedSecondsMap, entry.getKey(), 0L); long value = RMServerUtils
value += entry.getValue(); .getOrDefault(preemptedSecondsMap, entry.getKey(), 0L);
preemptedSecondsMap.put(entry.getKey(), value); value += entry.getValue();
preemptedSecondsMap.put(entry.getKey(), value);
}
} }
} }
} finally {
this.readLock.unlock();
} }
return new RMAppMetrics(resourcePreempted, numNonAMContainerPreempted, return new RMAppMetrics(resourcePreempted, numNonAMContainerPreempted,