hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1330552 - in /hadoop/common/trunk/hadoop-mapreduce-project: ./ hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodeman...
Date Wed, 25 Apr 2012 20:49:42 GMT
Author: bobby
Date: Wed Apr 25 20:49:41 2012
New Revision: 1330552

URL: http://svn.apache.org/viewvc?rev=1330552&view=rev
Log:
MAPREDUCE-4194. ConcurrentModificationError in DirectoryCollection (Jonathan Eagles via bobby)

Added:
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDirectoryCollection.java
Modified:
    hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java

Modified: hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt?rev=1330552&r1=1330551&r2=1330552&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt Wed Apr 25 20:49:41 2012
@@ -406,6 +406,9 @@ Release 0.23.3 - UNRELEASED
 
     MAPREDUCE-4133. MR over viewfs is broken (John George via bobby)
 
+    MAPREDUCE-4194. ConcurrentModificationError in DirectoryCollection
+    (Jonathan Eagles via bobby)
+
 Release 0.23.2 - UNRELEASED
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java?rev=1330552&r1=1330551&r2=1330552&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java
(original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java
Wed Apr 25 20:49:41 2012
@@ -19,10 +19,9 @@
 package org.apache.hadoop.yarn.server.nodemanager;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.Collections;
 import java.util.List;
-import java.util.ListIterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -41,23 +40,22 @@ class DirectoryCollection {
   private int numFailures;
 
   public DirectoryCollection(String[] dirs) {
-    localDirs = new ArrayList<String>();
-    localDirs.addAll(Arrays.asList(dirs));
-    failedDirs = new ArrayList<String>();
+    localDirs = new CopyOnWriteArrayList<String>(dirs);
+    failedDirs = new CopyOnWriteArrayList<String>();
   }
 
   /**
    * @return the current valid directories 
    */
   synchronized List<String> getGoodDirs() {
-    return localDirs;
+    return Collections.unmodifiableList(localDirs);
   }
 
   /**
    * @return the failed directories
    */
   synchronized List<String> getFailedDirs() {
-    return failedDirs;
+    return Collections.unmodifiableList(failedDirs);
   }
 
   /**
@@ -75,22 +73,17 @@ class DirectoryCollection {
    */
   synchronized boolean checkDirs() {
     int oldNumFailures = numFailures;
-    ListIterator<String> it = localDirs.listIterator();
-    while (it.hasNext()) {
-      final String dir = it.next();
+    for (final String dir : localDirs) {
       try {
         DiskChecker.checkDir(new File(dir));
       } catch (DiskErrorException de) {
         LOG.warn("Directory " + dir + " error " +
             de.getMessage() + ", removing from the list of valid directories.");
-        it.remove();
+        localDirs.remove(dir);
         failedDirs.add(dir);
         numFailures++;
       }
     }
-    if (numFailures > oldNumFailures) {
-      return true;
-    }
-    return false;
+    return numFailures > oldNumFailures;
   }
 }

Added: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDirectoryCollection.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDirectoryCollection.java?rev=1330552&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDirectoryCollection.java
(added)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDirectoryCollection.java
Wed Apr 25 20:49:41 2012
@@ -0,0 +1,68 @@
+/**
+* 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.yarn.server.nodemanager;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.hadoop.fs.FileUtil;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestDirectoryCollection {
+
+  private static final File testDir = new File("target",
+      TestDirectoryCollection.class.getName()).getAbsoluteFile();
+  private static final File testFile = new File(testDir, "testfile");
+
+  @BeforeClass
+  public static void setup() throws IOException {
+    testDir.mkdirs();
+    testFile.createNewFile();
+  }
+
+  @AfterClass
+  public static void teardown() {
+    FileUtil.fullyDelete(testDir);
+  }
+
+  @Test
+  public void testConcurrentAccess() throws IOException {
+    // Initialize DirectoryCollection with a file instead of a directory
+    String[] dirs = {testFile.getPath()};
+    DirectoryCollection dc = new DirectoryCollection(dirs);
+
+    // Create an iterator before checkDirs is called to reliable test case
+    List<String> list = dc.getGoodDirs();
+    ListIterator<String> li = list.listIterator();
+
+    // DiskErrorException will invalidate iterator of non-concurrent
+    // collections. ConcurrentModificationException will be thrown upon next
+    // use of the iterator.
+    Assert.assertTrue("checkDirs did not remove test file from directory list",
+        dc.checkDirs());
+
+    // Verify no ConcurrentModification is thrown
+    li.next();
+  }
+}



Mime
View raw message