hadoop-yarn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeag...@apache.org
Subject svn commit: r1580970 - /hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java
Date Mon, 24 Mar 2014 18:21:43 GMT
Author: jeagles
Date: Mon Mar 24 18:21:42 2014
New Revision: 1580970

URL: http://svn.apache.org/r1580970
Log:
YARN-1670. aggregated log writer can write more log data then it says is the log length (Mit
Desai via jeagles)

Modified:
    hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java

Modified: hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java?rev=1580970&r1=1580969&r2=1580970&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java
(original)
+++ hadoop/common/branches/branch-2.4/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java
Mon Mar 24 18:21:42 2014
@@ -182,28 +182,36 @@ public class AggregatedLogFormat {
         Arrays.sort(logFiles);
         for (File logFile : logFiles) {
 
-          long fileLength = 0;
+          final long fileLength = logFile.length();
 
           // Write the logFile Type
           out.writeUTF(logFile.getName());
 
           // Write the log length as UTF so that it is printable
-          out.writeUTF(String.valueOf(fileLength = logFile.length()));
+          out.writeUTF(String.valueOf(fileLength));
 
           // Write the log itself
           FileInputStream in = null;
           try {
             in = SecureIOUtils.openForRead(logFile, getUser(), null);
             byte[] buf = new byte[65535];
-            long curRead = 0;
             int len = 0;
-            while ( ((len = in.read(buf)) != -1) && (curRead < fileLength) ) {
-              out.write(buf, 0, len);
-              curRead += len;
+            long bytesLeft = fileLength;
+            while ((len = in.read(buf)) != -1) {
+              //If buffer contents within fileLength, write
+              if (len < bytesLeft) {
+                out.write(buf, 0, len);
+                bytesLeft-=len;
+              }
+              //else only write contents within fileLength, then exit early
+              else {
+                out.write(buf, 0, (int)bytesLeft);
+                break;
+              }
             }
             long newLength = logFile.length();
             if(fileLength < newLength) {
-              LOG.warn("Aggregated Logs Truncated by "+
+              LOG.warn("Aggregated logs truncated by approximately "+
                   (newLength-fileLength) +" bytes.");
             }
           } catch (IOException e) {



Mime
View raw message