From 5580626ea0d20c51b3b25855b8257dce79fc5117 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Tue, 9 Aug 2016 22:12:35 +0000 Subject: [PATCH] YARN-5262. Optimize sending RMNodeFinishedContainersPulledByAMEvent for every AM heartbeat. Contributed by Rohith Sharma K S (cherry picked from commit 26b5e6116f392b6be91dca57968259f87554ce33) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../resourcemanager/rmapp/attempt/RMAppAttemptImpl.java | 9 ++++++--- .../rmapp/attempt/TestRMAppAttemptTransitions.java | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 8fc224327b3..b667e322fcd 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -10,6 +10,9 @@ Release 2.7.4 - UNRELEASED OPTIMIZATIONS + YARN-5262. Optimize sending RMNodeFinishedContainersPulledByAMEvent for + every AM heartbeat (Rohith Sharma K S via jlowe) + BUG FIXES YARN-5197. RM leaks containers if running container disappears from 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/attempt/RMAppAttemptImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java index 9c4a8a60753..463e62693c7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java @@ -763,9 +763,11 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable { } } - finishedContainersSentToAM.putIfAbsent(nodeId, new ArrayList - ()); - finishedContainersSentToAM.get(nodeId).addAll(finishedContainers); + if (!finishedContainers.isEmpty()) { + finishedContainersSentToAM.putIfAbsent(nodeId, + new ArrayList()); + finishedContainersSentToAM.get(nodeId).addAll(finishedContainers); + } } return returnList; @@ -1713,6 +1715,7 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable { eventHandler.handle(new RMNodeFinishedContainersPulledByAMEvent(nodeId, containerIdList)); } + this.finishedContainersSentToAM.clear(); } // Add am container to the list so that am container instance will be diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index 9b2e54f9b5f..8cb4395ee81 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -1427,6 +1427,13 @@ public class TestRMAppAttemptTransitions { Assert.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty()); Assert.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt) .size()); + + // verify if no containers to acknowledge to NM then event should not be + // triggered. Number of times event invoked is 1 i.e on second pull + containerStatuses = applicationAttempt.pullJustFinishedContainers(); + Assert.assertEquals(0, containerStatuses.size()); + Mockito.verify(rmnodeEventHandler, times(1)) + .handle(Mockito.any(RMNodeEvent.class)); } private static List getFinishedContainersSentToAM(