Explorar el Código

Merge -r 779558:779559 from trunk to 0.20 branch. Fixes: HADOOP-5623.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20@896285 13f79535-47bb-0310-9956-ffa450edef68
Thomas White hace 15 años
padre
commit
34e4962ec7

+ 3 - 0
CHANGES.txt

@@ -89,6 +89,9 @@ Release 0.20.2 - Unreleased
     HDFS-101. DFS write pipeline: DFSClient sometimes does not detect second
     datanode failure. (hairong)
 
+    HADOOP-5623. Fixes a problem to do with status messages getting overwritten
+    in streaming jobs. (Rick Cox and Jothi Padmanabhan via tomwhite)
+
 Release 0.20.1 - 2009-09-01
 
   INCOMPATIBLE CHANGES

+ 7 - 1
src/contrib/streaming/src/java/org/apache/hadoop/streaming/PipeMapRed.java

@@ -385,7 +385,11 @@ public abstract class PipeMapRed {
           if (now-lastStdoutReport > reporterOutDelay_) {
             lastStdoutReport = now;
             String hline = "Records R/W=" + numRecRead_ + "/" + numRecWritten_;
-            reporter.setStatus(hline);
+            if (!processProvidedStatus_) {
+              reporter.setStatus(hline);
+            } else {
+              reporter.progress();
+            }
             logprintln(hline);
             logflush();
           }
@@ -446,6 +450,7 @@ public abstract class PipeMapRed {
             if (matchesCounter(lineStr)) {
               incrCounter(lineStr);
             } else if (matchesStatus(lineStr)) {
+              processProvidedStatus_ = true;
               setStatus(lineStr);
             } else {
               LOG.warn("Cannot parse reporter line: " + lineStr);
@@ -671,4 +676,5 @@ public abstract class PipeMapRed {
   String LOGNAME;
   PrintStream log_;
 
+  volatile boolean processProvidedStatus_ = false;
 }

+ 11 - 2
src/contrib/streaming/src/test/org/apache/hadoop/streaming/StderrApp.java

@@ -32,8 +32,16 @@ public class StderrApp
    * postWriteLines to stderr.
    */
   public static void go(int preWriteLines, int sleep, int postWriteLines) throws IOException {
+    go(preWriteLines, sleep, postWriteLines, false);
+  }
+  
+  public static void go(int preWriteLines, int sleep, int postWriteLines, boolean status) throws IOException {
     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     String line;
+    
+    if (status) {
+      System.err.println("reporter:status:starting echo");
+    }      
        
     while (preWriteLines > 0) {
       --preWriteLines;
@@ -57,13 +65,14 @@ public class StderrApp
 
   public static void main(String[] args) throws IOException {
     if (args.length < 3) {
-      System.err.println("Usage: StderrApp PREWRITE SLEEP POSTWRITE");
+      System.err.println("Usage: StderrApp PREWRITE SLEEP POSTWRITE [STATUS]");
       return;
     }
     int preWriteLines = Integer.parseInt(args[0]);
     int sleep = Integer.parseInt(args[1]);
     int postWriteLines = Integer.parseInt(args[2]);
+    boolean status = args.length > 3 ? Boolean.parseBoolean(args[3]) : false;
     
-    go(preWriteLines, sleep, postWriteLines);
+    go(preWriteLines, sleep, postWriteLines, status);
   }
 }

+ 101 - 0
src/contrib/streaming/src/test/org/apache/hadoop/streaming/TestStreamingStatus.java

@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.streaming;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.MiniMRCluster;
+import org.apache.hadoop.mapred.TaskReport;
+
+/**
+ * Tests for the ability of a streaming task to set the status
+ * by writing "reporter:status:" lines to stderr. Uses MiniMR
+ * since the local jobtracker doesn't track status.
+ */
+public class TestStreamingStatus extends TestCase {
+  private static String TEST_ROOT_DIR =
+    new File(System.getProperty("test.build.data","/tmp"))
+    .toURI().toString().replace(' ', '+');
+  protected String INPUT_FILE = TEST_ROOT_DIR + "/input.txt";
+  protected String OUTPUT_DIR = TEST_ROOT_DIR + "/out";
+  protected String input = "roses.are.red\nviolets.are.blue\nbunnies.are.pink\n";
+  protected String map = StreamUtil.makeJavaCommand(StderrApp.class, new String[]{"3", "0", "0", "true"});
+
+  protected String[] genArgs(int jobtrackerPort) {
+    return new String[] {
+      "-input", INPUT_FILE,
+      "-output", OUTPUT_DIR,
+      "-mapper", map,
+      "-jobconf", "mapred.map.tasks=1",
+      "-jobconf", "mapred.reduce.tasks=0",      
+      "-jobconf", "keep.failed.task.files=true",
+      "-jobconf", "stream.tmpdir="+System.getProperty("test.build.data","/tmp"),
+      "-jobconf", "mapred.job.tracker=localhost:"+jobtrackerPort,
+      "-jobconf", "fs.default.name=file:///"
+    };
+  }
+  
+  public void makeInput(FileSystem fs) throws IOException {
+    Path inFile = new Path(INPUT_FILE);
+    DataOutputStream file = fs.create(inFile);
+    file.writeBytes(input);
+    file.close();
+  }
+
+  public void clean(FileSystem fs) {
+    try {
+      Path outDir = new Path(OUTPUT_DIR);
+      fs.delete(outDir, true);
+    } catch (Exception e) {}
+    try {
+      Path inFile = new Path(INPUT_FILE);    
+      fs.delete(inFile, false);
+    } catch (Exception e) {}
+  }
+  
+  public void testStreamingStatus() throws Exception {
+    MiniMRCluster mr = null;
+    FileSystem fs = null;
+    try {
+      mr = new MiniMRCluster(1, "file:///", 3);
+
+      Path inFile = new Path(INPUT_FILE);
+      fs = inFile.getFileSystem(mr.createJobConf());
+      clean(fs);
+      makeInput(fs);
+      
+      StreamJob job = new StreamJob();
+      int failed = job.run(genArgs(mr.getJobTrackerPort()));
+      assertEquals(0, failed);
+
+      TaskReport[] reports = job.jc_.getMapTaskReports(job.jobId_);
+      assertEquals(1, reports.length);
+      assertEquals("starting echo > sort", reports[0].getState());
+    } finally {
+      if (fs != null) { clean(fs); }
+      if (mr != null) { mr.shutdown(); }
+    }
+  }
+}