You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by tg...@apache.org on 2012/07/05 23:37:53 UTC

svn commit: r1357940 - in /hadoop/common/branches/branch-2/hadoop-mapreduce-project: CHANGES.txt hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java

Author: tgraves
Date: Thu Jul  5 21:37:53 2012
New Revision: 1357940

URL: http://svn.apache.org/viewvc?rev=1357940&view=rev
Log:
merge -r 1357936:1357937 from trunk. FIXES: MAPREDUCE-4384

Modified:
    hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java

Modified: hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt?rev=1357940&r1=1357939&r2=1357940&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-mapreduce-project/CHANGES.txt Thu Jul  5 21:37:53 2012
@@ -514,6 +514,8 @@ Release 0.23.3 - UNRELEASED
     MAPREDUCE-4392. Counters.makeCompactString() changed behavior from 0.20
     (Jason Lowe via bobby)
 
+    MAPREDUCE-4384. Race conditions in IndexCache (Kihwal Lee via tgraves)
+
 Release 0.23.2 - UNRELEASED
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java?rev=1357940&r1=1357939&r2=1357940&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java (original)
+++ hadoop/common/branches/branch-2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IndexCache.java Thu Jul  5 21:37:53 2012
@@ -67,13 +67,13 @@ class IndexCache {
     if (info == null) {
       info = readIndexFileToCache(fileName, mapId, expectedIndexOwner);
     } else {
-      synchronized (info) {
-        while (null == info.mapSpillRecord) {
-          try {
-            info.wait();
-          } catch (InterruptedException e) {
-            throw new IOException("Interrupted waiting for construction", e);
-          }
+      while (isUnderConstruction(info)) {
+        try {
+          // In case the entry is ready after the above check but
+          // before the following wait, we do timed wait.
+          info.wait(200);
+        } catch (InterruptedException e) {
+          throw new IOException("Interrupted waiting for construction", e);
         }
       }
       LOG.debug("IndexCache HIT: MapId " + mapId + " found");
@@ -88,6 +88,12 @@ class IndexCache {
     return info.mapSpillRecord.getIndex(reduce);
   }
 
+  private boolean isUnderConstruction(IndexInformation info) {
+    synchronized(info) {
+      return (null == info.mapSpillRecord);
+    }
+  }
+
   private IndexInformation readIndexFileToCache(Path indexFileName,
                                                 String mapId,
                                                 String expectedIndexOwner)
@@ -95,13 +101,13 @@ class IndexCache {
     IndexInformation info;
     IndexInformation newInd = new IndexInformation();
     if ((info = cache.putIfAbsent(mapId, newInd)) != null) {
-      synchronized (info) {
-        while (null == info.mapSpillRecord) {
-          try {
-            info.wait();
-          } catch (InterruptedException e) {
-            throw new IOException("Interrupted waiting for construction", e);
-          }
+      while (isUnderConstruction(info)) {
+        try {
+          // In case the entry is ready after the above check but
+          // before the following wait, we do timed wait.
+          info.wait(200);
+        } catch (InterruptedException e) {
+          throw new IOException("Interrupted waiting for construction", e);
         }
       }
       LOG.debug("IndexCache HIT: MapId " + mapId + " found");
@@ -139,7 +145,7 @@ class IndexCache {
    */
   public void removeMap(String mapId) {
     IndexInformation info = cache.get(mapId);
-    if ((info != null) && (info.getSize() == 0)) {
+    if (info == null || ((info != null) && isUnderConstruction(info))) {
       return;
     }
     info = cache.remove(mapId);