Browse Source

HADOOP-12831. LocalFS/FSOutputSummer NPEs in constructor if bytes per checksum set to 0 (Mingliang Liu via gtcarrera9)

(cherry-picked from commit 7545ce6636066a05763744a817878e03ee87f456)
Li Lu 9 years ago
parent
commit
090f74c741

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -126,6 +126,9 @@ Release 2.8.0 - UNRELEASED
     (Larry McCay via cnauroth)
     (Larry McCay via cnauroth)
 
 
   IMPROVEMENTS
   IMPROVEMENTS
+    
+    HADOOP-12831. LocalFS/FSOutputSummer NPEs in constructor if bytes per checksum 
+    set to 0 (Mingliang Liu via gtcarrera9)
 
 
     HADOOP-12458. Retries is typoed to spell Retires in parts of
     HADOOP-12458. Retries is typoed to spell Retires in parts of
     hadoop-yarn and hadoop-common
     hadoop-yarn and hadoop-common

+ 4 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java

@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.ClosedChannelException;
 import java.util.Arrays;
 import java.util.Arrays;
 
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configuration;
@@ -61,6 +62,9 @@ public abstract class ChecksumFileSystem extends FilterFileSystem {
     if (conf != null) {
     if (conf != null) {
       bytesPerChecksum = conf.getInt(LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_KEY,
       bytesPerChecksum = conf.getInt(LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_KEY,
 		                     LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_DEFAULT);
 		                     LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_DEFAULT);
+      Preconditions.checkState(bytesPerChecksum > 0,
+          "bytes per checksum should be positive but was %s",
+          bytesPerChecksum);
     }
     }
   }
   }
   
   

+ 23 - 0
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestChecksumFileSystem.java

@@ -228,6 +228,29 @@ public class TestChecksumFileSystem {
   }
   }
 
 
 
 
+  @Test
+  public void testSetConf() {
+    Configuration conf = new Configuration();
+
+    conf.setInt(LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_KEY, 0);
+    try {
+      localFs.setConf(conf);
+      fail("Should have failed because zero bytes per checksum is invalid");
+    } catch (IllegalStateException ignored) {
+    }
+
+    conf.setInt(LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_KEY, -1);
+    try {
+      localFs.setConf(conf);
+      fail("Should have failed because negative bytes per checksum is invalid");
+    } catch (IllegalStateException ignored) {
+    }
+
+    conf.setInt(LocalFileSystemConfigKeys.LOCAL_FS_BYTES_PER_CHECKSUM_KEY, 512);
+    localFs.setConf(conf);
+
+  }
+
   void verifyRename(Path srcPath, Path dstPath, boolean dstIsDir)
   void verifyRename(Path srcPath, Path dstPath, boolean dstIsDir)
       throws Exception { 
       throws Exception { 
     localFs.delete(srcPath,true);
     localFs.delete(srcPath,true);