hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r725888 - in /hadoop/core/trunk: CHANGES.txt src/mapred/org/apache/hadoop/mapred/IFile.java src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java
Date Fri, 12 Dec 2008 02:15:29 GMT
Author: cdouglas
Date: Thu Dec 11 18:15:29 2008
New Revision: 725888

URL: http://svn.apache.org/viewvc?rev=725888&view=rev
Log:
HADOOP-4706. Close the underlying output stream in IFileOutputStream::close. Contributed by
Jothi Padmanabhan.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFile.java
    hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=725888&r1=725887&r2=725888&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Dec 11 18:15:29 2008
@@ -354,6 +354,9 @@
     it's deprecated in favour of
     org.apache.hadoop.security.AccessControlException. (acmurthy) 
 
+    HADOOP-4706. Close the underlying output stream in
+    IFileOutputStream::close. (Jothi Padmanabhan via cdouglas)
+
 Release 0.19.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFile.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFile.java?rev=725888&r1=725887&r2=725888&view=diff
==============================================================================
--- hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFile.java (original)
+++ hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFile.java Thu Dec 11 18:15:29 2008
@@ -131,22 +131,28 @@
       out.flush();
   
       if (compressOutput) {
-        // Flush & return the compressor
+        // Flush
         compressedOut.finish();
         compressedOut.resetState();
-        CodecPool.returnCompressor(compressor);
-        compressor = null;
       }
       
-      // Close the stream
-      checksumOut.close();
-      
-      compressedBytesWritten = rawOut.getPos() - start;
-    
       // Close the underlying stream iff we own it...
       if (ownOutputStream) {
-        rawOut.close();
+        out.close();
+      }
+      else {
+        // Write the checksum
+        checksumOut.finish();
+      }
+
+      compressedBytesWritten = rawOut.getPos() - start;
+
+      if (compressOutput) {
+        // Return back the compressor
+        CodecPool.returnCompressor(compressor);
+        compressor = null;
       }
+
       out = null;
       if(writtenRecordsCounter != null) {
         writtenRecordsCounter.increment(numRecordsWritten);

Modified: hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java?rev=725888&r1=725887&r2=725888&view=diff
==============================================================================
--- hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java (original)
+++ hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/IFileOutputStream.java Thu Dec 11
18:15:29 2008
@@ -36,6 +36,7 @@
   private final DataChecksum sum;
   private byte[] barray;
   private boolean closed = false;
+  private boolean finished = false;
 
   /**
    * Create a checksum output stream that writes
@@ -55,11 +56,25 @@
       return;
     }
     closed = true;
+    finish();
+    out.close();
+  }
+
+  /**
+   * Finishes writing data to the output stream, by writing
+   * the checksum bytes to the end. The underlying stream is not closed.
+   * @throws IOException
+   */
+  public void finish() throws IOException {
+    if (finished) {
+      return;
+    }
+    finished = true;
     sum.writeValue(barray, 0, false);
     out.write (barray, 0, sum.getChecksumSize());
     out.flush();
   }
-  
+
   /**
    * Write bytes to the stream.
    */



Mime
View raw message