diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/tfile/LogAggregationTFileController.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/tfile/LogAggregationTFileController.java index 92e3a08da3..5064e267f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/tfile/LogAggregationTFileController.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/filecontroller/tfile/LogAggregationTFileController.java @@ -96,8 +96,10 @@ public void initializeWriter(LogAggregationFileControllerContext context) @Override public void closeWriter() { - this.writer.close(); - this.writer = null; + if (this.writer != null) { + this.writer.close(); + this.writer = null; + } } @Override @@ -117,6 +119,9 @@ public void postWrite(final LogAggregationFileControllerContext record) record.increcleanupOldLogTimes(); } + // close the writer before the file is renamed or deleted + closeWriter(); + final Path renamedPath = record.getRollingMonitorInterval() <= 0 ? record.getRemoteNodeLogFileForApp() : new Path( record.getRemoteNodeLogFileForApp().getParent(),