From 0f0204c3c2a291c1741dd05227ddbfe08bae25bc Mon Sep 17 00:00:00 2001 From: Robert Joseph Evans Date: Thu, 26 Apr 2012 18:28:18 +0000 Subject: [PATCH] svn merge -c 1331012. FIXES: MAPREDUCE-4169. Container Logs appear in unsorted order (Jonathan Eagles via bobby) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1331014 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../yarn/logaggregation/AggregatedLogFormat.java | 13 +++++++++++-- .../nodemanager/webapp/ContainerLogsPage.java | 9 +++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 4c572f212f6..1190c32fbea 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -303,6 +303,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 5bf075546c9..dfd4c257d3f 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.InputStreamReader; 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 class AggregatedLogFormat { // 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 class AggregatedLogFormat { 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 1dba16c73f8..ee019255193 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.FileReader; 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 @@ public class ContainerLogsPage extends NMView { } } } 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),