diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/AppLogAggregatorImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/AppLogAggregatorImpl.java index 3f09e5d..c42f44f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/AppLogAggregatorImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/AppLogAggregatorImpl.java @@ -417,6 +417,11 @@ public Object run() throws Exception { public void run() { try { doAppLogAggregation(); + } catch (Exception e) { + // do post clean up of log directories on any exception + LOG.error("Error occured while aggregating the log for the application " + + appId, e); + doAppLogAggregationPostCleanUp(); } finally { if (!this.appAggregationFinished.get()) { LOG.warn("Aggregation did not complete for application " + appId); @@ -454,6 +459,15 @@ private void doAppLogAggregation() { // App is finished, upload the container logs. uploadLogsForContainers(true); + doAppLogAggregationPostCleanUp(); + + this.dispatcher.getEventHandler().handle( + new ApplicationEvent(this.appId, + ApplicationEventType.APPLICATION_LOG_HANDLING_FINISHED)); + this.appAggregationFinished.set(true); + } + + private void doAppLogAggregationPostCleanUp() { // Remove the local app-log-dirs List localAppLogDirs = new ArrayList(); for (String rootLogDir : dirsHandler.getLogDirsForCleanup()) { @@ -474,11 +488,6 @@ private void doAppLogAggregation() { this.delService.delete(this.userUgi.getShortUserName(), null, localAppLogDirs.toArray(new Path[localAppLogDirs.size()])); } - - this.dispatcher.getEventHandler().handle( - new ApplicationEvent(this.appId, - ApplicationEventType.APPLICATION_LOG_HANDLING_FINISHED)); - this.appAggregationFinished.set(true); } private Path getRemoteNodeTmpLogFileForApp() { -- 1.7.11.1