hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yhema...@apache.org
Subject svn commit: r818946 - in /hadoop/mapreduce/trunk: ./ src/contrib/mumak/src/test/org/apache/hadoop/mapred/ src/java/org/apache/hadoop/mapred/ src/test/mapred/org/apache/hadoop/mapred/
Date Fri, 25 Sep 2009 18:44:44 GMT
Author: yhemanth
Date: Fri Sep 25 18:44:44 2009
New Revision: 818946

URL: http://svn.apache.org/viewvc?rev=818946&view=rev
Log:
MAPREDUCE-964. Fixed start and finish times of TaskStatus to be consistent, thereby fixing
inconsistencies in metering tasks. Contributed by Sreekanth Ramakrishnan.

Added:
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskStatus.java
Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/contrib/mumak/src/test/org/apache/hadoop/mapred/CheckedEventQueue.java
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskStatus.java
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskTracker.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=818946&r1=818945&r2=818946&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Fri Sep 25 18:44:44 2009
@@ -731,3 +731,7 @@
     irrespective of slot size for the job.
     (Ravi Gummadi via yhemanth)
 
+    MAPREDUCE-964. Fixed start and finish times of TaskStatus to be
+    consistent, thereby fixing inconsistencies in metering tasks.
+    (Sreekanth Ramakrishnan via yhemanth)
+

Modified: hadoop/mapreduce/trunk/src/contrib/mumak/src/test/org/apache/hadoop/mapred/CheckedEventQueue.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/mumak/src/test/org/apache/hadoop/mapred/CheckedEventQueue.java?rev=818946&r1=818945&r2=818946&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/mumak/src/test/org/apache/hadoop/mapred/CheckedEventQueue.java
(original)
+++ hadoop/mapreduce/trunk/src/contrib/mumak/src/test/org/apache/hadoop/mapred/CheckedEventQueue.java
Fri Sep 25 18:44:44 2009
@@ -161,6 +161,7 @@
         org.apache.hadoop.mapred.TaskAttemptID.downgrade(taskId);
     MapTaskStatus status = new MapTaskStatus(taskIdOldApi, 1.0f, 1,
         State.SUCCEEDED, null, null, null, Phase.MAP, null);
+    status.setStartTime(mapStart);
     status.setFinishTime(mapDone);
     TaskAttemptCompletionEvent completionEvent = 
         new TaskAttemptCompletionEvent(taskTracker, status);
@@ -177,6 +178,7 @@
         org.apache.hadoop.mapred.TaskAttemptID.downgrade(taskId);
     ReduceTaskStatus status = new ReduceTaskStatus(taskIdOldApi, 1.0f, 1,
         State.SUCCEEDED, null, null, null, Phase.REDUCE, null);
