From 47e04d3124dd03fb918aabc68542c71eccd0a8e9 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Wed, 14 Sep 2011 15:35:42 +0000 Subject: [PATCH] MAPREDUCE-2949. Fixed NodeManager to shut-down correctly if a service startup fails. Contributed by Ravi Teja Ch N V. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1170689 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../ResourceLocalizationService.java | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 0b1dbb98850..13acc035992 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -1318,6 +1318,9 @@ Release 0.23.0 - Unreleased MAPREDUCE-2995. Fixed race condition in ContainerLauncher. (vinodkv via acmurthy) + MAPREDUCE-2949. Fixed NodeManager to shut-down correctly if a service + startup fails. (Ravi Teja via vinodkv) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java index d120b5ccdf9..ead650fab89 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java @@ -107,9 +107,10 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.even import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.security.LocalizerSecurityInfo; import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.security.LocalizerTokenSecretManager; import org.apache.hadoop.yarn.service.AbstractService; +import org.apache.hadoop.yarn.service.CompositeService; import org.apache.hadoop.yarn.util.ConverterUtils; -public class ResourceLocalizationService extends AbstractService +public class ResourceLocalizationService extends CompositeService implements EventHandler, LocalizationProtocol { private static final Log LOG = LogFactory.getLog(ResourceLocalizationService.class); @@ -201,9 +202,8 @@ public class ResourceLocalizationService extends AbstractService localizationServerAddress = NetUtils.createSocketAddr( conf.get(YarnConfiguration.NM_LOCALIZER_ADDRESS, YarnConfiguration.DEFAULT_NM_LOCALIZER_ADDRESS)); localizerTracker = createLocalizerTracker(conf); + addService(localizerTracker); dispatcher.register(LocalizerEventType.class, localizerTracker); - cacheCleanup.scheduleWithFixedDelay(new CacheCleanup(dispatcher), - cacheCleanupPeriod, cacheCleanupPeriod, TimeUnit.MILLISECONDS); super.init(conf); } @@ -214,6 +214,8 @@ public class ResourceLocalizationService extends AbstractService @Override public void start() { + cacheCleanup.scheduleWithFixedDelay(new CacheCleanup(dispatcher), + cacheCleanupPeriod, cacheCleanupPeriod, TimeUnit.MILLISECONDS); server = createServer(); LOG.info("Localizer started on port " + server.getPort()); server.start(); @@ -247,9 +249,7 @@ public class ResourceLocalizationService extends AbstractService if (server != null) { server.close(); } - if (localizerTracker != null) { - localizerTracker.stop(); - } + cacheCleanup.shutdown(); super.stop(); } @@ -403,7 +403,7 @@ public class ResourceLocalizationService extends AbstractService /** * Sub-component handling the spawning of {@link ContainerLocalizer}s */ - class LocalizerTracker implements EventHandler { + class LocalizerTracker extends AbstractService implements EventHandler { private final PublicLocalizer publicLocalizer; private final Map privLocalizers; @@ -414,9 +414,15 @@ public class ResourceLocalizationService extends AbstractService LocalizerTracker(Configuration conf, Map privLocalizers) { + super(LocalizerTracker.class.getName()); this.publicLocalizer = new PublicLocalizer(conf); this.privLocalizers = privLocalizers; + } + + @Override + public synchronized void start() { publicLocalizer.start(); + super.start(); } public LocalizerHeartbeatResponse processHeartbeat(LocalizerStatus status) { @@ -435,12 +441,14 @@ public class ResourceLocalizationService extends AbstractService return localizer.update(status.getResources()); } } - + + @Override public void stop() { for (LocalizerRunner localizer : privLocalizers.values()) { localizer.interrupt(); } publicLocalizer.interrupt(); + super.stop(); } @Override