From 6217e54718fc0ba8845ef8cc5a558fe67d98c18e Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Tue, 25 Oct 2011 00:36:19 +0000 Subject: [PATCH] MAPREDUCE-3159. Ensure DefaultContainerExecutor doesn't delete application directories during app-init. Contributed by Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1188466 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 ++ .../nodemanager/DefaultContainerExecutor.java | 6 --- .../localizer/LocalizedResource.java | 5 ++ .../ResourceLocalizationService.java | 51 +++++++++++-------- .../localizer/event/LocalizerEvent.java | 4 ++ .../localizer/event/LocalizerEventType.java | 1 + .../event/LocalizerResourceRequestEvent.java | 5 ++ .../localizer/event/ResourceEventType.java | 9 ++++ 8 files changed, 57 insertions(+), 27 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index b344c3d5aac..daafe6b576c 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -1753,6 +1753,9 @@ Release 0.23.0 - Unreleased MAPREDUCE-3252. Fix map tasks to not rewrite data an extra time when map output fits in spill buffer. (todd) + MAPREDUCE-3159. Ensure DefaultContainerExecutor doesn't delete application + directories during app-init. (todd via acmurthy) + 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/DefaultContainerExecutor.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DefaultContainerExecutor.java index 40ef62a18c1..9a0de4efb24 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DefaultContainerExecutor.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DefaultContainerExecutor.java @@ -340,12 +340,6 @@ public class DefaultContainerExecutor extends ContainerExecutor { FsPermission appperms = new FsPermission(APPDIR_PERM); for (Path localDir : localDirs) { Path fullAppDir = getApplicationDir(localDir, user, appId); - if (lfs.util().exists(fullAppDir)) { - // this will happen on a partial execution of localizeJob. Sometimes - // copying job.xml to the local disk succeeds but copying job.jar might - // throw out an exception. We should clean up and then try again. - lfs.delete(fullAppDir, true); - } // create $local.dir/usercache/$user/appcache/$appId try { lfs.mkdir(fullAppDir, appperms, true); 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/LocalizedResource.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/LocalizedResource.java index 1e02fe68980..883b4bcf559 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/LocalizedResource.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/LocalizedResource.java @@ -205,6 +205,11 @@ public class LocalizedResource implements EventHandler { // typedef } + /** + * Transition from INIT to DOWNLOADING. + * Sends a {@link LocalizerResourceRequestEvent} to the + * {@link ResourceLocalizationService}. + */ @SuppressWarnings("unchecked") // dispatcher not typed private static class FetchResourceTransition extends ResourceTransition { @Override 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 d5b50c8347b..22c2d3d9358 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 @@ -71,7 +71,6 @@ import org.apache.hadoop.fs.LocalDirAllocator; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.net.NetUtils; -import org.apache.hadoop.security.SecurityInfo; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.yarn.YarnException; import org.apache.hadoop.yarn.event.Dispatcher; @@ -320,6 +319,11 @@ public class ResourceLocalizationService extends CompositeService app.getAppId())); } + /** + * For each of the requested resources for a container, determines the + * appropriate {@link LocalResourcesTracker} and forwards a + * {@link LocalResourceRequest} to that tracker. + */ private void handleInitContainerResources( ContainerLocalizationRequestEvent rsrcReqs) { Container c = rsrcReqs.getContainer(); @@ -833,26 +837,7 @@ public class ResourceLocalizationService extends CompositeService // 0) init queue, etc. // 1) write credentials to private dir - DataOutputStream tokenOut = null; - try { - Credentials credentials = context.getCredentials(); - FileContext lfs = getLocalFileContext(getConfig()); - tokenOut = - lfs.create(nmPrivateCTokensPath, EnumSet.of(CREATE, OVERWRITE)); - LOG.info("Writing credentials to the nmPrivate file " - + nmPrivateCTokensPath.toString() + ". Credentials list: "); - if (LOG.isDebugEnabled()) { - for (Token tk : credentials - .getAllTokens()) { - LOG.debug(tk.getService() + " : " + tk.encodeToUrlString()); - } - } - credentials.writeTokenStorageToStream(tokenOut); - } finally { - if (tokenOut != null) { - tokenOut.close(); - } - } + writeCredentials(nmPrivateCTokensPath); // 2) exec initApplication and wait exec.startLocalizer(nmPrivateCTokensPath, localizationServerAddress, context.getUser(), @@ -876,6 +861,30 @@ public class ResourceLocalizationService extends CompositeService } } + private void writeCredentials(Path nmPrivateCTokensPath) + throws IOException { + DataOutputStream tokenOut = null; + try { + Credentials credentials = context.getCredentials(); + FileContext lfs = getLocalFileContext(getConfig()); + tokenOut = + lfs.create(nmPrivateCTokensPath, EnumSet.of(CREATE, OVERWRITE)); + LOG.info("Writing credentials to the nmPrivate file " + + nmPrivateCTokensPath.toString() + ". Credentials list: "); + if (LOG.isDebugEnabled()) { + for (Token tk : credentials + .getAllTokens()) { + LOG.debug(tk.getService() + " : " + tk.encodeToUrlString()); + } + } + credentials.writeTokenStorageToStream(tokenOut); + } finally { + if (tokenOut != null) { + tokenOut.close(); + } + } + } + } static class CacheCleanup extends Thread { 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/event/LocalizerEvent.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/event/LocalizerEvent.java index d3cb4afcd90..bf5097a884b 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/event/LocalizerEvent.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/event/LocalizerEvent.java @@ -18,7 +18,11 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event; import org.apache.hadoop.yarn.event.AbstractEvent; +import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService; +/** + * Events delivered to the {@link ResourceLocalizationService.LocalizerTracker} + */ public class LocalizerEvent extends AbstractEvent { private final String localizerId; 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/event/LocalizerEventType.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/event/LocalizerEventType.java index 09a1ae06607..eb033b9a3f0 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/event/LocalizerEventType.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/event/LocalizerEventType.java @@ -18,6 +18,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event; public enum LocalizerEventType { + /** See {@link LocalizerResourceRequestEvent} */ REQUEST_RESOURCE_LOCALIZATION, ABORT_LOCALIZATION } 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/event/LocalizerResourceRequestEvent.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/event/LocalizerResourceRequestEvent.java index f8a2c899913..4a86d763004 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/event/LocalizerResourceRequestEvent.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/event/LocalizerResourceRequestEvent.java @@ -20,8 +20,13 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.eve import org.apache.hadoop.yarn.api.records.LocalResourceVisibility; import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizedResource; import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizerContext; +import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService; import org.apache.hadoop.yarn.util.ConverterUtils; +/** + * Event indicating that the {@link ResourceLocalizationService.LocalizerTracker} + * should fetch this resource. + */ public class LocalizerResourceRequestEvent extends LocalizerEvent { private final LocalizerContext context; 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/event/ResourceEventType.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/event/ResourceEventType.java index 8e84ac6902b..d68a1b6d391 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/event/ResourceEventType.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/event/ResourceEventType.java @@ -17,8 +17,17 @@ */ package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event; +import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizedResource; + +/** + * Events delivered to {@link LocalizedResource}. Each of these + * events is a subclass of {@link ResourceEvent}. + */ public enum ResourceEventType { + /** See {@link ResourceRequestEvent} */ REQUEST, + /** See {@link ResourceLocalizedEvent} */ LOCALIZED, + /** See {@link ResourceReleaseEvent} */ RELEASE }