+    status.setStartTime(mapDone);
     status.setFinishTime(reduceDone);
     TaskAttemptCompletionEvent completionEvent = 
         new TaskAttemptCompletionEvent(taskTracker, status);

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskStatus.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskStatus.java?rev=818946&r1=818945&r2=818946&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskStatus.java (original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskStatus.java Fri Sep 25 18:44:44
2009
@@ -27,6 +27,7 @@
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
+import org.apache.hadoop.util.StringUtils;
 /**************************************************
  * Describes the current status of a task.  This is
  * not intended to be a comprehensive piece of data.
@@ -132,11 +133,21 @@
   }
 
   /**
-   * Sets finishTime. 
+   * Sets finishTime for the task status if and only if the
+   * start time is set and passed finish time is greater than
+   * zero.
+   * 
    * @param finishTime finish time of task.
    */
   void setFinishTime(long finishTime) {
-    this.finishTime = finishTime;
+    if(this.getStartTime() > 0 && finishTime > 0) {
+      this.finishTime = finishTime;
+    } else {
+      //Using String utils to get the stack trace.
+      LOG.error("Trying to set finish time for task " + taskid + 
+          " when no start time is set, stackTrace is : " + 
+      		StringUtils.stringifyException(new Exception()));
+    }
   }
   /**
    * Get shuffle finish time for the task. If shuffle finish time was 
@@ -201,11 +212,20 @@
   }
 
   /**
-   * Set startTime of the task.
+   * Set startTime of the task if start time is greater than zero.
    * @param startTime start time
    */
   void setStartTime(long startTime) {
-    this.startTime = startTime;
+    //Making the assumption of passed startTime to be a positive
+    //long value explicit.
+    if (startTime > 0) {
+      this.startTime = startTime;
+    } else {
+      //Using String utils to get the stack trace.
+      LOG.error("Trying to set illegal startTime for task : " + taskid +
+          ".Stack trace is : " +
+          StringUtils.stringifyException(new Exception()));
+    }
   }
   /**
    * Get current phase of this task. Phase.Map in case of map tasks, 
@@ -326,11 +346,11 @@
 
     setDiagnosticInfo(status.getDiagnosticInfo());
     
-    if (status.getStartTime() != 0) {
-      this.startTime = status.getStartTime(); 
+    if (status.getStartTime() > 0) {
+      this.setStartTime(status.getStartTime()); 
     }
-    if (status.getFinishTime() != 0) {
-      this.finishTime = status.getFinishTime(); 
+    if (status.getFinishTime() > 0) {
+      this.setFinishTime(status.getFinishTime()); 
     }
     
     this.phase = status.getPhase();
@@ -359,8 +379,8 @@
     setProgress(progress);
     setStateString(state);
     setPhase(phase);
-    if (finishTime != 0) {
-      this.finishTime = finishTime; 
+    if (finishTime > 0) {
+      setFinishTime(finishTime); 
     }
   }
 

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskTracker.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskTracker.java?rev=818946&r1=818945&r2=818946&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskTracker.java (original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/TaskTracker.java Fri Sep 25 18:44:44
2009
@@ -2487,6 +2487,7 @@
           taskStatus.setRunState(TaskStatus.State.KILLED);
         }
       }
+      taskStatus.setFinishTime(System.currentTimeMillis());
       removeFromMemoryManager(task.getTaskID());
       releaseSlot();
     }

Added: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskStatus.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskStatus.java?rev=818946&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskStatus.java (added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestTaskStatus.java Fri
Sep 25 18:44:44 2009
@@ -0,0 +1,74 @@
+/**
+ * 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.mapred;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestTaskStatus {
+
+  @Test
+  public void testMapTaskStatusStartAndFinishTimes() {
+    checkTaskStatues(true);
+  }
+
+  @Test
+  public void testReduceTaskStatusStartAndFinishTimes() {
+    checkTaskStatues(false);
+  }
+
+  /**
+   * Private utility method which ensures uniform testing of newly created
+   * TaskStatus object.
+   * 
+   * @param isMap
+   *          true to test map task status, false for reduce.
+   */
+  private void checkTaskStatues(boolean isMap) {
+
+    TaskStatus status = null;
+    if (isMap) {
+      status = new MapTaskStatus();
+    } else {
+      status = new ReduceTaskStatus();
+    }
+    long currentTime = System.currentTimeMillis();
+    // first try to set the finish time before
+    // start time is set.
+    status.setFinishTime(currentTime);
+    assertEquals("Finish time of the task status set without start time", 0,
+        status.getFinishTime());
+    // Now set the start time to right time.
+    status.setStartTime(currentTime);
+    assertEquals("Start time of the task status not set correctly.",
+        currentTime, status.getStartTime());
+    // try setting wrong start time to task status.
+    long wrongTime = -1;
+    status.setStartTime(wrongTime);
+    assertEquals(
+        "Start time of the task status is set to wrong negative value",
+        currentTime, status.getStartTime());
+    // finally try setting wrong finish time i.e. negative value.
+    status.setFinishTime(wrongTime);
+    assertEquals("Finish time of task status is set to wrong negative value",
+        0, status.getFinishTime());
+    status.setFinishTime(currentTime);
+    assertEquals("Finish time of the task status not set correctly.",
+        currentTime, status.getFinishTime());
+  }
+}



Mime
View raw message