From 9cd2e3be26a94abf55699b35ba83363a74df8657 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Wed, 21 Dec 2011 23:49:39 +0000 Subject: [PATCH] MAPREDUCE-3586. Modified CompositeService to avoid duplicate stop operations thereby solving race conditions in MR AM shutdown. (vinodkv) svn merge -c 1221950 --ignore-ancestry ../../trunk/ git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1221951 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 4 ++++ .../apache/hadoop/yarn/service/CompositeService.java | 4 ++++ .../apache/hadoop/yarn/util/TestCompositeService.java | 10 +++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 979af1c701e..21001d01f0c 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -303,6 +303,10 @@ Release 0.23.1 - Unreleased MAPREDUCE-3349. Log rack-name in JobHistory for unsuccessful tasks. (Amar Kamat and Devaraj K via sseth) + MAPREDUCE-3586. Modified CompositeService to avoid duplicate stop operations + thereby solving race conditions in MR AM shutdown. (vinodkv) + +>>>>>>> .merge-right.r1221950 Release 0.23.0 - 2011-11-01 INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/CompositeService.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/CompositeService.java index 36fecc38ff8..00cebcfef46 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/CompositeService.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/CompositeService.java @@ -81,6 +81,10 @@ public class CompositeService extends AbstractService { } public synchronized void stop() { + if (this.getServiceState() == STATE.STOPPED) { + // The base composite-service is already stopped, don't do anything again. + return; + } if (serviceList.size() > 0) { stop(serviceList.size() - 1); } diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestCompositeService.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestCompositeService.java index 9ca0e4b42c9..7a8aef88f7d 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestCompositeService.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestCompositeService.java @@ -88,6 +88,14 @@ public class TestCompositeService { ((NUM_OF_SERVICES - 1) - i), services[i].getCallSequenceNumber()); } + // Try to stop again. This should be a no-op. + serviceManager.stop(); + // Verify that stop() call sequence numbers for every service don't change. + for (int i = 0; i < NUM_OF_SERVICES; i++) { + assertEquals("For " + services[i] + + " service, stop() call sequence number should have been ", + ((NUM_OF_SERVICES - 1) - i), services[i].getCallSequenceNumber()); + } } @Test @@ -153,7 +161,7 @@ public class TestCompositeService { serviceManager.start(); - // Start the composite service + // Stop the composite service try { serviceManager.stop(); } catch (YarnException e) {