diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index ceeb3f0802..0f00d00a41 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -412,6 +412,9 @@ Release 0.23.3 - UNRELEASED MAPREDUCE-3613. web service calls header contains 2 content types (tgraves) + MAPREDUCE-4169. Container Logs appear in unsorted order (Jonathan Eagles + via bobby) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java index 5bf075546c..dfd4c257d3 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java @@ -29,6 +29,9 @@ import java.io.IOException; import java.io.Writer; import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.List; @@ -112,8 +115,11 @@ public static class LogValue { // the entire k-v format public LogValue(List rootLogDirs, ContainerId containerId) { - this.rootLogDirs = rootLogDirs; + this.rootLogDirs = new ArrayList(rootLogDirs); this.containerId = containerId; + + // Ensure logs are processed in lexical order + Collections.sort(this.rootLogDirs); } public void write(DataOutputStream out) throws IOException { @@ -131,7 +137,10 @@ public void write(DataOutputStream out) throws IOException { continue; // ContainerDir may have been deleted by the user. } - for (File logFile : containerLogDir.listFiles()) { + // Write out log files in lexical order + File[] logFiles = containerLogDir.listFiles(); + Arrays.sort(logFiles); + for (File logFile : logFiles) { // Write the logFile Type out.writeUTF(logFile.getName()); diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java index 1dba16c73f..ee01925519 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java @@ -30,6 +30,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.List; @@ -269,12 +271,15 @@ private void printLogs(Block html, ContainerId containerId, } } } else { - // Just print out the log-types + // Print out log types in lexical order List containerLogsDirs = getContainerLogDirs(containerId, dirsHandler); + Collections.sort(containerLogsDirs); boolean foundLogFile = false; for (File containerLogsDir : containerLogsDirs) { - for (File logFile : containerLogsDir.listFiles()) { + File[] logFiles = containerLogsDir.listFiles(); + Arrays.sort(logFiles); + for (File logFile : logFiles) { foundLogFile = true; html.p() .a(url("containerlogs", $(CONTAINER_ID), $(APP_OWNER),