Просмотр исходного кода

HADOOP-549. Fix a NullPointerException in TaskReport's serialization. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@502029 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 лет назад
Родитель
Сommit
d470548bb5

+ 3 - 0
CHANGES.txt

@@ -122,6 +122,9 @@ Trunk (unreleased changes)
     add a README; make the environment file use a template.
     (Tom White via cutting)
 
+38. HADOOP-549.  Fix a NullPointerException in TaskReport's
+    serialization.  (omalley via cutting)
+
 
 Release 0.10.1 - 2007-01-10
 

+ 2 - 1
src/java/org/apache/hadoop/mapred/InterTrackerProtocol.java

@@ -31,8 +31,9 @@ interface InterTrackerProtocol extends VersionedProtocol {
    * version 3 introduced to replace 
    * emitHearbeat/pollForNewTask/pollForTaskWithClosedJob with
    * {@link #heartbeat(TaskTrackerStatus, boolean, boolean, short)}
+   * version 4 changed TaskReport for HADOOP-549.
    */
-  public static final long versionID = 3L;
+  public static final long versionID = 4L;
   
   public final static int TRACKERS_OK = 0;
   public final static int UNKNOWN_TASKTRACKER = 1;

+ 19 - 1
src/java/org/apache/hadoop/mapred/JobClient.java

@@ -349,12 +349,30 @@ public class JobClient extends ToolBase implements MRConstants  {
         }
     }
 
+    /**
+     * Get the information of the current state of the map tasks of a job.
+     * @param jobId the job to query
+     * @return the list of all of the map tips
+     */
+    public TaskReport[] getMapTaskReports(String jobId) throws IOException {
+      return jobSubmitClient.getMapTaskReports(jobId);
+    }
+    
+    /**
+     * Get the information of the current state of the reduce tasks of a job.
+     * @param jobId the job to query
+     * @return the list of all of the map tips
+     */    
+    public TaskReport[] getReduceTaskReports(String jobId) throws IOException {
+      return jobSubmitClient.getReduceTaskReports(jobId);
+    }
+    
     public ClusterStatus getClusterStatus() throws IOException {
       return jobSubmitClient.getClusterStatus();
     }
     
     public JobStatus[] jobsToComplete() throws IOException {
-	return jobSubmitClient.jobsToComplete();
+      return jobSubmitClient.jobsToComplete();
     }
     
     /** Utility that submits a job, then polls for progress until the job is

+ 6 - 8
src/java/org/apache/hadoop/mapred/TaskReport.java

@@ -84,23 +84,21 @@ public class TaskReport implements Writable {
   // Writable
   //////////////////////////////////////////////
   public void write(DataOutput out) throws IOException {
-    UTF8.writeString(out, taskid);
+    Text.writeString(out, taskid);
     out.writeFloat(progress);
-    UTF8.writeString(out, state);
+    Text.writeString(out, state);
     out.writeLong(startTime);
     out.writeLong(finishTime);
-    new ObjectWritable(diagnostics).write(out);
+    WritableUtils.writeStringArray(out, diagnostics);
   }
 
   public void readFields(DataInput in) throws IOException {
-    this.taskid = UTF8.readString(in);
+    this.taskid = Text.readString(in);
     this.progress = in.readFloat();
-    this.state = UTF8.readString(in);
+    this.state = Text.readString(in);
     this.startTime = in.readLong(); 
     this.finishTime = in.readLong() ;
     
-    ObjectWritable wrapper = new ObjectWritable();
-    wrapper.readFields(in);
-    diagnostics = (String[])wrapper.get();
+    diagnostics = WritableUtils.readStringArray(in);
   }
 }

+ 6 - 0
src/test/org/apache/hadoop/mapred/TestMiniMRLocalFS.java

@@ -47,6 +47,12 @@ public class TestMiniMRLocalFS extends TestCase {
                                                     + "red fox sox\n");
           // assert the number of lines read during caching
           assertTrue("Failed test archives not matching", ret);
+          // test the task report fetchers
+          JobClient client = new JobClient(jconf);
+          TaskReport[] reports = client.getMapTaskReports("job_0001");
+          assertEquals("number of maps", 10, reports.length);
+          reports = client.getReduceTaskReports("job_0001");
+          assertEquals("number of reduces", 1, reports.length);
       } finally {
           if (mr != null) { mr.shutdown(); }
       }