Browse Source

Merge -r 672920:672921 from trunk to branch 0.18 to move the change of HADOOP-3539 into the release 0.18.0 section.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@672924 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 17 năm trước cách đây
mục cha
commit
9081b5e7ef

+ 3 - 0
CHANGES.txt

@@ -688,6 +688,9 @@ Release 0.18.0 - Unreleased
     HADOOP-3635. Uncaught exception in DataBlockScanner. 
     (Tsz Wo (Nicholas), SZE via hairong)
 
+    HADOOP-3539. Exception when closing DFSClient while multiple files are
+    open. (Benjamin Gufler via hairong)
+
 Release 0.17.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 8 - 10
src/hdfs/org/apache/hadoop/dfs/DFSClient.java

@@ -207,20 +207,18 @@ class DFSClient implements FSConstants {
     synchronized (this) {
       checkOpen();
       synchronized (pendingCreates) {
-        Iterator file_itr = pendingCreates.keySet().iterator();
-        while (file_itr.hasNext()) {
-          String name = (String) file_itr.next();
-          OutputStream out = pendingCreates.get(name);
-          try {
-            if (out != null) {
+        while (!pendingCreates.isEmpty()) {
+          String name = pendingCreates.firstKey();
+          OutputStream out = pendingCreates.remove(name);
+          if (out != null) {
+            try {
               out.close();
+            } catch (IOException ie) {
+              System.err.println("Exception closing file " + name);
+              ie.printStackTrace();
             }
-          } catch (IOException ie) {
-            System.err.println("Exception closing file " + name);
-            ie.printStackTrace();
           }
         }
-        pendingCreates.clear();
       }
       this.clientRunning = false;
       try {

+ 23 - 0
src/test/org/apache/hadoop/dfs/TestDistributedFileSystem.java

@@ -22,6 +22,7 @@ import java.net.URI;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
 
 public class TestDistributedFileSystem extends junit.framework.TestCase {
   public void testFileSystemCloseAll() throws Exception {
@@ -42,4 +43,26 @@ public class TestDistributedFileSystem extends junit.framework.TestCase {
       if (cluster != null) {cluster.shutdown();}
     }
   }
+  
+  /**
+   * Tests DFSClient.close throws no ConcurrentModificationException if 
+   * multiple files are open.
+   */
+  public void testDFSClose() throws Exception {
+    Configuration conf = new Configuration();
+    MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
+    FileSystem fileSys = cluster.getFileSystem();
+
+    try {
+      // create two files
+      fileSys.create(new Path("/test/dfsclose/file-0"));
+      fileSys.create(new Path("/test/dfsclose/file-1"));
+
+      fileSys.close();
+    }
+    finally {
+      if (cluster != null) {cluster.shutdown();}
+    }
+  }
+
 }