Browse Source

Merge r744113:744114 from trunk to branch-0.19. Fixes HADOOP-4760.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.19@744117 13f79535-47bb-0310-9956-ffa450edef68
Enis Soztutar 16 years ago
parent
commit
ca6359e52b

+ 3 - 0
CHANGES.txt

@@ -105,6 +105,9 @@ Release 0.19.1 - Unreleased
     HADOOP-5067. Fixes TaskInProgress.java to keep track of count of failed and
     killed tasks correctly. (Amareshwari Sriramadasu via ddas)
 
+    HADOOP-4760. HDFS streams should not throw exceptions when closed twice. 
+    (enis)
+
 Release 0.19.0 - 2008-11-18
 
   INCOMPATIBLE CHANGES

+ 1 - 1
src/core/org/apache/hadoop/fs/s3/S3InputStream.java

@@ -168,7 +168,7 @@ class S3InputStream extends FSInputStream {
   @Override
   public void close() throws IOException {
     if (closed) {
-      throw new IOException("Stream closed");
+      return;
     }
     if (blockStream != null) {
       blockStream.close();

+ 1 - 1
src/core/org/apache/hadoop/fs/s3/S3OutputStream.java

@@ -200,7 +200,7 @@ class S3OutputStream extends OutputStream {
   @Override
   public synchronized void close() throws IOException {
     if (closed) {
-      throw new IOException("Stream closed");
+      return;
     }
 
     flush();

+ 1 - 1
src/core/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java

@@ -164,7 +164,7 @@ public class NativeS3FileSystem extends FileSystem {
     @Override
     public synchronized void close() throws IOException {
       if (closed) {
-        throw new IOException("Stream closed");
+        return;
       }
 
       backupStream.close();

+ 13 - 14
src/hdfs/org/apache/hadoop/hdfs/DFSClient.java

@@ -204,12 +204,13 @@ public class DFSClient implements FSConstants, java.io.Closeable {
    * created and close connections to the namenode.
    */
   public synchronized void close() throws IOException {
-    checkOpen();
-    clientRunning = false;
-    leasechecker.close();
-
-    // close connections to the namenode
-    RPC.stopProxy(rpcNamenode);
+    if(clientRunning) {
+      clientRunning = false;
+      leasechecker.close();
+  
+      // close connections to the namenode
+      RPC.stopProxy(rpcNamenode);
+    }
   }
 
   /**
@@ -1568,11 +1569,11 @@ public class DFSClient implements FSConstants, java.io.Closeable {
      */
     @Override
     public synchronized void close() throws IOException {
-      checkOpen();
       if (closed) {
-        throw new IOException("Stream closed");
+        return;
       }
-
+      checkOpen();
+      
       if ( blockReader != null ) {
         blockReader.close();
         blockReader = null;
@@ -2525,12 +2526,8 @@ public class DFSClient implements FSConstants, java.io.Closeable {
     }
 
     private void isClosed() throws IOException {
-      if (closed) {
-        if (lastException != null) {
+      if (closed && lastException != null) {
           throw lastException;
-        } else {
-          throw new IOException("Stream closed.");
-        }
       }
     }
 
@@ -3052,6 +3049,8 @@ public class DFSClient implements FSConstants, java.io.Closeable {
      */
     @Override
     public void close() throws IOException {
+      if(closed)
+        return;
       closeInternal();
       leasechecker.remove(src);
       

+ 20 - 0
src/test/org/apache/hadoop/fs/FileSystemContractBaseTest.java

@@ -423,6 +423,26 @@ public abstract class FileSystemContractBaseTest extends TestCase {
         fs.exists(path("/test/new/newdir/dir/subdir/file2")));
   }
 
+  public void testInputStreamClosedTwice() throws IOException {
+    //HADOOP-4760 according to Closeable#close() closing already-closed 
+    //streams should have no effect. 
+    Path src = path("/test/hadoop/file");
+    createFile(src);
+    FSDataInputStream in = fs.open(src);
+    in.close();
+    in.close();
+  }
+  
+  public void testOutputStreamClosedTwice() throws IOException {
+    //HADOOP-4760 according to Closeable#close() closing already-closed 
+    //streams should have no effect. 
+    Path src = path("/test/hadoop/file");
+    FSDataOutputStream out = fs.create(src);
+    out.writeChar('H'); //write some data
+    out.close();
+    out.close();
+  }
+  
   protected Path path(String pathString) {
     return new Path(pathString).makeQualified(fs);
   }