MAPREDUCE-2846. Fixed a race condition in writing the log index file that
caused tasks to fail. (omalley)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-204@1159730 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 87131ac..71bca85 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -13,6 +13,9 @@
 
   BUG FIXES
 
+    MAPREDUCE-2846. Fixed a race condition in writing the log index file that
+    caused tasks to fail. (omalley)
+
     MAPREDUCE-2651. Fix race condition in Linux task controller for
     job log directory creation. (Bharath Mundlapudi via llu)
 
diff --git a/src/mapred/org/apache/hadoop/mapred/TaskLog.java b/src/mapred/org/apache/hadoop/mapred/TaskLog.java
index 3484fbb..4b3a303 100644
--- a/src/mapred/org/apache/hadoop/mapred/TaskLog.java
+++ b/src/mapred/org/apache/hadoop/mapred/TaskLog.java
@@ -308,9 +308,11 @@
     }
   }
   
-  static void writeToIndexFile(String logLocation,
-      TaskAttemptID currentTaskid, boolean isCleanup,
-      Map<LogName, Long[]> lengths) throws IOException {
+  static synchronized 
+  void writeToIndexFile(String logLocation,
+                        TaskAttemptID currentTaskid, 
+                        boolean isCleanup,
+                        Map<LogName, Long[]> lengths) throws IOException {
     // To ensure atomicity of updates to index file, write to temporary index
     // file first and then rename.
     File tmpIndexFile = getTmpIndexFile(currentTaskid, isCleanup);