hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1494304 - in /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs: ChecksumFileSystem.java ChecksumFs.java FSOutputSummer.java
Date Tue, 18 Jun 2013 21:08:37 GMT
Author: atm
Date: Tue Jun 18 21:08:37 2013
New Revision: 1494304

URL: http://svn.apache.org/r1494304
Log:
HDFS-4906. HDFS Output streams should not accept writes after being closed. Contributed by
Aaron T. Myers.

Modified:
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSOutputSummer.java

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java?rev=1494304&r1=1494303&r2=1494304&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java
Tue Jun 18 21:08:37 2013
@@ -19,6 +19,7 @@
 package org.apache.hadoop.fs;
 
 import java.io.*;
+import java.nio.channels.ClosedChannelException;
 import java.util.Arrays;
 
 import org.apache.hadoop.classification.InterfaceAudience;
@@ -368,6 +369,7 @@ public abstract class ChecksumFileSystem
     private FSDataOutputStream datas;    
     private FSDataOutputStream sums;
     private static final float CHKSUM_AS_FRACTION = 0.01f;
+    private boolean isClosed = false;
     
     public ChecksumFSOutputSummer(ChecksumFileSystem fs, 
                           Path file, 
@@ -391,9 +393,13 @@ public abstract class ChecksumFileSystem
     
     @Override
     public void close() throws IOException {
-      flushBuffer();
-      sums.close();
-      datas.close();
+      try {
+        flushBuffer();
+        sums.close();
+        datas.close();
+      } finally {
+        isClosed = true;
+      }
     }
     
     @Override
@@ -402,6 +408,13 @@ public abstract class ChecksumFileSystem
       datas.write(b, offset, len);
       sums.write(checksum);
     }
+
+    @Override
+    protected void checkClosed() throws IOException {
+      if (isClosed) {
+        throw new ClosedChannelException();
+      }
+    }
   }
 
   @Override

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java?rev=1494304&r1=1494303&r2=1494304&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java
Tue Jun 18 21:08:37 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.fs;
 
 import java.io.*;
 import java.net.URISyntaxException;
+import java.nio.channels.ClosedChannelException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EnumSet;
@@ -325,6 +326,7 @@ public abstract class ChecksumFs extends
     private FSDataOutputStream datas;    
     private FSDataOutputStream sums;
     private static final float CHKSUM_AS_FRACTION = 0.01f;
+    private boolean isClosed = false;
     
     
     public ChecksumFSOutputSummer(final ChecksumFs fs, final Path file, 
@@ -356,9 +358,13 @@ public abstract class ChecksumFs extends
     
     @Override
     public void close() throws IOException {
-      flushBuffer();
-      sums.close();
-      datas.close();
+      try {
+        flushBuffer();
+        sums.close();
+        datas.close();
+      } finally {
+        isClosed = true;
+      }
     }
     
     @Override
@@ -367,6 +373,13 @@ public abstract class ChecksumFs extends
       datas.write(b, offset, len);
       sums.write(checksum);
     }
+
+    @Override
+    protected void checkClosed() throws IOException {
+      if (isClosed) {
+        throw new ClosedChannelException();
+      }
+    }
   }
 
   @Override

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSOutputSummer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSOutputSummer.java?rev=1494304&r1=1494303&r2=1494304&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSOutputSummer.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FSOutputSummer.java
Tue Jun 18 21:08:37 2013
@@ -53,6 +53,15 @@ abstract public class FSOutputSummer ext
    */
   protected abstract void writeChunk(byte[] b, int offset, int len, byte[] checksum)
   throws IOException;
+  
+  /**
+   * Check if the implementing OutputStream is closed and should no longer
+   * accept writes. Implementations should do nothing if this stream is not
+   * closed, and should throw an {@link IOException} if it is closed.
+   * 
+   * @throws IOException if this stream is already closed.
+   */
+  protected abstract void checkClosed() throws IOException;
 
   /** Write one byte */
   @Override
@@ -84,7 +93,10 @@ abstract public class FSOutputSummer ext
    */
   @Override
   public synchronized void write(byte b[], int off, int len)
-  throws IOException {
+      throws IOException {
+    
+    checkClosed();
+    
     if (off < 0 || len < 0 || off > b.length - len) {
       throw new ArrayIndexOutOfBoundsException();
     }



Mime
View raw message