Author: eli
Date: Sun Nov 18 02:19:16 2012
New Revision: 1410813
URL: http://svn.apache.org/viewvc?rev=1410813&view=rev
Log:
HDFS-4156. Seeking to a negative position should throw an IOE. Contributed by
Eli Reisman
Modified:
hadoop/common/branches/branch-2/hadoop-hdfs-project/ (props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/ (props
changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/native/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs/
(props changed)
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java
Propchange: hadoop/common/branches/branch-2/hadoop-hdfs-project/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project:r1410812
Propchange: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs:r1410812
Modified:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1410813&r1=1410812&r2=1410813&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
(original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Sun Nov 18 02:19:16 2012
@@ -250,6 +250,9 @@ Release 2.0.3-alpha - Unreleased
HDFS-4105. The SPNEGO user for secondary namenode should use the web
keytab. (Arpit Gupta via jitendra)
+ HDFS-4156. Seeking to a negative position should throw an IOE.
+ (Eli Reisman via eli)
+
Release 2.0.2-alpha - 2012-09-07
INCOMPATIBLE CHANGES
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java:r1410812
Modified:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java?rev=1410813&r1=1410812&r2=1410813&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java
Sun Nov 18 02:19:16 2012
@@ -1076,6 +1076,9 @@ public class DFSInputStream extends FSIn
if (targetPos > getFileLength()) {
throw new IOException("Cannot seek after EOF");
}
+ if (targetPos < 0) {
+ throw new IOException("Cannot seek to negative offset");
+ }
if (closed) {
throw new IOException("Stream is closed!");
}
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/native/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/native:r1410812
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode:r1410812
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs:r1410812
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/secondary:r1410812
Propchange:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs/
------------------------------------------------------------------------------
Merged
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/hdfs:r1410812
Modified:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java?rev=1410813&r1=1410812&r2=1410813&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java
Sun Nov 18 02:19:16 2012
@@ -141,7 +141,69 @@ public class TestSeekBug {
cluster.shutdown();
}
}
-
+
+ /**
+ * Test (expected to throw IOE) for negative
+ * <code>FSDataInpuStream#seek</code> argument
+ */
+ @Test (expected=IOException.class)
+ public void testNegativeSeek() throws IOException {
+ Configuration conf = new HdfsConfiguration();
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+ FileSystem fs = cluster.getFileSystem();
+ try {
+ Path seekFile = new Path("seekboundaries.dat");
+ DFSTestUtil.createFile(
+ fs,
+ seekFile,
+ ONEMB,
+ ONEMB,
+ fs.getDefaultBlockSize(seekFile),
+ fs.getDefaultReplication(seekFile),
+ seed);
+ FSDataInputStream stream = fs.open(seekFile);
+ // Perform "safe seek" (expected to pass)
+ stream.seek(65536);
+ assertEquals(65536, stream.getPos());
+ // expect IOE for this call
+ stream.seek(-73);
+ } finally {
+ fs.close();
+ cluster.shutdown();
+ }
+ }
+
+ /**
+ * Test (expected to throw IOE) for <code>FSDataInpuStream#seek</code>
+ * when the position argument is larger than the file size.
+ */
+ @Test (expected=IOException.class)
+ public void testSeekPastFileSize() throws IOException {
+ Configuration conf = new HdfsConfiguration();
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+ FileSystem fs = cluster.getFileSystem();
+ try {
+ Path seekFile = new Path("seekboundaries.dat");
+ DFSTestUtil.createFile(
+ fs,
+ seekFile,
+ ONEMB,
+ ONEMB,
+ fs.getDefaultBlockSize(seekFile),
+ fs.getDefaultReplication(seekFile),
+ seed);
+ FSDataInputStream stream = fs.open(seekFile);
+ // Perform "safe seek" (expected to pass)
+ stream.seek(65536);
+ assertEquals(65536, stream.getPos());
+ // expect IOE for this call
+ stream.seek(ONEMB + ONEMB + ONEMB);
+ } finally {
+ fs.close();
+ cluster.shutdown();
+ }
+ }
+
/**
* Tests if the seek bug exists in FSDataInputStream in LocalFS.
*/