hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r570900 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/mapred/TaskRunner.java
Date Wed, 29 Aug 2007 19:13:11 GMT
Author: cutting
Date: Wed Aug 29 12:13:11 2007
New Revision: 570900

URL: http://svn.apache.org/viewvc?rev=570900&view=rev
Log:
HADOOP-1750.  Log standard output and error when forking task processes.  Contributed by Owen.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=570900&r1=570899&r2=570900&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Wed Aug 29 12:13:11 2007
@@ -121,6 +121,8 @@
     instance creation, avoiding classloader issues, and to implement
     Configurable.  (Enis Soztutar via cutting)
 
+    HADOOP-1750.  Log standard output and standard error when forking
+    task processes.  (omalley via cutting)
 
 Release 0.14.1 - (unreleased)
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java?rev=570900&r1=570899&r2=570900&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/TaskRunner.java Wed Aug 29 12:13:11
2007
@@ -290,7 +290,7 @@
 
         List<String> wrappedCommand = 
           TaskLog.captureOutAndError(vargs, stdout, stderr, logSize);
-        runChild(wrappedCommand, workDir);
+        runChild(wrappedCommand, workDir, taskid);
                  
     } catch (FSError e) {
       LOG.fatal("FSError", e);
@@ -390,9 +390,35 @@
   }
 
   /**
+   * Append the contents of the input stream to the output file. Both streams 
+   * are closed upon exit.
+   * @param in the stream to read
+   * @param outName the filename to append the data to
+   * @throws IOException if something goes wrong
+   */
+  private void copyStream(InputStream in, File outName) throws IOException {
+    try {
+      OutputStream out = new FileOutputStream(outName, true);
+      try {
+        byte[] buffer = new byte[1024];
+        int len = in.read(buffer);
+        while (len > 0) {
+          out.write(buffer, 0, len);
+          len = in.read(buffer);
+        }
+      } finally {
+        out.close();
+      }
+    } finally {
+      in.close();
+    }
+  }
+
+  /**
    * Run the child process
    */
-  private void runChild(List<String> args, File dir) throws IOException {
+  private void runChild(List<String> args, File dir,
+                        String taskid) throws IOException {
     ProcessBuilder builder = new ProcessBuilder(args);
     builder.directory(dir);
     process = builder.start();
@@ -404,6 +430,10 @@
         if (exit_code == 65) {
           tracker.getTaskTrackerMetrics().taskFailedPing();
         }
+        copyStream(process.getInputStream(), 
+                   TaskLog.getTaskLogFile(taskid, TaskLog.LogName.STDOUT));
+        copyStream(process.getErrorStream(), 
+                   TaskLog.getTaskLogFile(taskid, TaskLog.LogName.STDERR));
         throw new IOException("Task process exit with nonzero status of " +
                               exit_code + ".");
       }



Mime
View raw message