Browse Source

HADOOP-319. Fix FileSystem.close() to remove FileSystem instance from the cache. Contributed by Hairong.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@417245 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 năm trước cách đây
mục cha
commit
3cfaff4141

+ 3 - 0
CHANGES.txt

@@ -41,6 +41,9 @@ Trunk (unreleased changes)
  9. HADOOP-316.  Fix a potential deadlock in the jobtracker.
     (omalley via cutting)
 
+10. HADOOP-319.  Fix FileSystem.close() to remove the FileSystem
+    instance from the cache.  (Hairong Kuang via cutting)
+
 
 Release 0.3.2 - 2006-06-09
 

+ 1 - 0
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -196,6 +196,7 @@ public class DistributedFileSystem extends FileSystem {
     }
 
     public void close() throws IOException {
+        super.close();
         dfs.close();
     }
 

+ 3 - 1
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -540,7 +540,9 @@ public abstract class FileSystem extends Configured {
      * No more filesystem operations are needed.  Will
      * release any held locks.
      */
-    public abstract void close() throws IOException;
+    public void close() throws IOException {
+        NAME_TO_FS.remove(getName());
+    }
 
     /**
      * Report a checksum error to the file system.

+ 3 - 1
src/java/org/apache/hadoop/fs/LocalFileSystem.java

@@ -322,7 +322,9 @@ public class LocalFileSystem extends FileSystem {
       throws IOException {
     }
 
-    public void close() throws IOException {}
+    public void close() throws IOException {
+        super.close();
+    }
 
     public String toString() {
         return "LocalFS";

+ 3 - 12
src/test/org/apache/hadoop/fs/TestCopyFiles.java

@@ -171,12 +171,10 @@ public class TestCopyFiles extends TestCase {
   public void testCopyFromDfsToDfs() throws IOException {
     String namenode = null;
     MiniDFSCluster cluster = null;
-    FileSystem fileSys = null;
     try {
       Configuration conf = new Configuration();
       cluster = new MiniDFSCluster(65314, conf);
-      fileSys = cluster.getFileSystem();
-      namenode = fileSys.getName();
+      namenode = conf.get("fs.default.name", "local");
       if (!"local".equals(namenode)) {
         MyFile[] files = createFiles(namenode, "/srcdat");
         CopyFiles.main(new String[] {"dfs://"+namenode+"/srcdat",
@@ -187,7 +185,6 @@ public class TestCopyFiles extends TestCase {
         deldir(namenode, "/srcdat");
       }
     } finally {
-      if (fileSys != null) { fileSys.close(); }
       if (cluster != null) { cluster.shutdown(); }
     }
   }
@@ -196,12 +193,10 @@ public class TestCopyFiles extends TestCase {
   public void testCopyFromLocalToDfs() throws IOException {
     String namenode = null;
     MiniDFSCluster cluster = null;
-    FileSystem fileSys = null;
     try {
       Configuration conf = new Configuration();
       cluster = new MiniDFSCluster(65316, conf);
-      fileSys = cluster.getFileSystem();
-      namenode = fileSys.getName();
+      namenode = conf.get("fs.default.name", "local");
       if (!"local".equals(namenode)) {
         MyFile[] files = createFiles("local", TEST_ROOT_DIR+"/srcdat");
         CopyFiles.main(new String[] {"file://"+TEST_ROOT_DIR+"/srcdat",
@@ -212,7 +207,6 @@ public class TestCopyFiles extends TestCase {
         deldir("local", TEST_ROOT_DIR+"/srcdat");
       }
     } finally {
-      if (fileSys != null) { fileSys.close(); }
       if (cluster != null) { cluster.shutdown(); }
     }
   }
@@ -221,12 +215,10 @@ public class TestCopyFiles extends TestCase {
   public void testCopyFromDfsToLocal() throws IOException {
     String namenode = null;
     MiniDFSCluster cluster = null;
-    FileSystem fileSys = null;
     try {
       Configuration conf = new Configuration();
       cluster = new MiniDFSCluster(65318, conf);
-      fileSys = cluster.getFileSystem();
-      namenode = fileSys.getName();
+      namenode = conf.get("fs.default.name", "local");
       if (!"local".equals(namenode)) {
         MyFile[] files = createFiles(namenode, "/srcdat");
         CopyFiles.main(new String[] {"dfs://"+namenode+"/srcdat",
@@ -237,7 +229,6 @@ public class TestCopyFiles extends TestCase {
         deldir(namenode, "/srcdat");
       }
     } finally {
-      if (fileSys != null) { fileSys.close(); }
       if (cluster != null) { cluster.shutdown(); }
     }
  }